Skip to content

Commit 0b8f0e9

Browse files
committed
Add bulk_service
1 parent fa1e08a commit 0b8f0e9

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

example/example_client.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,13 @@ def example_bulk_export():
106106
print(response.json())
107107

108108

109+
def example_bulk_service():
110+
raw_query = '+"window.onload=function(){ url =\'/webui\';window.location.href=url;}" +port:443'
111+
query = RawQuery(raw_query)
112+
response = CLIENT.bulk_service([query])
113+
print(response.json())
114+
115+
109116
if __name__ == "__main__":
110117
example_get_host_filter_plugin()
111118
example_get_service_filter_plugin()
@@ -116,3 +123,4 @@ def example_bulk_export():
116123
example_get_leak_raw_query()
117124
example_get_plugins()
118125
example_bulk_export()
126+
example_bulk_service()

leakix/client.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,27 @@ def bulk_export(self, queries: Optional[List[Query]] = None):
176176
else:
177177
return ErrorResponse(response=r, response_json=r.json())
178178
return r
179+
180+
def bulk_service(self, queries: Optional[List[Query]] = None):
181+
url = "%s/bulk/service" % (self.base_url)
182+
if queries is None or len(queries) == 0:
183+
serialized_query = EmptyQuery().serialize()
184+
else:
185+
serialized_query = [q.serialize() for q in queries]
186+
serialized_query = " ".join(serialized_query)
187+
serialized_query = "%s" % serialized_query
188+
params = {"q": serialized_query}
189+
r = requests.get(url, params=params, headers=self.headers, stream=True)
190+
if r.status_code == 200:
191+
response_json = []
192+
for line in r.iter_lines():
193+
json_event = json.loads(line)
194+
response_json.append(l9format.L9Event.from_dict(json_event))
195+
return SuccessResponse(response=r, response_json=response_json)
196+
elif r.status_code == 429:
197+
return RateLimitResponse(response=r)
198+
elif r.status_code == 204:
199+
return ErrorResponse(response=r, response_json=[], status_code=200)
200+
else:
201+
return ErrorResponse(response=r, response_json=r.json())
202+
return r

0 commit comments

Comments
 (0)