osbot-utils 1.29.0__py3-none-any.whl → 1.30.0__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.
- osbot_utils/helpers/Hashicorp_Secrets.py +101 -0
- osbot_utils/helpers/trace/Trace_Call.py +2 -2
- osbot_utils/utils/Env.py +2 -2
- osbot_utils/version +1 -1
- {osbot_utils-1.29.0.dist-info → osbot_utils-1.30.0.dist-info}/METADATA +2 -2
- {osbot_utils-1.29.0.dist-info → osbot_utils-1.30.0.dist-info}/RECORD +8 -7
- {osbot_utils-1.29.0.dist-info → osbot_utils-1.30.0.dist-info}/LICENSE +0 -0
- {osbot_utils-1.29.0.dist-info → osbot_utils-1.30.0.dist-info}/WHEEL +0 -0
@@ -0,0 +1,101 @@
|
|
1
|
+
from osbot_utils.utils.Env import get_env
|
2
|
+
from osbot_utils.base_classes.Type_Safe import Type_Safe
|
3
|
+
from osbot_utils.utils.Lists import list_index_by
|
4
|
+
from osbot_utils.utils.Misc import list_set
|
5
|
+
|
6
|
+
ENV_VAR__HCP_ACCESS_TOKEN = 'HCP_ACCESS_TOKEN'
|
7
|
+
ENV_VAR__HCP_APP_NAME = 'HCP_APP_NAME'
|
8
|
+
ENV_VAR__HCP_CLIENT_ID = 'HCP_CLIENT_ID'
|
9
|
+
ENV_VAR__HCP_CLIENT_SECRET = 'HCP_CLIENT_SECRET'
|
10
|
+
ENV_VAR__HCP_ORGANIZATION_ID = 'HCP_ORGANIZATION_ID'
|
11
|
+
ENV_VAR__HCP_PROJECT_ID = 'HCP_PROJECT_ID'
|
12
|
+
|
13
|
+
class Hashicorp_Secrets(Type_Safe):
|
14
|
+
|
15
|
+
# helper methods
|
16
|
+
def hcp__auth_details(self):
|
17
|
+
client_id = get_env(ENV_VAR__HCP_CLIENT_ID)
|
18
|
+
client_secret = get_env(ENV_VAR__HCP_CLIENT_SECRET)
|
19
|
+
return client_id, client_secret
|
20
|
+
|
21
|
+
def hcp__access_token(self): # todo: refactor to remove dependency on requests package (which is not part of the OSBOt_utils project)
|
22
|
+
import requests
|
23
|
+
|
24
|
+
access_token = get_env(ENV_VAR__HCP_ACCESS_TOKEN) # todo: add better way to detect when the access token as expired
|
25
|
+
if not access_token:
|
26
|
+
|
27
|
+
client_id, client_secret = self.hcp__auth_details()
|
28
|
+
token_url = 'https://auth.idp.hashicorp.com/oauth2/token'
|
29
|
+
payload = { 'client_id' : client_id ,
|
30
|
+
'client_secret' : client_secret ,
|
31
|
+
'grant_type' : 'client_credentials' ,
|
32
|
+
'audience' : 'https://api.hashicorp.cloud' }
|
33
|
+
|
34
|
+
response = requests.post(token_url, data=payload) # todo: refactor into requests_post method
|
35
|
+
if response.status_code == 200:
|
36
|
+
access_token = response.json().get('access_token')
|
37
|
+
return access_token
|
38
|
+
|
39
|
+
def hcp__enabled(self):
|
40
|
+
if self.hcp__organization_id():
|
41
|
+
if self.hcp__project_id():
|
42
|
+
return True
|
43
|
+
return False
|
44
|
+
|
45
|
+
def hcp__app_name(self):
|
46
|
+
return get_env(ENV_VAR__HCP_APP_NAME)
|
47
|
+
|
48
|
+
def hcp__organization_id(self):
|
49
|
+
return get_env(ENV_VAR__HCP_ORGANIZATION_ID)
|
50
|
+
|
51
|
+
def hcp__project_id(self):
|
52
|
+
return get_env(ENV_VAR__HCP_PROJECT_ID)
|
53
|
+
|
54
|
+
def requests_get(self, path, data_field=None):
|
55
|
+
import requests
|
56
|
+
|
57
|
+
organization_id = self.hcp__organization_id()
|
58
|
+
project_id = self.hcp__project_id()
|
59
|
+
headers = {'Authorization': f"Bearer { self.hcp__access_token()}" }
|
60
|
+
url = f"https://api.cloud.hashicorp.com/secrets/2023-06-13/organizations/{organization_id}/projects/{project_id}/{path}"
|
61
|
+
response = requests.get(url, headers=headers)
|
62
|
+
if response.status_code == 200:
|
63
|
+
json_data = response.json()
|
64
|
+
if data_field is None:
|
65
|
+
data_field = path
|
66
|
+
return json_data.get(data_field)
|
67
|
+
return {}
|
68
|
+
|
69
|
+
# API methods
|
70
|
+
def app_secrets(self, app_name=None):
|
71
|
+
if app_name is None:
|
72
|
+
app_name = self.hcp__app_name()
|
73
|
+
path_secrets = f'apps/{app_name}/secrets'
|
74
|
+
app_secrets = self.requests_get(path_secrets, 'secrets')
|
75
|
+
return app_secrets
|
76
|
+
|
77
|
+
def app_secrets_open(self, app_name=None):
|
78
|
+
if app_name is None:
|
79
|
+
app_name = self.hcp__app_name()
|
80
|
+
path_secrets = f'apps/{app_name}/open'
|
81
|
+
app_secrets = self.requests_get(path_secrets, 'secrets')
|
82
|
+
return app_secrets
|
83
|
+
|
84
|
+
def app_secrets_names(self, app_name=None):
|
85
|
+
app_secrets = self.app_secrets(app_name)
|
86
|
+
return list_set(list_index_by(app_secrets, 'name'))
|
87
|
+
|
88
|
+
def app_secrets_values(self, app_name=None):
|
89
|
+
secrets_values = {}
|
90
|
+
app_secrets = self.app_secrets_open(app_name)
|
91
|
+
for app_secret in app_secrets:
|
92
|
+
secret_name = app_secret.get('name' )
|
93
|
+
secret_value = app_secret.get('version', {}).get('value')
|
94
|
+
secrets_values[secret_name] = secret_value
|
95
|
+
return secrets_values
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
def apps(self):
|
100
|
+
return self.requests_get('apps')
|
101
|
+
|
@@ -11,8 +11,8 @@ from osbot_utils.helpers.trace.Trace_Call__View_Model import Trace_Call__V
|
|
11
11
|
|
12
12
|
|
13
13
|
def trace_calls(title = None , print_traces = True , show_locals = False, source_code = False ,
|
14
|
-
ignore = None , include = None , show_path = False, duration_bigger_than = 0 ,
|
15
|
-
max_string
|
14
|
+
ignore = None , include = None , show_path = False, duration_bigger_than = 0 ,
|
15
|
+
trace_depth = 0 , max_string = None , show_types = False, show_duration = False , # show_caller = False , # todo: add back when show_caller is working again
|
16
16
|
show_class = False, contains = None , show_internals = False, enabled = True ,
|
17
17
|
extra_data = False, show_lines = False, print_lines = False, show_types_padding = None , duration_padding=None):
|
18
18
|
def decorator(func):
|
osbot_utils/utils/Env.py
CHANGED
@@ -6,10 +6,10 @@ from osbot_utils.utils.Files import all_parent_folders, file_exists
|
|
6
6
|
from osbot_utils.utils.Misc import list_set
|
7
7
|
from osbot_utils.utils.Str import strip_quotes
|
8
8
|
|
9
|
-
def env__home_root():
|
9
|
+
def env__home_root(): # todo: this should be refatored to be env__home__is__root
|
10
10
|
return os.getenv('HOME') == '/root'
|
11
11
|
|
12
|
-
def env__terminal_xterm():
|
12
|
+
def env__terminal_xterm(): # todo: this should be refatored to be env__terminal__is__xterm
|
13
13
|
return os.getenv('TERM') == 'xterm'
|
14
14
|
|
15
15
|
def env__not_terminal_xterm():
|
osbot_utils/version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
v1.
|
1
|
+
v1.30.0
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: osbot_utils
|
3
|
-
Version: 1.
|
3
|
+
Version: 1.30.0
|
4
4
|
Summary: OWASP Security Bot - Utils
|
5
5
|
Home-page: https://github.com/owasp-sbot/OSBot-Utils
|
6
6
|
License: MIT
|
@@ -22,7 +22,7 @@ Description-Content-Type: text/markdown
|
|
22
22
|
|
23
23
|
Powerful Python util methods and classes that simplify common apis and tasks.
|
24
24
|
|
25
|
-

