susmng.py reads secret from file instead from cli
This commit is contained in:
parent
1b5746096e
commit
d4d1c8e956
14
susmng.py
14
susmng.py
@ -4,6 +4,8 @@ import sys
|
|||||||
import requests
|
import requests
|
||||||
import hmac
|
import hmac
|
||||||
import hashlib
|
import hashlib
|
||||||
|
import pathlib
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
def get_args():
|
def get_args():
|
||||||
@ -15,13 +17,21 @@ def get_args():
|
|||||||
parser.add_argument('command')
|
parser.add_argument('command')
|
||||||
parser.add_argument('shortlink')
|
parser.add_argument('shortlink')
|
||||||
parser.add_argument('value')
|
parser.add_argument('value')
|
||||||
parser.add_argument('--secret', default="secret")
|
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('--http', action='store_true')
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
def main(args):
|
def main(args):
|
||||||
""" Entry point for script """
|
""" Entry point for script """
|
||||||
|
|
||||||
|
if not args.secret_file.exists():
|
||||||
|
print(f"secret file does not exist at: {args.secret_file}")
|
||||||
|
return
|
||||||
|
|
||||||
|
with open(args.secret_file) as fp:
|
||||||
|
secret = fp.read().strip()
|
||||||
|
|
||||||
r = requests.post(f"{'http' if args.http else 'https'}://{args.susserver}",
|
r = requests.post(f"{'http' if args.http else 'https'}://{args.susserver}",
|
||||||
data = {
|
data = {
|
||||||
'Command': args.command,
|
'Command': args.command,
|
||||||
@ -30,7 +40,7 @@ def main(args):
|
|||||||
},
|
},
|
||||||
headers = {
|
headers = {
|
||||||
'Signature': 'SUS-SIGNATURE-' + hmac.new(
|
'Signature': 'SUS-SIGNATURE-' + hmac.new(
|
||||||
args.secret.encode("UTF-8"),
|
secret.encode("UTF-8"),
|
||||||
(args.command+":"+args.shortlink+":"+args.value).encode("UTF-8"),
|
(args.command+":"+args.shortlink+":"+args.value).encode("UTF-8"),
|
||||||
hashlib.sha256
|
hashlib.sha256
|
||||||
).hexdigest()
|
).hexdigest()
|
||||||
|
Loading…
Reference in New Issue
Block a user