algosec-appviz 0.0.2__py3-none-any.whl → 0.0.5__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.
@@ -0,0 +1,3 @@
1
+ from .main import AppViz
2
+
3
+ __all__ = ["AppViz"]
algosec_appviz/main.py CHANGED
@@ -2,15 +2,28 @@ import requests
2
2
  from algosec_appviz import environment
3
3
  from mydict import MyDict
4
4
 
5
+ regions = {
6
+ 'eu': 'eu.app.algosec.com',
7
+ 'us': 'us.app.algosec.com',
8
+ 'anz': 'anz.app.algosec.com',
9
+ 'me': 'me.app.algosec.com',
10
+ 'uae': 'uae.app.algosec.com',
11
+ 'ind': 'ind.app.algosec.com',
12
+ 'sgp': 'sgp.app.algosec.com'
13
+ }
5
14
 
6
- class AlgoSecAppViz:
7
- def __init__(self, tenant_id, client_id, client_secret):
8
- self.url = "https://eu.app.algosec.com/api/algosaas/auth/v1/access-keys/login"
15
+
16
+ class AppViz:
17
+ def __init__(self, region='eu', tenant_id=None, client_id=None, client_secret=None):
18
+ if region not in regions.keys():
19
+ raise ValueError(f"Invalid region, must be one of: {', '.join(regions.keys())}")
20
+
21
+ login_url = f"https://{regions[region]}/api/algosaas/auth/v1/access-keys/login"
9
22
 
10
23
  data = {
11
- "tenantId": environment.get_tenant_id(),
12
- "clientId": environment.get_client_id(),
13
- "clientSecret": environment.get_client_secret()
24
+ "tenantId": tenant_id or environment.get_tenant_id(),
25
+ "clientId": client_id or environment.get_client_id(),
26
+ "clientSecret": client_secret or environment.get_client_secret()
14
27
  }
15
28
 
16
29
  headers = {
@@ -18,41 +31,82 @@ class AlgoSecAppViz:
18
31
  "Accept": "application/json"
19
32
  }
20
33
 
21
- response = requests.post(self.url, json=data, headers=headers)
34
+ response = requests.post(login_url, json=data, headers=headers)
22
35
  if response.status_code != 200:
23
36
  raise ConnectionError(f"Authentication to AppViz failed: {response.text}")
37
+ self.url = 'https://' + regions[region]
24
38
  self._token_type = response.json()['token_type']
25
39
  self._token = response.json()['access_token']
26
40
 
