update documenation, susmng

This commit is contained in:
Akbar Rahman 2022-05-26 15:51:14 +01:00
parent fc8dfb43e0
commit 1fee71280f
Signed by: alvierahman90
GPG Key ID: 20609519444A1269
4 changed files with 56 additions and 12 deletions

2
.gitignore vendored
View File

@ -1,2 +1,2 @@
redis
docker-compose.yml
.env

View File

@ -5,7 +5,7 @@ services:
build: .
ports: [ "80:80" ]
environment:
- SECRET=secret
- SECRET=${SECRET}
redis:
image: redis:7
volumes: [ "./redis:/data" ]

26
readme
View File

@ -2,3 +2,29 @@ sus
===
simple URL shortener
usage
-----
running the server
1. generate the secret used to create and delete shortlinks
echo SECRET=`pwgen -s 64 1` >> .env
2. run the services
docker-compose up -d --build
setting up susmng
1. install susmng
make install-susmng
2. create config files
susmng init
3. edit config files (~/.config/susmng/config.json) to add your secrets

View File

@ -6,6 +6,7 @@ import hmac
import hashlib
import pathlib
import os
import json
def get_args():
@ -13,26 +14,43 @@ def get_args():
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('susserver')
parser.add_argument('command')
parser.add_argument('shortlink')
parser.add_argument('value')
parser.add_argument('--secret-file', type=pathlib.Path, default=pathlib.Path(os.path.expanduser('~/.susmng_secret')))
parser.add_argument('--http', action='store_true')
parser.add_argument('-s', '--server', default="")
parser.add_argument('-l', '--shortlink', default="")
parser.add_argument('-v', '--value', default="")
parser.add_argument('-c', '--config', type=pathlib.Path, default=pathlib.Path(os.path.expanduser('~/.config/susmng/config.json')))
parser.add_argument('-H', '--http', action='store_true')
return parser.parse_args()
def main(args):
""" Entry point for script """
if not args.secret_file.exists():
print(f"secret file does not exist at: {args.secret_file}")
if args.command == "init":
print(f"creating config file and quitting")
if args.config.exists():
print("config file exists... doing nothing")
return
with open(args.secret_file) as fp:
secret = fp.read().strip()
with open(args.config, 'w+') as fp:
json.dump({ 'secrets': { 'sus.example.com': 'secret' } }, fp, indent=2)
r = requests.post(f"{'http' if args.http else 'https'}://{args.susserver}",
return
with open(args.config) as fp:
config = json.load(fp)
server = args.server
if server == "":
server = list(config['secrets'].keys())[0]
secret = config['secrets'][server]
if args.command == "delete" and args.value != "confirm":
print("--value not set to 'confirm'... delete operation may fail")
r = requests.post(f"{'http' if args.http else 'https'}://{server}",
data = {
'Command': args.command,
'Shortlink': args.shortlink,