oc-cdtapi 3.19.4__py3-none-any.whl → 3.21.2__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/PgAPI.py +34 -1
- oc_cdtapi/VaultAPI.py +62 -0
- {oc_cdtapi-3.19.4.dist-info → oc_cdtapi-3.21.2.dist-info}/METADATA +2 -1
- {oc_cdtapi-3.19.4.dist-info → oc_cdtapi-3.21.2.dist-info}/RECORD +8 -7
- {oc_cdtapi-3.19.4.data → oc_cdtapi-3.21.2.data}/scripts/nexus.py +0 -0
- {oc_cdtapi-3.19.4.dist-info → oc_cdtapi-3.21.2.dist-info}/WHEEL +0 -0
- {oc_cdtapi-3.19.4.dist-info → oc_cdtapi-3.21.2.dist-info}/licenses/LICENSE +0 -0
- {oc_cdtapi-3.19.4.dist-info → oc_cdtapi-3.21.2.dist-info}/top_level.txt +0 -0
oc_cdtapi/PgAPI.py
CHANGED
@@ -401,4 +401,37 @@ class PostgresAPI(API.HttpAPI):
|
|
401
401
|
req = f"rest/api/1/clients/{code}"
|
402
402
|
res = self.get(req)
|
403
403
|
|
404
|
-
return res.json()
|
404
|
+
return res.json()
|
405
|
+
|
406
|
+
def post_new_component(self, payload):
|
407
|
+
"""
|
408
|
+
Post new component to the ci database.
|
409
|
+
|
410
|
+
This method sends a POST request to add new component into ci database.
|
411
|
+
|
412
|
+
Args:
|
413
|
+
payload : New component payload.
|
414
|
+
|
415
|
+
Returns:
|
416
|
+
requests.Response: The response object from the API call.
|
417
|
+
|
418
|
+
Example:
|
419
|
+
>>> payload = {
|
420
|
+
"ci_type_id": "NEWDSTR",
|
421
|
+
"ci_type_group_id": "NEW",
|
422
|
+
"name": "New component",
|
423
|
+
"is_standard": "Y",
|
424
|
+
"is_deliverable": True,
|
425
|
+
"regexp": "test.regexp.NEWDSTR:dstr:com",
|
426
|
+
"loc_type_id": "NXS",
|
427
|
+
"dms_id": "NEWDSTR"
|
428
|
+
}
|
429
|
+
>>> result = self.post_new_component(payload)
|
430
|
+
>>> print(result.status_code)
|
431
|
+
200
|
432
|
+
"""
|
433
|
+
req = f"rest/api/1/manage_citype"
|
434
|
+
res = self.post(req, json=payload)
|
435
|
+
logging.debug(f'Using post_manage_citype to register new component')
|
436
|
+
|
437
|
+
return res
|
oc_cdtapi/VaultAPI.py
ADDED
@@ -0,0 +1,62 @@
|
|
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_path=None,
|
13
|
+
vault_mount_point=None,
|
14
|
+
verify_ssl=True):
|
15
|
+
self.vault_enable = vault_enable or os.getenv("VAULT_ENABLE")
|
16
|
+
self.vault_url = vault_url or os.getenv("VAULT_URL")
|
17
|
+
self.vault_token = vault_token or os.getenv("VAULT_TOKEN")
|
18
|
+
self.vault_path = vault_path or os.getenv("VAULT_PATH")
|
19
|
+
self.mount_point = vault_mount_point or os.getenv("VAULT_MOUNT_POINT")
|
20
|
+
self.verify_ssl = verify_ssl
|
21
|
+
self._client = None
|
22
|
+
|
23
|
+
@property
|
24
|
+
def client(self):
|
25
|
+
if not self.vault_enable:
|
26
|
+
logging.warning("VAULT_ENABLE environment set to false, skip using vault")
|
27
|
+
return None
|
28
|
+
|
29
|
+
if self._client is None:
|
30
|
+
if not self.vault_url:
|
31
|
+
logging.warning("VAULT_URL environment variable or vault_url parameter is missing, skip using vault")
|
32
|
+
return None
|
33
|
+
if not self.vault_token:
|
34
|
+
logging.warning("VAULT_TOKEN environment variable or vault_token parameter is missing, skip using vault")
|
35
|
+
return None
|
36
|
+
|
37
|
+
self._client = hvac.Client(
|
38
|
+
url=self.vault_url,
|
39
|
+
token=self.vault_token,
|
40
|
+
verify=self.verify_ssl
|
41
|
+
)
|
42
|
+
|
43
|
+
if not self._client.is_authenticated():
|
44
|
+
logging.warning("Failed to authenticate with Vault - check credentials, skip using vault")
|
45
|
+
return None
|
46
|
+
|
47
|
+
return self._client
|
48
|
+
|
49
|
+
def get_secret_from_path(self, name):
|
50
|
+
client = self.client
|
51
|
+
if client is None:
|
52
|
+
return None
|
53
|
+
|
54
|
+
try:
|
55
|
+
response = client.secrets.kv.read_secret_version(path=self.vault_path, mount_point=self.mount_point)
|
56
|
+
return response['data']['data'].get(name)
|
57
|
+
except VaultError as e:
|
58
|
+
logging.warning(f"Failed getting data from vault: {e}")
|
59
|
+
return None
|
60
|
+
|
61
|
+
def load_secret(self, name, default=None):
|
62
|
+
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.2
|
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
|
@@ -6,14 +6,15 @@ oc_cdtapi/DmsGetverAPI.py,sha256=ZPU4HlF59fngKu5mSFhtss3rlBuduffDOSm_y3XWrxk,155
|
|
6
6
|
oc_cdtapi/ForemanAPI.py,sha256=9r1MSOsubiSxM1sdzF2MHD7IcSwX9Y4UDJknHqQK07g,44255
|
7
7
|
oc_cdtapi/JenkinsAPI.py,sha256=lZ8pe3a4eb_6h53JE7QLuzOSlu7Sqatc9PQwWhio9Vg,15748
|
8
8
|
oc_cdtapi/NexusAPI.py,sha256=uU12GtHvKlWorFaPAnFcQ5AGEc94MZ5SdmfM2Pw3F7A,26122
|
9
|
-
oc_cdtapi/PgAPI.py,sha256=
|
9
|
+
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=4-fIFJ6x7BFaF6YJIRY0QKW2umGVGlGKZqx_gldI0ow,2259
|
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.2.data/scripts/nexus.py,sha256=4teqZ_KtCSrwHDJVgA7lkreteod4Xt5XJFZNbwb7E6E,6858
|
16
|
+
oc_cdtapi-3.21.2.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
17
|
+
oc_cdtapi-3.21.2.dist-info/METADATA,sha256=Ss_KnNrUfZKUqThcxOc3BmgOzgm182tXiciWvuQwlBU,504
|
18
|
+
oc_cdtapi-3.21.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
19
|
+
oc_cdtapi-3.21.2.dist-info/top_level.txt,sha256=d4-5-D-0CSeSXYuLCP7-nIFCpjkfmJr-Y_muzds8iVU,10
|
20
|
+
oc_cdtapi-3.21.2.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|