diff options
author | 2020-04-21 13:39:35 +0100 | |
---|---|---|
committer | 2020-04-22 14:41:17 +0100 | |
commit | ae21e35b8eb8008cf1a3119bab2ad987db9f9e7f (patch) | |
tree | 22769a4a52169095f37f0ed4377355771d7910ad /components/pm-subscription-handler/pmsh_service/mod/pmsh_utils.py | |
parent | 8c68d73eb231da211abe962478c1c77d49665874 (diff) |
[PMSH] Adding cbs module support
Signed-off-by: efiacor <fiachra.corcoran@est.tech>
Change-Id: Ie711995a3c7a2111f6cb872952507f511c0de6dd
Issue-ID: DCAEGEN2-2156
Diffstat (limited to 'components/pm-subscription-handler/pmsh_service/mod/pmsh_utils.py')
-rwxr-xr-x | components/pm-subscription-handler/pmsh_service/mod/pmsh_utils.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/components/pm-subscription-handler/pmsh_service/mod/pmsh_utils.py b/components/pm-subscription-handler/pmsh_service/mod/pmsh_utils.py index 750b7211..8db3c1f8 100755 --- a/components/pm-subscription-handler/pmsh_service/mod/pmsh_utils.py +++ b/components/pm-subscription-handler/pmsh_service/mod/pmsh_utils.py @@ -20,11 +20,36 @@ import uuid from threading import Timer import requests +from onap_dcae_cbs_docker_client.client import get_all from requests.auth import HTTPBasicAuth +from tenacity import wait_fixed, stop_after_attempt, retry, retry_if_exception_type import mod.pmsh_logging as logger +class ConfigHandler: + """ Handles retrieval of PMSH's configuration from Configbinding service.""" + @staticmethod + @retry(wait=wait_fixed(2), stop=stop_after_attempt(5), retry=retry_if_exception_type(Exception)) + def get_pmsh_config(): + """ Retrieves PMSH's configuration from Config binding service. If a non-2xx response + is received, it retries after 2 seconds for 5 times before raising an exception. + + Returns: + dict: Dictionary representation of the the service configuration + + Raises: + Exception: If any error occurred pulling configuration from Config binding service. + """ + try: + config = get_all() + logger.debug(f'PMSH config from CBS: {config}') + return config + except Exception as err: + logger.debug(f'Failed to get config from CBS: {err}') + raise Exception + + class AppConfig: def __init__(self, **kwargs): self.aaf_creds = {'aaf_id': kwargs.get('aaf_identity'), |