algosec-appviz 0.0.9__tar.gz → 0.0.10__tar.gz
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-0.0.9 → algosec_appviz-0.0.10}/PKG-INFO +1 -1
- {algosec_appviz-0.0.9 → algosec_appviz-0.0.10}/pyproject.toml +1 -1
- {algosec_appviz-0.0.9 → algosec_appviz-0.0.10}/src/algosec_appviz/main.py +18 -5
- {algosec_appviz-0.0.9 → algosec_appviz-0.0.10}/LICENSE +0 -0
- {algosec_appviz-0.0.9 → algosec_appviz-0.0.10}/README.md +0 -0
- {algosec_appviz-0.0.9 → algosec_appviz-0.0.10}/src/algosec_appviz/__init__.py +0 -0
- {algosec_appviz-0.0.9 → algosec_appviz-0.0.10}/src/algosec_appviz/environment.py +0 -0
|
@@ -6,7 +6,7 @@ build-backend = "poetry.core.masonry.api"
|
|
|
6
6
|
name = "algosec_appviz"
|
|
7
7
|
repository = "https://github.com/bogdan-iot/algosec-appviz"
|
|
8
8
|
documentation = "https://github.com/bogdan-iot/algosec-appviz/blob/master/README.md"
|
|
9
|
-
version = "0.0.
|
|
9
|
+
version = "0.0.10"
|
|
10
10
|
license = "LICENSE"
|
|
11
11
|
readme = "README.md"
|
|
12
12
|
description = "AlgoSec AppViz Library"
|
|
@@ -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:
|
|
@@ -164,6 +173,10 @@ class AppViz:
|
|
|
164
173
|
return [MyDict(x) for x in response]
|
|
165
174
|
|
|
166
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
|
+
|
|
167
180
|
valid_methods = ['get', 'post', 'delete']
|
|
168
181
|
headers = {
|
|
169
182
|
'Accept': 'application/json',
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|