From 49e74caeebfd308cf782439c24dd63ea4f1f99ac Mon Sep 17 00:00:00 2001 From: Alejandro Sirgo Rica Date: Thu, 21 Nov 2024 11:34:20 +0100 Subject: cli: move config.py into cli/ folder --- cli/cli.py | 2 +- cli/config.py | 31 +++++++++++++++++++++++++++++++ config.py | 31 ------------------------------- 3 files changed, 32 insertions(+), 32 deletions(-) create mode 100644 cli/config.py delete mode 100755 config.py diff --git a/cli/cli.py b/cli/cli.py index 0e34cd0..e62ec4c 100644 --- a/cli/cli.py +++ b/cli/cli.py @@ -20,7 +20,7 @@ from cli.objects.center import OgCenter from cli.objects.room import OgRoom from cli.objects.folder import OgFolder from cli.objects.session import OgSession -from config import cfg +from cli.config import cfg import argparse import requests import sys diff --git a/cli/config.py b/cli/config.py new file mode 100644 index 0000000..5a79698 --- /dev/null +++ b/cli/config.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python3 + +# Copyright (C) 2020-2024 Soleta Networks +# +# This program is free software: you can redistribute it and/or modify it under +# the terms of the GNU Affero General Public License as published by the +# Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. + +import json + +OG_CLI_CFG_PATH = "/opt/opengnsys/etc/ogcli.json" + +def load_config(): + data = None + try: + with open(OG_CLI_CFG_PATH, 'r') as json_file: + data = json.load(json_file) + except json.JSONDecodeError: + sys.exit(f'ERROR: Failed parse malformed JSON file {OG_CLI_CFG_PATH}') + except Exception as e: + sys.exit(f'ERROR: cannot open {OG_CLI_CFG_PATH}: {e}') + + required_cfg_params = {'api_token', 'ip', 'port'} + difference_cfg_params = required_cfg_params - data.keys() + if len(difference_cfg_params) > 0: + sys.exit(f'Missing {difference_cfg_params} key in ' + f'json config file') + return data + +cfg = load_config() diff --git a/config.py b/config.py deleted file mode 100755 index 5a79698..0000000 --- a/config.py +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env python3 - -# Copyright (C) 2020-2024 Soleta Networks -# -# This program is free software: you can redistribute it and/or modify it under -# the terms of the GNU Affero General Public License as published by the -# Free Software Foundation; either version 3 of the License, or -# (at your option) any later version. - -import json - -OG_CLI_CFG_PATH = "/opt/opengnsys/etc/ogcli.json" - -def load_config(): - data = None - try: - with open(OG_CLI_CFG_PATH, 'r') as json_file: - data = json.load(json_file) - except json.JSONDecodeError: - sys.exit(f'ERROR: Failed parse malformed JSON file {OG_CLI_CFG_PATH}') - except Exception as e: - sys.exit(f'ERROR: cannot open {OG_CLI_CFG_PATH}: {e}') - - required_cfg_params = {'api_token', 'ip', 'port'} - difference_cfg_params = required_cfg_params - data.keys() - if len(difference_cfg_params) > 0: - sys.exit(f'Missing {difference_cfg_params} key in ' - f'json config file') - return data - -cfg = load_config() -- cgit v1.2.3-18-g5258