summaryrefslogtreecommitdiffstats
path: root/components/pm-subscription-handler/pmsh_service/mod/pmsh_utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'components/pm-subscription-handler/pmsh_service/mod/pmsh_utils.py')
-rwxr-xr-xcomponents/pm-subscription-handler/pmsh_service/mod/pmsh_utils.py25
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'),