oc-cdtapi 3.28.1__py3-none-any.whl → 3.30.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
oc_cdtapi/PgQAPI.py CHANGED
@@ -26,7 +26,7 @@ class PgQAPI (object):
26
26
  else:
27
27
  logging.debug('No connection provided, creating')
28
28
  self.conn = self.pg_connect(url, username, password)
29
- self.message_types = ['dlartifacts', 'dlbuild', 'dlcontents', 'dlupload', 'ns']
29
+ self.message_types = ['dlartifacts', 'dlbuild', 'dlcontents', 'dlupload', 'ns', 'register_file']
30
30
 
31
31
  def create_queue(self, queue_code, queue_name):
32
32
  logging.debug('reached create_queue')
@@ -69,6 +69,21 @@ class PgQAPI (object):
69
69
  logging.debug(message)
70
70
  return message
71
71
 
72
+ def compose_register_file(self, parms):
73
+ logging.debug('reached compose_register_file')
74
+ logging.debug('received parms: [%s]' % parms)
75
+
76
+ location = parms.get("location")
77
+ citype = parms.get("citype")
78
+ depth = parms.get("depth")
79
+ if not location or citype is None or depth is None:
80
+ logging.error('location, citype, and depth must all be specified')
81
+ return None
82
+ message = ["register_file", [[*location], citype, depth], {}]
83
+ logging.debug('composed message')
84
+ logging.debug(message)
85
+ return message
86
+
72
87
  def enqueue_message(self, queue_code=None, msg_text=None, priority=50, pg_connection=None):
73
88
  logging.debug('reached enqueue_message')
74
89
  if pg_connection:
oc_cdtapi/VaultAPI.py CHANGED
@@ -1,33 +1,32 @@
1
+ import re
1
2
  import logging
2
3
  import os
4
+ from typing import Any, List, Optional
3
5
 
4
6
  import hvac
7
+ import requests
5
8
  from hvac.exceptions import VaultError
6
9
 
10
+ SECRET_PATTERN = re.compile(r"^[A-Z][A-Z0-9_]*__[A-Z][A-Z0-9_]*$")
11
+
12
+
7
13
  class VaultAPI:
8
14
  def __init__(self,
9
- vault_enable=False,
10
15
  vault_url=None,
11
16
  vault_token=None,
12
17
  vault_mount_point=None,
13
18
  verify_ssl=True):
14
- self.vault_enable = vault_enable or os.getenv("VAULT_ENABLE")
15
19
  self.vault_url = vault_url or os.getenv("VAULT_URL")
16
20
  self.vault_token = vault_token or os.getenv("VAULT_TOKEN")
17
21
  self.mount_point = vault_mount_point or os.getenv("VAULT_MOUNT_POINT")
18
- self.use_staging_secrets = os.getenv("USE_STAGING_ENVIRONMENT", "false").lower() == "true" #Check whether we have env USE_STAGING_ENVIRONMENT true or not
19
22
  self.verify_ssl = verify_ssl
20
23
  self._client = None
21
24
 
22
25
  # Create a logger instance for this class
23
26
  self.logger = logging.getLogger(__name__)
24
-
25
- @property
26
- def client(self):
27
- if not self.vault_enable:
28
- self.logger.warning("VAULT_ENABLE environment set to false, skip using vault")
29
- return None
30
27
 
28
+ @property
29
+ def client(self) -> Optional[hvac.Client]:
31
30
  if self._client is None:
32
31
  if not self.vault_url:
33
32
  self.logger.warning("VAULT_URL environment variable or vault_url parameter is missing, skip using vault")
@@ -41,39 +40,50 @@ class VaultAPI:
41
40
  token=self.vault_token,
42
41
  verify=self.verify_ssl
43
42
  )
44
-
45
- if not self._client.is_authenticated():
43
+ try:
44
+ is_authenticated = self._client.is_authenticated()
45
+ except requests.exceptions.ConnectionError as e:
46
+ self.logger.warning(f"Failed to authenticate with Vault - Vault is unreachable: {e}")
47
+ self._client = None
48
+ return None
49
+ if not is_authenticated:
46
50
  self.logger.warning("Failed to authenticate with Vault - check credentials, skip using vault")
47
51
  return None
48
-
49
52
  return self._client
50
53
 
51
- def parse_secret_name(self, name):
52
- if 'USER' in name:
53
- split_name = name.split('_USER')[0]
54
- return split_name, 'USER'
54
+ def _parse_secret_name(self, name: str) -> List[str]:
55
+ if not SECRET_PATTERN.match(name):
56
+ raise ValueError("Secret name must match <PATH>__<KEY>")
55
57
 
56
- if 'PASSWORD' in name:
57
- split_name = name.split('_PASSWORD')[0]
58
- return split_name, 'PASSWORD'
58
+ return name.split("__", 1)
59
59
 
60
- return 'OTHER', name
61
-
62
- def get_secret_from_path(self, name):
60
+ def get_secret_from_path(self, name: str) -> Optional[Any]:
63
61
  client = self.client
64
62
  if client is None:
65
63
  return None
