algosec-appviz 0.0.8__py3-none-any.whl → 0.0.10__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.
- algosec_appviz/main.py +42 -6
- {algosec_appviz-0.0.8.dist-info → algosec_appviz-0.0.10.dist-info}/METADATA +1 -1
- algosec_appviz-0.0.10.dist-info/RECORD +7 -0
- algosec_appviz-0.0.8.dist-info/RECORD +0 -7
- {algosec_appviz-0.0.8.dist-info → algosec_appviz-0.0.10.dist-info}/LICENSE +0 -0
- {algosec_appviz-0.0.8.dist-info → algosec_appviz-0.0.10.dist-info}/WHEEL +0 -0
algosec_appviz/main.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import requests
|
|
2
2
|
from algosec_appviz import environment
|
|
3
|
+
from datetime import datetime, timedelta
|
|
3
4
|
from mydict import MyDict
|
|
4
5
|
|
|
5
6
|
regions = {
|
|
@@ -19,12 +20,19 @@ class AppViz:
|
|
|
19
20
|
raise ValueError(f"Invalid region, must be one of: {', '.join(regions.keys())}")
|
|
20
21
|
|
|
21
22
|
self.proxies = proxies
|
|
23
|
+
self.region = region
|
|
24
|
+
self.tenant_id = tenant_id or environment.get_tenant_id()
|
|
25
|
+
self._client_id = client_id or environment.get_client_id()
|
|
26
|
+
self._client_secret = client_secret or environment.get_client_secret()
|
|
22
27
|
|
|
23
|
-
|
|
28
|
+
self._init_token()
|
|
29
|
+
|
|
30
|
+
def _init_token(self):
|
|
31
|
+
login_url = f"https://{regions[self.region]}/api/algosaas/auth/v1/access-keys/login"
|
|
24
32
|
data = {
|
|
25
|
-
"tenantId": tenant_id
|
|
26
|
-
"clientId":
|
|
27
|
-
"clientSecret":
|
|
33
|
+
"tenantId": self.tenant_id,
|
|
34
|
+
"clientId": self._client_id,
|
|
35
|
+
"clientSecret": self._client_secret
|
|
28
36
|
}
|
|
29
37
|
|
|
30
38
|
headers = {
|
|
@@ -36,9 +44,10 @@ class AppViz:
|
|
|
36
44
|
if response.status_code != 200:
|
|
37
45
|
raise ConnectionError(f"Authentication to AppViz failed: {response.text}")
|
|
38
46
|
|
|
39
|
-
self.url = 'https://' + regions[region]
|
|
47
|
+
self.url = 'https://' + regions[self.region]
|
|
40
48
|
self._token_type = response.json()['token_type']
|
|
41
49
|
self._token = response.json()['access_token']
|
|
50
|
+
self._token_expires = datetime.now() + timedelta(seconds=response.json()['expires_in'])
|
|
42
51
|
|
|
43
52
|
def create_application(self, name=None, **kwargs):
|
|
44
53
|
if not name:
|
|
@@ -82,7 +91,7 @@ class AppViz:
|
|
|
82
91
|
"""
|
|
83
92
|
Deletes a network object in AppViz
|
|
84
93
|
:param obj_id: The object ID
|
|
85
|
-
:return:
|
|
94
|
+
:return: Change details if successful, empty string otherwise
|
|
86
95
|
"""
|
|
87
96
|
if not obj_id:
|
|
88
97
|
raise ValueError("Object ID is mandatory")
|
|
@@ -96,6 +105,29 @@ class AppViz:
|
|
|
96
105
|
|
|
97
106
|
return result
|
|
98
107
|
|
|
108
|
+
def update_network_object(self, obj_id=None, **kwargs):
|
|
109
|
+
"""
|
|
110
|
+
Updates a network object in AppViz
|
|
111
|
+
:return: The new object details, if successful, empty string otherwise
|
|
112
|
+
"""
|
|
113
|
+
if not obj_id:
|
|
114
|
+
raise ValueError("Object ID is mandatory")
|
|
115
|
+
|
|
116
|
+
result = self._make_api_call('POST',
|
|
117
|
+
f'/BusinessFlow/rest/v1/network_objects/{obj_id}',
|
|
118
|
+
body={**kwargs})
|
|
119
|
+
|
|
120
|
+
if isinstance(result, dict) and 'networkObject' in result.keys():
|
|
121
|
+
return result['networkObject']
|
|
122
|
+
|
|
123
|
+
try:
|
|
124
|
+
print(result[1])
|
|
125
|
+
except KeyError:
|
|
126
|
+
if 'success' in result.keys() and not result['success']:
|
|
127
|
+
print(result['message'])
|
|
128
|
+
|
|
129
|
+
return ""
|
|
130
|
+
|
|
99
131
|
def get_applications(self):
|
|
100
132
|
response = self._make_api_call('GET',
|
|
101
133
|
'/BusinessFlow/rest/v1/applications')
|
|
@@ -141,6 +173,10 @@ class AppViz:
|
|
|
141
173
|
return [MyDict(x) for x in response]
|
|
142
174
|
|
|
143
175
|
def _make_api_call(self, method, url_path, body=None, params=None):
|
|
176
|
+
# Check if the token is still valid, otherwise request a new one
|
|
177
|
+
if datetime.now() >= self._token_expires - timedelta(seconds=5):
|
|
178
|
+
self._init_token()
|
|
179
|
+
|
|
144
180
|
valid_methods = ['get', 'post', 'delete']
|
|
145
181
|
headers = {
|
|
146
182
|
'Accept': 'application/json',
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
algosec_appviz/__init__.py,sha256=epwLWpezNwfYP0Zuqk32rWEvNeloAKzbrRFi9tzlsXo,46
|
|
2
|
+
algosec_appviz/environment.py,sha256=ycrVSpR6oLpj9p54SvDdy0nqwS9IwHAh-1x-zOaTQ5I,1775
|
|
3
|
+
algosec_appviz/main.py,sha256=4rUcspAZtjWgzKKN-PznQUmxsp-jGMQY5Fz_TBBerMw,7132
|
|
4
|
+
algosec_appviz-0.0.10.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
|
5
|
+
algosec_appviz-0.0.10.dist-info/METADATA,sha256=fjdGcU5_4MRTMLw2Cru5dh7IRKpzPKruMek8iWAvfgs,1799
|
|
6
|
+
algosec_appviz-0.0.10.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
|
|
7
|
+
algosec_appviz-0.0.10.dist-info/RECORD,,
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
algosec_appviz/__init__.py,sha256=epwLWpezNwfYP0Zuqk32rWEvNeloAKzbrRFi9tzlsXo,46
|
|
2
|
-
algosec_appviz/environment.py,sha256=ycrVSpR6oLpj9p54SvDdy0nqwS9IwHAh-1x-zOaTQ5I,1775
|
|
3
|
-
algosec_appviz/main.py,sha256=NAkuuMtSFgZcnhMnBV-22ebT3_ObocFGsdj-KAas3AI,5783
|
|
4
|
-
algosec_appviz-0.0.8.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
|
5
|
-
algosec_appviz-0.0.8.dist-info/METADATA,sha256=isNuuOwxax_jp7kBJmVDN0w52uExys-4OxP_eAJzf40,1798
|
|
6
|
-
algosec_appviz-0.0.8.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
|
|
7
|
-
algosec_appviz-0.0.8.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|