27
- def get_applications(self):
28
- url = 'https://eu.app.algosec.com/BusinessFlow/rest/v1/applications'
29
- headers = {
30
- 'Accept': 'application/json',
31
- 'Authorization': f'{self._token_type} {self._token}'
41
+ def create_application(self, name=None, **kwargs):
42
+ if not name:
43
+ raise ValueError("Name is required")
44
+
45
+ body = {
46
+ 'name': name,
47
+ **kwargs
32
48
  }
33
49
 
34
- response = requests.get(url, headers=headers)
35
- return [MyDict(x) for x in response.json()]
50
+ result = self._make_api_call('POST',
51
+ '/BusinessFlow/rest/v1/applications/new',
52
+ body=body)
36
53
 
37
- def get_network_objects(self):
38
- url = 'https://eu.app.algosec.com/ObjectFlow/rest/v1/network_objects/name/'
39
- headers = {
40
- 'Accept': 'application/json',
41
- 'Authorization': f'{self._token_type} {self._token}'
54
+ return result
55
+
56
+ def create_network_object(self, name=None, obj_type=None, content=None, **kwargs):
57
+ valid_object_types = ['Range', 'Host', 'Group', 'Abstract']
58
+
59
+ if not name:
60
+ raise ValueError("Object name is required")
61
+ if not obj_type:
62
+ raise ValueError("Object type is required")
63
+ if obj_type not in valid_object_types:
64
+ raise ValueError(f"Object type invalid, allowed values: {', '.join(valid_object_types)}")
65
+
66
+ body = {
67
+ 'name': name,
68
+ 'type': obj_type,
69
+ 'content': content,
70
+ **kwargs
42
71
  }
43
72
 
44
- response = requests.get(url, headers=headers)
45
- return [MyDict(x) for x in response.json()]
73
+ result = self._make_api_call('POST',
74
+ '/BusinessFlow/rest/v1/network_objects/new',
75
+ body=body)
76
+
77
+ return result
78
+
79
+ def get_applications(self):
80
+ response = self._make_api_call('GET',
81
+ '/BusinessFlow/rest/v1/applications')
82
+
83
+ return [MyDict(x) for x in response]
46
84
 
47
- def _make_api_call(self, method, url):
85
+ def list_network_objects(self, page_number=1, page_size=1000):
86
+ response = self._make_api_call('GET',
87
+ '/BusinessFlow/rest/v1/network_objects/',
88
+ params={'page_number': page_number, 'page_size': page_size})
89
+
90
+ return [MyDict(x) for x in response]
91
+
92
+ def search_exact_object(self, content):
93
+ response = self._make_api_call('GET',
94
+ '/BusinessFlow/rest/v1/network_objects/find',
95
+ params={'address': content, 'type': 'EXACT'})
96
+
97
+ return [MyDict(x) for x in response]
98
+
99
+ def _make_api_call(self, method, url_path, body=None, params=None):
48
100
  headers = {
49
101
  'Accept': 'application/json',
50
102
  'Authorization': f'{self._token_type} {self._token}'
51
103
  }
52
104
 
53
105
  if method.lower() == 'get':
54
- response = requests.get(url, headers=headers)
106
+ response = requests.get(self.url + url_path, headers=headers, json=body, params=params)
55
107
  elif method.lower() == 'post':
56
- response = requests.get(url, headers=headers)
108
+ response = requests.post(self.url + url_path, headers=headers, json=body, params=params)
57
109
  else:
58
- raise AssertionError("Invalid method, must be: 'GET' or 'POST'")
110
+ raise ValueError("Invalid method, must be: 'GET' or 'POST'")
111
+
112
+ return response.json()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: algosec_appviz
3
- Version: 0.0.2
3
+ Version: 0.0.5
4
4
  Summary: AlgoSec AppViz Library
5
5
  Home-page: https://github.com/bogdan-iot/algosec-appviz
6
6
  License: LICENSE
@@ -22,7 +22,12 @@ Description-Content-Type: text/markdown
22
22
 
23
23
  # AlgoSec AppViz Python Library
24
24
 
25
- Unofficial library to interract with AlgoSec AppViz in Python.
25
+ Unofficial library to interact with AlgoSec AppViz in Python. Official API documentation can be found here:
26
+ https://api-docs.algosec.com/docs/appvizsaas-api-docs/lr8pw057bsh37-welcome-to-the-app-viz-api-reference
27
+
28
+ ## API Endpoint
29
+ **Important Note:** If not specified, the EU region will be used. If your tenant is provisioned in a different
30
+ region, this needs to be provided when creating the class instance.
26
31
 
27
32
  ## Installation
28
33
 
@@ -30,3 +35,22 @@ Unofficial library to interract with AlgoSec AppViz in Python.
30
35
  $ pip install algosec_appviz
31
36
  ```
32
37
 
38
+ ## Environment Variables
39
+
40
+ The following Environment Variables will be automatically read if set:
41
+ TENANT_ID
42
+ CLIENT_ID
43
+ CLIENT_SECRET
44
+
45
+ ## Usage
46
+
47
+ ```python
48
+ from algosec_appviz import AppViz
49
+
50
+ # Use automatically loaded environment variables as mentioned above
51
+ appviz_inst = AppViz()
52
+
53
+ # Provide parameters in code
54
+ appviz_inst = AppViz(region='us', tenant_id='xxx', client_id='xxx', client_secret='xxx')
55
+ ```
56
+
@@ -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=h96IyEVtELXmmGuvxrQojh9L45c0ssDG7UB2WPZX4J0,4028
4
+ algosec_appviz-0.0.5.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
5
+ algosec_appviz-0.0.5.dist-info/METADATA,sha256=aIriv-vJisyeYbnd3K3Qdct_XL_M4GRTyq0ievrAgEo,1798
6
+ algosec_appviz-0.0.5.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
7
+ algosec_appviz-0.0.5.dist-info/RECORD,,
@@ -1,7 +0,0 @@
1
- algosec_appviz/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- algosec_appviz/environment.py,sha256=ycrVSpR6oLpj9p54SvDdy0nqwS9IwHAh-1x-zOaTQ5I,1775
3
- algosec_appviz/main.py,sha256=qUdqAuaDIPFFul2jLvuZgltp5-oAo_oNryiI9fnO4gM,2057
4
- algosec_appviz-0.0.2.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
5
- algosec_appviz-0.0.2.dist-info/METADATA,sha256=MjIKPr0aa89icnaNxsRsXXiXZhpOO2hk4mBO8rCUB5s,1042
6
- algosec_appviz-0.0.2.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
7
- algosec_appviz-0.0.2.dist-info/RECORD,,