From a219bc7ff729516aea7ddea8516b50d96e7d9363 Mon Sep 17 00:00:00 2001 From: Alejandro Sirgo Rica Date: Wed, 6 Nov 2024 13:19:26 +0100 Subject: ogcli: move configuration data into a different file Move the configuration into its own file so it is easier to access from multiple files. --- ogcli | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) (limited to 'ogcli') diff --git a/ogcli b/ogcli index f4b55d5..8ed9903 100755 --- a/ogcli +++ b/ogcli @@ -15,8 +15,6 @@ import argparse import json import sys -OG_CLI_CFG_PATH = "/opt/opengnsys/etc/ogcli.json" - def sigint_handler(signum, frame): print("User has pressed ctrl-C, interrupting...") sys.exit(1) @@ -25,22 +23,8 @@ class CLI(): def __init__(self): signal.signal(signal.SIGPIPE, signal.SIG_DFL) signal.signal(signal.SIGINT, sigint_handler) - try: - with open(OG_CLI_CFG_PATH, 'r') as json_file: - self.cfg = json.load(json_file) - except json.JSONDecodeError: - sys.exit(f'ERROR: Failed parse malformed JSON file ' - f'{OG_CLI_CFG_PATH}') - except: - sys.exit(f'ERROR: cannot open {OG_CLI_CFG_PATH}') - - required_cfg_params = {'api_token', 'ip', 'port'} - difference_cfg_params = required_cfg_params - self.cfg.keys() - if len(difference_cfg_params) > 0: - sys.exit(f'Missing {difference_cfg_params} key in ' - f'json config file') - self.ogcli = OgCLI(self.cfg) + self.ogcli = OgCLI() parser = argparse.ArgumentParser(prog='ogcli') parser.add_argument('command', help='Subcommand to run', nargs='?', -- cgit v1.2.3-18-g5258