algosec-appviz 0.0.7__py3-none-any.whl → 0.0.9__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
@@ -78,13 +78,78 @@ 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: Change details if successful, empty string otherwise
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
+
99
+ def update_network_object(self, obj_id=None, **kwargs):
100
+ """
101
+ Updates a network object in AppViz
102
+ :return: The new object details, if successful, empty string otherwise
103
+ """
104
+ if not obj_id:
105
+ raise ValueError("Object ID is mandatory")
106
+
107
+ result = self._make_api_call('POST',
108
+ f'/BusinessFlow/rest/v1/network_objects/{obj_id}',
109
+ body={**kwargs})
110
+
111
+ if isinstance(result, dict) and 'networkObject' in result.keys():
112
+ return result['networkObject']
113
+
114
+ try:
115
+ print(result[1])
116
+ except KeyError:
117
+ if 'success' in result.keys() and not result['success']:
118
+ print(result['message'])
119
+
120
+ return ""
121
+
81
122
  def get_applications(self):
82
123
  response = self._make_api_call('GET',
83
124
  '/BusinessFlow/rest/v1/applications')
84
125
 
85
126
  return [MyDict(x) for x in response]
86
127
 
128
+ def get_all_network_objects(self):
129
+ """
130
+ Gets all the network objects from AppViz. This could take some time, depending on the number of objects.
131
+ :return: The list of objects
132
+ """
133
+ appviz_objects = []
134
+ page = 1
135
+
136
+ while True:
137
+ print(f"Getting AppViz Network Objects, page {page}...")
138
+ objects = self.list_network_objects(page_number=page)
139
+ page = page + 1
140
+ appviz_objects.extend(objects)
141
+ if len(objects) < 1000:
142
+ break
143
+
144
+ return appviz_objects
145
+
87
146
  def list_network_objects(self, page_number=1, page_size=1000):
147
+ """
148
+ Get a list of objects based on the page_size (the number of objects to be retrieved) and the page number
149
+ :param page_number: Page number, defaults to 1
150
+ :param page_size: Page size, defaults to 1000
151
+ :return: The list of objects
152
+ """
88
153
  response = self._make_api_call('GET',
89
154
  '/BusinessFlow/rest/v1/network_objects/',
90
155
  params={'page_number': page_number, 'page_size': page_size})
@@ -99,6 +164,7 @@ class AppViz:
99
164
  return [MyDict(x) for x in response]
100
165
 
101
166
  def _make_api_call(self, method, url_path, body=None, params=None):
167
+ valid_methods = ['get', 'post', 'delete']
102
168
  headers = {
103
169
  'Accept': 'application/json',
104
170
  'Authorization': f'{self._token_type} {self._token}'
@@ -110,8 +176,9 @@ class AppViz:
110
176
  response = requests.get(url, headers=headers, json=body, params=params, proxies=self.proxies)
111
177
  elif method.lower() == 'post':
112
178
  response = requests.post(url, headers=headers, json=body, params=params, proxies=self.proxies)
179
+ elif method.lower() == 'delete':
180
+ response = requests.delete(url, headers=headers, json=body, params=params, proxies=self.proxies)
113
181
  else:
114
- raise ValueError("Invalid method, must be: 'GET' or 'POST'")
182
+ raise ValueError(f"Invalid method, must be: {', '.join(valid_methods)}")
115
183
 
116
- response.raise_for_status()
117
184
  return response.json()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: algosec_appviz
3
- Version: 0.0.7
3
+ Version: 0.0.9
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=4t6EQxiSnqzvClgWr16FzpjgEV8rcbtaxH_cco5hny8,6591
4
+ algosec_appviz-0.0.9.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
5
+ algosec_appviz-0.0.9.dist-info/METADATA,sha256=h1bBuqUvU8_Tnwdehn_dVy4xN521-YMAdgptir-C0bw,1798
6
+ algosec_appviz-0.0.9.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
7
+ algosec_appviz-0.0.9.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=2yYudC6XbIMeBIfC8Sg4TYqEbIx_vH-qXiMNc_cGfHY,4175
4
- algosec_appviz-0.0.7.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
5
- algosec_appviz-0.0.7.dist-info/METADATA,sha256=OVzoNc-MhpHNT8-PAz79OVcOXw4J1uMDA_WeTtVDgYM,1798
6
- algosec_appviz-0.0.7.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
7
- algosec_appviz-0.0.7.dist-info/RECORD,,