update documenation, susmng
This commit is contained in:
38
susmng.py
38
susmng.py
@@ -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.config, 'w+') as fp:
|
||||
json.dump({ 'secrets': { 'sus.example.com': 'secret' } }, fp, indent=2)
|
||||
|
||||
return
|
||||
|
||||
with open(args.secret_file) as fp:
|
||||
secret = fp.read().strip()
|
||||
with open(args.config) as fp:
|
||||
config = json.load(fp)
|
||||
|
||||
r = requests.post(f"{'http' if args.http else 'https'}://{args.susserver}",
|
||||
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,
|
||||
|
||||
Reference in New Issue
Block a user