Skip to content

Commit 01b280f

Browse files
committed
README: replace inline examples with links to example directory
1 parent 6fe23c6 commit 01b280f

1 file changed

Lines changed: 4 additions & 113 deletions

File tree

README.md

Lines changed: 4 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -53,116 +53,7 @@ If you need commercial support, have a look at https://leakix.net/plans.
5353

5454
## Examples
5555

56-
```python
57-
import decouple
58-
from leakix import Client
59-
from leakix.query import MustQuery, MustNotQuery, RawQuery
60-
from leakix.field import PluginField, CountryField, TimeField, Operator
61-
from leakix.plugin import Plugin
62-
from datetime import datetime, timedelta
63-
64-
65-
API_KEY = decouple.config("API_KEY")
66-
BASE_URL = decouple.config("LEAKIX_HOST", default=None)
67-
CLIENT = Client(api_key=API_KEY)
68-
69-
70-
def example_get_host_filter_plugin():
71-
response = CLIENT.get_host(ipv4="33.33.33.33")
72-
assert response.status_code() == 200
73-
74-
75-
def example_get_service_filter_plugin():
76-
"""
77-
Filter by fields. In this example, we want to have the NTLM services.
78-
A list of plugins can be found in leakix.plugin
79-
"""
80-
query_http_ntlm = MustQuery(field=PluginField(Plugin.HttpNTLM))
81-
response = CLIENT.get_service(queries=[query_http_ntlm])
82-
assert response.status_code() == 200
83-
# check we only get NTML related services
84-
assert all((i.tags == ["ntlm"] for i in response.json()))
85-
86-
87-
def example_get_service_filter_plugin_with_pagination():
88-
"""
89-
Filter by fields. In this example, we want to have the NTLM services.
90-
A list of plugins can be found in leakix.plugin.
91-
Ask for page 1 (starts at 0)
92-
"""
93-
query_http_ntlm = MustQuery(field=PluginField(Plugin.HttpNTLM))
94-
response = CLIENT.get_service(queries=[query_http_ntlm], page=1)
95-
assert response.status_code() == 200
96-
# check we only get NTML related services
97-
assert all((i.tags == ["ntlm"] for i in response.json()))
98-
99-
100-
def example_get_leaks_filter_multiple_plugins():
101-
query_http_ntlm = MustQuery(field=PluginField(Plugin.HttpNTLM))
102-
query_country = MustQuery(field=CountryField("France"))
103-
response = CLIENT.get_leak(queries=[query_http_ntlm, query_country])
104-
assert response.status_code() == 200
105-
assert all(
106-
(
107-
i.geoip.country_name == "France" and i.tags == ["ntlm"]
108-
for i in response.json()
109-
)
110-
)
111-
112-
113-
def example_get_leaks_multiple_filter_plugins_must_not():
114-
query_http_ntlm = MustQuery(field=PluginField(Plugin.HttpNTLM))
115-
query_country = MustNotQuery(field=CountryField("France"))
116-
response = CLIENT.get_leak(queries=[query_http_ntlm, query_country])
117-
assert response.status_code() == 200
118-
assert all(
119-
(
120-
i.geoip.country_name != "France" and i.tags == ["ntlm"]
121-
for i in response.json()
122-
)
123-
)
124-
125-
126-
def example_get_leak_raw_query():
127-
raw_query = '+plugin:HttpNTLM +country:"France"'
128-
query = RawQuery(raw_query)
129-
response = CLIENT.get_leak(queries=[query])
130-
assert response.status_code() == 200
131-
assert all(
132-
(
133-
i.geoip.country_name == "France" and i.tags == ["ntlm"]
134-
for i in response.json()
135-
)
136-
)
137-
138-
139-
def example_get_leak_plugins_with_time():
140-
query_plugin = MustQuery(field=PluginField(Plugin.GitConfigHttpPlugin))
141-
today = datetime.now()
142-
one_month_ago = today - timedelta(days=30)
143-
query_today = MustQuery(field=TimeField(today, Operator.StrictlySmaller))
144-
query_yesterday = MustQuery(
145-
field=TimeField(one_month_ago, Operator.StrictlyGreater)
146-
)
147-
queries = [query_today, query_yesterday, query_plugin]
148-
response = CLIENT.get_leak(queries=queries)
149-
assert response.status_code() == 200
150-
151-
152-
def example_get_plugins():
153-
response = CLIENT.get_plugins()
154-
for p in response.json():
155-
print(p.name)
156-
print(p.description)
157-
158-
159-
if __name__ == "__main__":
160-
example_get_host_filter_plugin()
161-
example_get_service_filter_plugin()
162-
example_get_service_filter_plugin_with_pagination()
163-
example_get_leaks_filter_multiple_plugins()
164-
example_get_leaks_multiple_filter_plugins_must_not()
165-
example_get_leak_plugins_with_time()
166-
example_get_leak_raw_query()
167-
example_get_plugins()
168-
```
56+
See the [example/](example/) directory for complete usage examples:
57+
58+
- [Sync client](example/example_client.py)
59+
- [Async client](example/example_async_client.py)

0 commit comments

Comments
 (0)