Skip to content

Commit

Permalink
Add bulk_service
Browse files Browse the repository at this point in the history
  • Loading branch information
dannywillems committed Oct 19, 2023
1 parent fa1e08a commit 0b8f0e9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
8 changes: 8 additions & 0 deletions example/example_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -116,3 +123,4 @@ def example_bulk_export():
example_get_leak_raw_query()
example_get_plugins()
example_bulk_export()
example_bulk_service()
24 changes: 24 additions & 0 deletions leakix/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 0b8f0e9

Please sign in to comment.