algosec-appviz 0.0.4__tar.gz → 0.0.6__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: algosec_appviz
3
- Version: 0.0.4
3
+ Version: 0.0.6
4
4
  Summary: AlgoSec AppViz Library
5
5
  Home-page: https://github.com/bogdan-iot/algosec-appviz
6
6
  License: LICENSE
@@ -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.4"
9
+ version = "0.0.6"
10
10
  license = "LICENSE"
11
11
  readme = "README.md"
12
12
  description = "AlgoSec AppViz Library"
@@ -14,12 +14,13 @@ regions = {
14
14
 
15
15
 
16
16
  class AppViz:
17
- def __init__(self, region='eu', tenant_id=None, client_id=None, client_secret=None):
17
+ def __init__(self, region='eu', tenant_id=None, client_id=None, client_secret=None, proxies=None):
18
18
  if region not in regions.keys():
19
19
  raise ValueError(f"Invalid region, must be one of: {', '.join(regions.keys())}")
20
20
 
21
- login_url = f"https://{regions[region]}/api/algosaas/auth/v1/access-keys/login"
21
+ self.proxies = proxies
22
22
 
23
+ login_url = f"https://{regions[region]}/api/algosaas/auth/v1/access-keys/login"
23
24
  data = {
24
25
  "tenantId": tenant_id or environment.get_tenant_id(),
25
26
  "clientId": client_id or environment.get_client_id(),
@@ -34,10 +35,26 @@ class AppViz:
34
35
  response = requests.post(login_url, json=data, headers=headers)
35
36
  if response.status_code != 200:
36
37
  raise ConnectionError(f"Authentication to AppViz failed: {response.text}")
38
+
37
39
  self.url = 'https://' + regions[region]
38
40
  self._token_type = response.json()['token_type']
39
41
  self._token = response.json()['access_token']
40
42
 
43
+ def create_application(self, name=None, **kwargs):
44
+ if not name:
45
+ raise ValueError("Name is required")
46
+
47
+ body = {
48
+ 'name': name,
49
+ **kwargs
50
+ }
51
+
52
+ result = self._make_api_call('POST',
53
+ '/BusinessFlow/rest/v1/applications/new',
54
+ body=body)
55
+
56
+ return result
57
+
41
58
  def create_network_object(self, name=None, obj_type=None, content=None, **kwargs):
42
59
  valid_object_types = ['Range', 'Host', 'Group', 'Abstract']
43
60
 
@@ -59,7 +76,7 @@ class AppViz:
59
76
  '/BusinessFlow/rest/v1/network_objects/new',
60
77
  body=body)
61
78
 
62
- print(result)
79
+ return result
63
80
 
64
81
  def get_applications(self):
65
82
  response = self._make_api_call('GET',
@@ -87,11 +104,14 @@ class AppViz:
87
104
  'Authorization': f'{self._token_type} {self._token}'
88
105
  }
89
106
 
107
+ url = self.url + url_path
108
+
90
109
  if method.lower() == 'get':
91
- response = requests.get(self.url + url_path, headers=headers, json=body, params=params)
110
+ response = requests.get(url, headers=headers, json=body, params=params, proxies=self.proxies)
92
111
  elif method.lower() == 'post':
93
- response = requests.post(self.url + url_path, headers=headers, json=body, params=params)
112
+ response = requests.post(url, headers=headers, json=body, params=params, proxies=self.proxies)
94
113
  else:
95
- raise AssertionError("Invalid method, must be: 'GET' or 'POST'")
114
+ raise ValueError("Invalid method, must be: 'GET' or 'POST'")
96
115
 
116
+ response.raise_for_status()
97
117
  return response.json()
File without changes
File without changes