66
-
67
- secret_path, credentials = self.parse_secret_name(name)
68
- if self.use_staging_secrets:
69
- secret_path = secret_path + "_TEST"
64
+ try:
65
+ secret_path, credentials = self._parse_secret_name(name=name)
66
+ except ValueError as e:
67
+ self.logger.warning(f"Failed parsing secret: {e}")
68
+ return None
70
69
 
71
70
  try:
72
71
  response = client.secrets.kv.read_secret_version(path=secret_path, mount_point=self.mount_point)
73
- return response['data']['data'].get(credentials)
72
+ return response["data"]["data"].get(credentials)
74
73
  except VaultError as e:
75
74
  self.logger.warning(f"Failed getting data from vault for path {secret_path} and credentials {credentials}: {e}")
76
75
  return None
76
+ except requests.exceptions.ConnectionError as e:
77
+ self.logger.warning(f"Failed to retrieve secret from Vault - Vault is unreachable: {e}")
78
+ return None
79
+
80
+ def load_secret(self, name: str, default: Optional[Any] = None) -> Optional[Any]:
81
+ is_test = os.getenv("PYTHON_ENV") == "test"
82
+ if is_test:
83
+ name = f"{name}_TEST"
84
+
85
+ value = self.get_secret_from_path(name=name)
86
+ if value is not None:
87
+ return value
77
88
 
78
- def load_secret(self, name, default=None):
79
- return self.get_secret_from_path(name) or os.getenv(name, default)
89
+ return os.getenv(name, default=default)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: oc-cdtapi
3
- Version: 3.28.1
3
+ Version: 3.30.3
4
4
  Summary: Custom Development python API libraries
5
5
  License: Apache2.0
6
6
  Requires-Python: >=3.6
@@ -7,14 +7,14 @@ oc_cdtapi/ForemanAPI.py,sha256=0GsC9s9uGoYgMbsgBW5aDEGoGLGeRPJJSTAWhbelhVY,57135
7
7
  oc_cdtapi/JenkinsAPI.py,sha256=lZ8pe3a4eb_6h53JE7QLuzOSlu7Sqatc9PQwWhio9Vg,15748
8
8
  oc_cdtapi/NexusAPI.py,sha256=uU12GtHvKlWorFaPAnFcQ5AGEc94MZ5SdmfM2Pw3F7A,26122
9
9
  oc_cdtapi/PgAPI.py,sha256=URSz7qu-Ir7AOj0jI3ucTXn2PM-nC96nmPZI746OLjA,14356
10
- oc_cdtapi/PgQAPI.py,sha256=VwnI6Hm6d0guwuFVrJxr-SvDz0V1NIO6Qh195WgXsEk,8822
10
+ oc_cdtapi/PgQAPI.py,sha256=MJzzm9XGkrMQ8mjoM4WeS1KYAgLeCL73yga8kB-HoUk,9436
11
11
  oc_cdtapi/RundeckAPI.py,sha256=O3LmcFaHSz8UqeUyIHTTEMJncDD191Utd-iZaeJay2s,24243
12
12
  oc_cdtapi/TestServer.py,sha256=HV97UWg2IK4gOYAp9yaMdwFUWsw9v66MxyZdI3qQctA,2715
13
- oc_cdtapi/VaultAPI.py,sha256=P-x_PsWe_S0mGUKTCmR1KhUjdfs7GmyaltjGQcnWj_s,2967
13
+ oc_cdtapi/VaultAPI.py,sha256=Vp-tY28rVeVT4zwemH2lKDr7xI0kPXsfzBYFYLveG2o,3380
14
14
  oc_cdtapi/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
15
- oc_cdtapi-3.28.1.data/scripts/nexus.py,sha256=4teqZ_KtCSrwHDJVgA7lkreteod4Xt5XJFZNbwb7E6E,6858
16
- oc_cdtapi-3.28.1.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
17
- oc_cdtapi-3.28.1.dist-info/METADATA,sha256=0VzwXmwuzjqdH9LNfO08rOSM9yoc5aQn5PkbNPznHK8,504
18
- oc_cdtapi-3.28.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
19
- oc_cdtapi-3.28.1.dist-info/top_level.txt,sha256=d4-5-D-0CSeSXYuLCP7-nIFCpjkfmJr-Y_muzds8iVU,10
20
- oc_cdtapi-3.28.1.dist-info/RECORD,,
15
+ oc_cdtapi-3.30.3.data/scripts/nexus.py,sha256=4teqZ_KtCSrwHDJVgA7lkreteod4Xt5XJFZNbwb7E6E,6858
16
+ oc_cdtapi-3.30.3.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
17
+ oc_cdtapi-3.30.3.dist-info/METADATA,sha256=mptP1lE_iMD-16miVFs4RtSvPsClWFdIiOgP07IBlvE,504
18
+ oc_cdtapi-3.30.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
19
+ oc_cdtapi-3.30.3.dist-info/top_level.txt,sha256=d4-5-D-0CSeSXYuLCP7-nIFCpjkfmJr-Y_muzds8iVU,10
20
+ oc_cdtapi-3.30.3.dist-info/RECORD,,