|
26
26
|
[](https://codecov.io/gh/owasp-sbot/OSBot-Utils)
|
27
27
|
|
28
28
|
|
@@ -57,6 +57,7 @@ osbot_utils/graphs/mgraph/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJW
|
|
57
57
|
osbot_utils/helpers/CFormat.py,sha256=1_XvqGwgU6qC97MbzcKF0o7s9mCXpU5Kq9Yf-1ixUwY,6808
|
58
58
|
osbot_utils/helpers/CPrint.py,sha256=ztKPNmT8BGxeyPXSQKRs63PqqbgxKDz_BiZmzFMup9g,1413
|
59
59
|
osbot_utils/helpers/Dict_To_Attr.py,sha256=NdhXl5mJH7-NaBk213amzc5Nfy3tJgW-N_uYIRE4hoc,208
|
60
|
+
osbot_utils/helpers/Hashicorp_Secrets.py,sha256=zjXa_dQvfR9L1uoulWJ8nYYaDvznV6o_QPPS4zmb6mo,4235
|
60
61
|
osbot_utils/helpers/Local_Cache.py,sha256=0JZZX3fFImcwtbBvxAQl-EbBegSNJRhRMYF6ovTH6zY,3141
|
61
62
|
osbot_utils/helpers/Local_Caches.py,sha256=HvuP5CURyVm_fVvJX-S4dml2bhRauzgA3be237yTaeY,1814
|
62
63
|
osbot_utils/helpers/Print_Table.py,sha256=LEXbyqGg_6WSraI4cob4bNNSu18ddqvALp1zGK7bPhs,19126
|
@@ -227,7 +228,7 @@ osbot_utils/helpers/ssh/SSH__Linux__Amazon.py,sha256=ZJFb7LFTvclAuhH5OoOtJ361NoX
|
|
227
228
|
osbot_utils/helpers/ssh/SSH__Python.py,sha256=O2DAwkbXzwkis8lffoqIL2NPSfYcN44Mr8i9Ey2iMKk,2066
|
228
229
|
osbot_utils/helpers/ssh/TestCase__SSH.py,sha256=MD8sq0_kI4f6pEmEO0cLq2mQOhIqbP45ZxFJNG44Jg4,1773
|
229
230
|
osbot_utils/helpers/ssh/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
230
|
-
osbot_utils/helpers/trace/Trace_Call.py,sha256=
|
231
|
+
osbot_utils/helpers/trace/Trace_Call.py,sha256=nKds4xTyrF-6A3XMCxVOR37KDzB3nfCQLykrrEsqp2k,6424
|
231
232
|
osbot_utils/helpers/trace/Trace_Call__Config.py,sha256=6nJplzrY1adz3WcwTIuwEhBCk1P0U0NbyWRzDyIox_Q,3250
|
232
233
|
osbot_utils/helpers/trace/Trace_Call__Graph.py,sha256=HCrXRKQI42DIQxxyFLcaosWiOcUyoITbeV17ICdXcXM,1156
|
233
234
|
osbot_utils/helpers/trace/Trace_Call__Handler.py,sha256=3gEX-DykEFixfBmD0jBdMhnTujxhNbXkjOhqxNTc9ac,11563
|
@@ -264,7 +265,7 @@ osbot_utils/utils/Assert.py,sha256=u9XLgYn91QvNWZGyPi29SjPJSXRHlm9andIn3NJEVog,1
|
|
264
265
|
osbot_utils/utils/Call_Stack.py,sha256=MAq_0vMxnbeLfCe9qQz7GwJYaOuXpt3qtQwN6wiXsU0,6595
|
265
266
|
osbot_utils/utils/Csv.py,sha256=oHLVpjRJqrLMz9lubMCNEoThXWju5rNTprcwHc1zq2c,1012
|
266
267
|
osbot_utils/utils/Dev.py,sha256=HibpQutYy_iG8gGV8g1GztxNN4l29E4Bi7UZaVL6-L8,1203
|
267
|
-
osbot_utils/utils/Env.py,sha256=
|
268
|
+
osbot_utils/utils/Env.py,sha256=Pbel6npitij9zag6SsWdPVH2j1BTZjxnwOR1vLiIyMo,5248
|
268
269
|
osbot_utils/utils/Exceptions.py,sha256=KyOUHkXQ_6jDTq04Xm261dbEZuRidtsM4dgzNwSG8-8,389
|
269
270
|
osbot_utils/utils/Files.py,sha256=bZFvjyC4TAmFH6RSp3Xvj_xBxfybCT2cE7x2qNTQmeE,20834
|
270
271
|
osbot_utils/utils/Functions.py,sha256=0E6alPJ0fJpBiJgFOWooCOi265wSRyxxXAJ5CELBnso,3498
|
@@ -285,8 +286,8 @@ osbot_utils/utils/Toml.py,sha256=dqiegndCJF7V1YT1Tc-b0-Bl6QWyL5q30urmQwMXfMQ,140
|
|
285
286
|
osbot_utils/utils/Version.py,sha256=Ww6ChwTxqp1QAcxOnztkTicShlcx6fbNsWX5xausHrg,422
|
286
287
|
osbot_utils/utils/Zip.py,sha256=t9txUxJzLBEHot6WJwF0iTTUQ1Gf_V2pVwsWzAqw_NU,12163
|
287
288
|
osbot_utils/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
288
|
-
osbot_utils/version,sha256=
|
289
|
-
osbot_utils-1.
|
290
|
-
osbot_utils-1.
|
291
|
-
osbot_utils-1.
|
292
|
-
osbot_utils-1.
|
289
|
+
osbot_utils/version,sha256=rySeFYh2TX0iwzR0MwppiJ1yllnTK1JQxMRPUGe8DS0,8
|
290
|
+
osbot_utils-1.30.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
291
|
+
osbot_utils-1.30.0.dist-info/METADATA,sha256=XspSKWOcbtP6-hGL3r9N7NmMZn7n91lK68mf8vPxetI,1266
|
292
|
+
osbot_utils-1.30.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
293
|
+
osbot_utils-1.30.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|