algosec-appviz 0.0.6__py3-none-any.whl → 0.0.8__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 CHANGED
@@ -32,7 +32,7 @@ class AppViz:
32
32
  "Accept": "application/json"
33
33
  }
34
34
 
35
- response = requests.post(login_url, json=data, headers=headers)
35
+ response = requests.post(login_url, json=data, headers=headers, proxies=self.proxies)
36
36
  if response.status_code != 200:
37
37
  raise ConnectionError(f"Authentication to AppViz failed: {response.text}")
38
38
 
@@ -78,13 +78,55 @@ class AppViz:
78
78
 
79
79
  return result
80
80
 
81
+ def delete_network_object(self, obj_id=None):
82
+ """
83
+ Deletes a network object in AppViz
84
+ :param obj_id: The object ID
85
+ :return: True if successful, false if not
86
+ """
87
+ if not obj_id:
88
+ raise ValueError("Object ID is mandatory")
89
+
90
+ result = self._make_api_call('DELETE',
91
+ f'/BusinessFlow/rest/v1/network_objects/{obj_id}')
92
+
93
+ if result['httpStatusCode'] != 200:
94
+ print(f"Error deleting object: {result['message']}")
95
+ return ""
96
+
97
+ return result
98
+
81
99
  def get_applications(self):
82
100
  response = self._make_api_call('GET',
83
101
  '/BusinessFlow/rest/v1/applications')
84
102
 
85
103
  return [MyDict(x) for x in response]
86
104
 
105
+ def get_all_network_objects(self):
106
+ """
107
+ Gets all the network objects from AppViz. This could take some time, depending on the number of objects.
108
+ :return: The list of objects
109
+ """
110
+ appviz_objects = []
111
+ page = 1
112
+
113
+ while True:
114
+ print(f"Getting AppViz Network Objects, page {page}...")
115
+ objects = self.list_network_objects(page_number=page)
116
+ page = page + 1
117
+ appviz_objects.extend(objects)
118
+ if len(objects) < 1000:
119
+ break
120
+
121
+ return appviz_objects
122
+
87
123
  def list_network_objects(self, page_number=1, page_size=1000):
124
+ """
125
+ Get a list of objects based on the page_size (the number of objects to be retrieved) and the page number
126
+ :param page_number: Page number, defaults to 1
127
+ :param page_size: Page size, defaults to 1000
128
+ :return: The list of objects
129
+ """
88
130
  response = self._make_api_call('GET',
89
131
  '/BusinessFlow/rest/v1/network_objects/',
90
132
  params={'page_number': page_number, 'page_size': page_size})
@@ -99,6 +141,7 @@ class AppViz:
99
141
  return [MyDict(x) for x in response]
100
142
 
101
143
  def _make_api_call(self, method, url_path, body=None, params=None):
144
+ valid_methods = ['get', 'post', 'delete']
102
145
  headers = {
103
146
  'Accept': 'application/json',
104
147
  'Authorization': f'{self._token_type} {self._token}'
@@ -110,8 +153,9 @@ class AppViz:
110
153
  response = requests.get(url, headers=headers, json=body, params=params, proxies=self.proxies)
111
154
  elif method.lower() == 'post':
112
155
  response = requests.post(url, headers=headers, json=body, params=params, proxies=self.proxies)
156
+ elif method.lower() == 'delete':
157
+ response = requests.delete(url, headers=headers, json=body, params=params, proxies=self.proxies)
113
158
  else:
114
- raise ValueError("Invalid method, must be: 'GET' or 'POST'")
159
+ raise ValueError(f"Invalid method, must be: {', '.join(valid_methods)}")
115
160
 
116
- response.raise_for_status()
117
161
  return response.json()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: algosec_appviz
3
- Version: 0.0.6
3
+ Version: 0.0.8
4
4
  Summary: AlgoSec AppViz Library
5
5
  Home-page: https://github.com/bogdan-iot/algosec-appviz
6
6
  License: LICENSE
@@ -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=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,,
@@ -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=2WCC6PaCaeUF6HTRjE_EoFCj7k1R0AngXsbCOmGww4c,4153
4
- algosec_appviz-0.0.6.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
5
- algosec_appviz-0.0.6.dist-info/METADATA,sha256=yq6_qrQYtflqYsvWv5nG-iLswU5VGf6Ym3xnZNRMKDw,1798
6
- algosec_appviz-0.0.6.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
7
- algosec_appviz-0.0.6.dist-info/RECORD,,