diff options
Diffstat (limited to 'src/onapsdk/configuration')
-rw-r--r-- | src/onapsdk/configuration/__init__.py | 18 | ||||
-rw-r--r-- | src/onapsdk/configuration/global_settings.py | 71 | ||||
-rw-r--r-- | src/onapsdk/configuration/loader.py | 115 |
3 files changed, 204 insertions, 0 deletions
diff --git a/src/onapsdk/configuration/__init__.py b/src/onapsdk/configuration/__init__.py new file mode 100644 index 0000000..027e7ef --- /dev/null +++ b/src/onapsdk/configuration/__init__.py @@ -0,0 +1,18 @@ +"""Configuration module.""" +# Copyright 2022 Orange, Deutsche Telekom AG +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +from .loader import SettingsLoader, SETTINGS_ENV + + +settings = SettingsLoader() # pylint: disable=invalid-name diff --git a/src/onapsdk/configuration/global_settings.py b/src/onapsdk/configuration/global_settings.py new file mode 100644 index 0000000..6f7e4d7 --- /dev/null +++ b/src/onapsdk/configuration/global_settings.py @@ -0,0 +1,71 @@ +"""Global settings module.""" # pylint: disable=bad-whitespace +# Copyright 2022 Orange, Deutsche Telekom AG +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +###################### +# # +# ONAP SERVICES URLS # +# # +###################### + +## API +AAI_URL = "https://aai.api.sparky.simpledemo.onap.org:30233" +AAI_API_VERSION = "v23" +AAI_AUTH = "Basic QUFJOkFBSQ==" +AAI_BULK_CHUNK = 30 +CDS_URL = "http://portal.api.simpledemo.onap.org:30449" +CDS_AUTH = ("ccsdkapps", "ccsdkapps") +CPS_URL = "http://portal.api.simpledemo.onap.org:8080" +CPS_AUTH = ("cpsuser", "cpsr0cks!") +MSB_URL = "https://msb.api.simpledemo.onap.org:30283" +SDC_BE_URL = "https://sdc.api.be.simpledemo.onap.org:30204" +SDC_FE_URL = "https://sdc.api.fe.simpledemo.onap.org:30207" +SDC_AUTH = "Basic YWFpOktwOGJKNFNYc3pNMFdYbGhhazNlSGxjc2UyZ0F3ODR2YW9HR21KdlV5MlU=" +SDNC_URL = "https://sdnc.api.simpledemo.onap.org:30267" +SDNC_AUTH = "Basic YWRtaW46S3A4Yko0U1hzek0wV1hsaGFrM2VIbGNzZTJnQXc4NHZhb0dHbUp2VXkyVQ==" +SO_URL = "http://so.api.simpledemo.onap.org:30277" +SO_API_VERSION = "v7" +SO_AUTH = "Basic SW5mcmFQb3J0YWxDbGllbnQ6cGFzc3dvcmQxJA==" +SO_CAT_DB_AUTH = "Basic YnBlbDpwYXNzd29yZDEk" +VID_URL = "https://vid.api.simpledemo.onap.org:30200" +VID_API_VERSION = "/vid" +CLAMP_URL = "https://clamp.api.simpledemo.onap.org:30258" +CLAMP_AUTH = "Basic ZGVtb0BwZW9wbGUub3NhYWYub3JnOmRlbW8xMjM0NTYh" +VES_URL = "http://ves.api.simpledemo.onap.org:30417" +DMAAP_URL = "http://dmaap.api.simpledemo.onap.org:3904" +NBI_URL = "https://nbi.api.simpledemo.onap.org:30274" +NBI_API_VERSION = "/nbi/api/v4" +DCAEMOD_URL = "" +HOLMES_URL = "https://aai.api.sparky.simpledemo.onap.org:30293" +POLICY_URL = "" + +## GUI +AAI_GUI_URL = "https://aai.api.sparky.simpledemo.onap.org:30220" +AAI_GUI_SERVICE = f"{AAI_GUI_URL}/services/aai/webapp/index.html#/browse" +CDS_GUI_SERVICE = f"{CDS_URL}/" +SO_MONITOR_GUI_SERVICE = f"{SO_URL}/" +SDC_GUI_SERVICE = f"{SDC_FE_URL}/sdc1/portal" +SDNC_DG_GUI_SERVICE = f"{SDNC_URL}/nifi/" +SDNC_ODL_GUI_SERVICE = f"{SDNC_URL}/odlux/index.html" + +DCAEMOD_GUI_SERVICE = f"{DCAEMOD_URL}/" +HOLMES_GUI_SERVICE = f"{HOLMES_URL}/iui/holmes/default.html" +POLICY_GUI_SERVICE = f"{POLICY_URL}/onap/login.html" +POLICY_CLAMP_GUI_SERVICE = f"{CLAMP_URL}/" + +# VID OBJECTS DEFAULT VALUES +PROJECT = "Onapsdk_project" +LOB = "Onapsdk_lob" +PLATFORM = "Onapsdk_platform" diff --git a/src/onapsdk/configuration/loader.py b/src/onapsdk/configuration/loader.py new file mode 100644 index 0000000..a9aae6f --- /dev/null +++ b/src/onapsdk/configuration/loader.py @@ -0,0 +1,115 @@ +"""Settings loader module.""" +# Copyright 2022 Orange, Deutsche Telekom AG +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import importlib +import os +from typing import Any + +from onapsdk.exceptions import ModuleError, SettingsError + +from . import global_settings + + +SETTINGS_ENV = "ONAP_PYTHON_SDK_SETTINGS" + + +class SettingsLoader: + """Settings loader class. + + Load global settings and optionally load + custom settings by importing the module + stored in ONAP_PYTHON_SDK_SETTINGS environment + variable. + The module has to be uder PYTHONPATH. + """ + + def __init__(self) -> None: + """Load settings. + + Load global settings and optionally load custom one. + + Raises: + ModuleError: If ONAP_PYTHON_SDK_SETTINGS environment variable + is set and module can't be imported. + + """ + self._settings = {} + + # Load values from global_settings (only uppercase) + self.filter_and_set(global_settings) + + settings_env_value: str = os.environ.get(SETTINGS_ENV) + if settings_env_value: + # Load values from custom settings + try: + module = importlib.import_module(settings_env_value) + except ModuleNotFoundError: + msg = "Can't import custom settings. Is it under PYTHONPATH?" + raise ModuleError(msg) + self.filter_and_set(module) + + def __getattribute__(self, name: str) -> Any: + """Return stored attributes. + + If attribute name is uppercase return it from + _settings dictionary. + Look for attribute in __dict__ otherwise. + + Args: + name (str): Attribute's name + + Raises: + SettingsError: a setting is not found by the key. + + Returns: + Any: Attribute's value + + """ + if name.isupper(): + try: + return self._settings[name] + except KeyError as exc: + msg = f"Requested setting {exc.args[0]} does not exist." + raise SettingsError(msg) from exc + return super().__getattribute__(name) + + def __setattr__(self, name: str, value: Any) -> None: + """Save attribute. + + If attribute name is uppercase save the value + in _settings dictionary. + Use Object class __setattr__ implementation + otherwise. + + Args: + name (str): Attribute's name + value (Any): Attribute's value + + """ + if name.isupper(): + self._settings[name] = value + super().__setattr__(name, value) + + def filter_and_set(self, module: "module") -> None: + """Filter module attributes and save the uppercased. + + Iterate through module's attribures and save the value + of them which name is uppercase. + + Args: + module (module): Module to get attributes from + + """ + for key in filter(lambda x: x.isupper(), dir(module)): + self._settings[key] = getattr(module, key) |