Skip to content

Commit 7df1dac

Browse files
authored
README: redirect examples to example directory (#76)
* README: replace inline examples with links to example directory * CHANGELOG: redirect README examples to example directory
1 parent 6fe23c6 commit 7df1dac

2 files changed

Lines changed: 8 additions & 113 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ and this project adheres to
2626
- Updated l9format requirement from =2.0.0 to =2.0.1 ([5764b2f], [#74])
2727
- Use explicit include lists instead of exclude lists for hatch build targets
2828
(sdist and wheel) in `pyproject.toml` ([aa9cc03], [#75])
29+
- README: replace inline examples with links to `example/` directory
30+
([01b280f], [#76])
2931

3032
### Fixed
3133

@@ -84,6 +86,7 @@ and this project adheres to
8486
[0.1.9]: https://github.com/LeakIX/LeakIXClient-Python/releases/tag/v0.1.9
8587

8688
<!-- Commit links -->
89+
[01b280f]: https://github.com/LeakIX/LeakIXClient-Python/commit/01b280f
8790
[aa9cc03]: https://github.com/LeakIX/LeakIXClient-Python/commit/aa9cc03
8891
[5764b2f]: https://github.com/LeakIX/LeakIXClient-Python/commit/5764b2f
8992
[cfa8b6c]: https://github.com/LeakIX/LeakIXClient-Python/commit/cfa8b6c
@@ -111,3 +114,4 @@ and this project adheres to
111114
[#72]: https://github.com/LeakIX/LeakIXClient-Python/pull/72
112115
[#74]: https://github.com/LeakIX/LeakIXClient-Python/pull/74
113116
[#75]: https://github.com/LeakIX/LeakIXClient-Python/pull/75
117+
[#76]: https://github.com/LeakIX/LeakIXClient-Python/pull/76

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)