48 lines
1.3 KiB
Python
Executable File
48 lines
1.3 KiB
Python
Executable File
#!/bin/python3
|
|
import os
|
|
import sys
|
|
import logging
|
|
import requests
|
|
import json
|
|
import argparse
|
|
|
|
sys.path.append(os.path.abspath("../"))
|
|
from subject import main
|
|
|
|
logging.basicConfig(format='%(levelname)s\t- %(message)s')
|
|
logger = logging.getLogger()
|
|
logger.setLevel(logging.INFO)
|
|
|
|
state = main(sys.argv)
|
|
|
|
def reset(args):
|
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument("-k", '--key', nargs=1, help="Path to the key file")
|
|
parser.add_argument("-r", '--repo', nargs=1, help="Address:Port of the repository")
|
|
parser.add_argument("-v", '--verbose', help="Increase verbosity", action="store_true")
|
|
|
|
parser.add_argument('password', nargs='?', default="123")
|
|
|
|
args = parser.parse_args()
|
|
|
|
if not args.password:
|
|
logger.error("Need password")
|
|
sys.exit(1)
|
|
|
|
try:
|
|
req = requests.post(f'http://{state['REP_ADDRESS']}/reset',json=json.dumps({'password' : args.password}))
|
|
req.raise_for_status()
|
|
|
|
except requests.exceptions.HTTPError:
|
|
logger.error("%d: %s", req.status_code, req.json()['error'])
|
|
sys.exit(-1)
|
|
|
|
except requests.exceptions.RequestException as errex:
|
|
logger.error("Failed to obtain response from server.")
|
|
sys.exit(-1)
|
|
|
|
if __name__ == '__main__':
|
|
reset(sys.argv[1:])
|