oc-cdtapi 3.20.0__py3-none-any.whl → 3.21.5__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/VaultAPI.py +76 -0
- {oc_cdtapi-3.20.0.dist-info → oc_cdtapi-3.21.5.dist-info}/METADATA +2 -1
- {oc_cdtapi-3.20.0.dist-info → oc_cdtapi-3.21.5.dist-info}/RECORD +7 -6
- {oc_cdtapi-3.20.0.data → oc_cdtapi-3.21.5.data}/scripts/nexus.py +0 -0
- {oc_cdtapi-3.20.0.dist-info → oc_cdtapi-3.21.5.dist-info}/WHEEL +0 -0
- {oc_cdtapi-3.20.0.dist-info → oc_cdtapi-3.21.5.dist-info}/licenses/LICENSE +0 -0
- {oc_cdtapi-3.20.0.dist-info → oc_cdtapi-3.21.5.dist-info}/top_level.txt +0 -0
oc_cdtapi/VaultAPI.py
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
import logging
|
2
|
+
import os
|
3
|
+
|
4
|
+
import hvac
|
5
|
+
from hvac.exceptions import VaultError
|
6
|
+
|
7
|
+
class VaultAPI:
|
8
|
+
def __init__(self,
|
9
|
+
vault_enable=False,
|
10
|
+
vault_url=None,
|
11
|
+
vault_token=None,
|
12
|
+
vault_mount_point=None,
|
13
|
+
verify_ssl=True):
|
14
|
+
self.vault_enable = vault_enable or os.getenv("VAULT_ENABLE")
|
15
|
+
self.vault_url = vault_url or os.getenv("VAULT_URL")
|
16
|
+
self.vault_token = vault_token or os.getenv("VAULT_TOKEN")
|
17
|
+
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
|
+
self.verify_ssl = verify_ssl
|
20
|
+
self._client = None
|
21
|
+
|
22
|
+
@property
|
23
|
+
def client(self):
|
24
|
+
if not self.vault_enable:
|
25
|
+
logging.warning("VAULT_ENABLE environment set to false, skip using vault")
|
26
|
+
return None
|
27
|
+
|
28
|
+
if self._client is None:
|
29
|
+
if not self.vault_url:
|
30
|
+
logging.warning("VAULT_URL environment variable or vault_url parameter is missing, skip using vault")
|
31
|
+
return None
|
32
|
+
if not self.vault_token:
|
33
|
+
logging.warning("VAULT_TOKEN environment variable or vault_token parameter is missing, skip using vault")
|
34
|
+
return None
|
35
|
+
|
36
|
+
self._client = hvac.Client(
|
37
|
+
url=self.vault_url,
|
38
|
+
token=self.vault_token,
|
39
|
+
verify=self.verify_ssl
|
40
|
+
)
|
41
|
+
|
42
|
+
if not self._client.is_authenticated():
|
43
|
+
logging.warning("Failed to authenticate with Vault - check credentials, skip using vault")
|
44
|
+
return None
|
45
|
+
|
46
|
+
return self._client
|
47
|
+
|
48
|
+
def parse_secret_name(self, name):
|
49
|
+
if 'USER' in name:
|
50
|
+
split_name = name.split('_USER')[0]
|
51
|
+
return split_name, 'USER'
|
52
|
+
|
53
|
+
if 'PASSWORD' in name:
|
54
|
+
split_name = name.split('_PASSWORD')[0]
|
55
|
+
return split_name, 'PASSWORD'
|
56
|
+
|
57
|
+
return 'OTHER', name
|
58
|
+
|
59
|
+
def get_secret_from_path(self, name):
|
60
|
+
client = self.client
|
61
|
+
if client is None:
|
62
|
+
return None
|
63
|
+
|
64
|
+
secret_path, credentials = self.parse_secret_name(name)
|
65
|
+
if self.use_staging_secrets:
|
66
|
+
secret_path = secret_path + "_TEST"
|
67
|
+
|
68
|
+
try:
|
69
|
+
response = client.secrets.kv.read_secret_version(path=secret_path, mount_point=self.mount_point)
|
70
|
+
return response['data']['data'].get(credentials)
|
71
|
+
except VaultError as e:
|
72
|
+
logging.warning(f"Failed getting data from vault for path {secret_path} and credentials {credentials}: {e}")
|
73
|
+
return None
|
74
|
+
|
75
|
+
def load_secret(self, name, default=None):
|
76
|
+
return self.get_secret_from_path(name) or os.getenv(name, default)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: oc-cdtapi
|
3
|
-
Version: 3.
|
3
|
+
Version: 3.21.5
|
4
4
|
Summary: Custom Development python API libraries
|
5
5
|
License: Apache2.0
|
6
6
|
Requires-Python: >=3.6
|
@@ -9,6 +9,7 @@ License-File: LICENSE
|
|
9
9
|
Requires-Dist: requests
|
10
10
|
Requires-Dist: packaging
|
11
11
|
Requires-Dist: psycopg2-binary
|
12
|
+
Requires-Dist: hvac
|
12
13
|
Dynamic: description
|
13
14
|
Dynamic: description-content-type
|
14
15
|
Dynamic: license
|
@@ -10,10 +10,11 @@ oc_cdtapi/PgAPI.py,sha256=URSz7qu-Ir7AOj0jI3ucTXn2PM-nC96nmPZI746OLjA,14356
|
|
10
10
|
oc_cdtapi/PgQAPI.py,sha256=CUN3TSvyglglJ5EgzIt-iE7PX6atKKycoPMHyLkT6oA,8658
|
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=OgKS5GFDAzs_6YlAv412OzFy2Cd4H1z-KjBGKfb__tY,2838
|
13
14
|
oc_cdtapi/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
14
|
-
oc_cdtapi-3.
|
15
|
-
oc_cdtapi-3.
|
16
|
-
oc_cdtapi-3.
|
17
|
-
oc_cdtapi-3.
|
18
|
-
oc_cdtapi-3.
|
19
|
-
oc_cdtapi-3.
|
15
|
+
oc_cdtapi-3.21.5.data/scripts/nexus.py,sha256=4teqZ_KtCSrwHDJVgA7lkreteod4Xt5XJFZNbwb7E6E,6858
|
16
|
+
oc_cdtapi-3.21.5.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
17
|
+
oc_cdtapi-3.21.5.dist-info/METADATA,sha256=6Ea8d0B0yVRLtl9OI9JDgqZprnX5IShStL4mEyRrfbY,504
|
18
|
+
oc_cdtapi-3.21.5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
19
|
+
oc_cdtapi-3.21.5.dist-info/top_level.txt,sha256=d4-5-D-0CSeSXYuLCP7-nIFCpjkfmJr-Y_muzds8iVU,10
|
20
|
+
oc_cdtapi-3.21.5.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|