diff --git a/example/example_client.py b/example/example_client.py index d2c0628..a9d9038 100644 --- a/example/example_client.py +++ b/example/example_client.py @@ -106,6 +106,13 @@ def example_bulk_export(): print(response.json()) +def example_bulk_service(): + raw_query = '+"window.onload=function(){ url =\'/webui\';window.location.href=url;}" +port:443' + query = RawQuery(raw_query) + response = CLIENT.bulk_service([query]) + print(response.json()) + + if __name__ == "__main__": example_get_host_filter_plugin() example_get_service_filter_plugin() @@ -116,3 +123,4 @@ def example_bulk_export(): example_get_leak_raw_query() example_get_plugins() example_bulk_export() + example_bulk_service() diff --git a/leakix/client.py b/leakix/client.py index e582bf4..e5b7c8e 100644 --- a/leakix/client.py +++ b/leakix/client.py @@ -176,3 +176,27 @@ def bulk_export(self, queries: Optional[List[Query]] = None): else: return ErrorResponse(response=r, response_json=r.json()) return r + + def bulk_service(self, queries: Optional[List[Query]] = None): + url = "%s/bulk/service" % (self.base_url) + if queries is None or len(queries) == 0: + serialized_query = EmptyQuery().serialize() + else: + serialized_query = [q.serialize() for q in queries] + serialized_query = " ".join(serialized_query) + serialized_query = "%s" % serialized_query + params = {"q": serialized_query} + r = requests.get(url, params=params, headers=self.headers, stream=True) + if r.status_code == 200: + response_json = [] + for line in r.iter_lines(): + json_event = json.loads(line) + response_json.append(l9format.L9Event.from_dict(json_event)) + return SuccessResponse(response=r, response_json=response_json) + elif r.status_code == 429: + return RateLimitResponse(response=r) + elif r.status_code == 204: + return ErrorResponse(response=r, response_json=[], status_code=200) + else: + return ErrorResponse(response=r, response_json=r.json()) + return r