Skip to content

Commit 9399004

Browse files
committed
Improve documentation
1 parent 83f152b commit 9399004

4 files changed

Lines changed: 102 additions & 0 deletions

File tree

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,31 @@ Official LeakIX python client
1111
pip install leakix
1212
```
1313

14+
To run tests, use `poetry run pytest`.
15+
16+
## Documentation
17+
18+
Docstrings are used to document the library.
19+
Types are also used to inform the user on what type of objects the functions are
20+
expecting.
21+
22+
The output are events described in
23+
[l9format](https://github.com/LeakIX/l9format-python).
24+
When you have an object of type `l9Event` (or the longer
25+
`l9format.l9format.L9Event`), you can refer to
26+
[L9Event](https://github.com/LeakIX/l9format-python/blob/main/l9format/l9format.py#L158)
27+
model class for the available fields.
28+
29+
For instance, to access the IP of an object `event` of type `L9Event`, you can
30+
use `event.ip`.
31+
32+
## Support
33+
34+
Feel free to open an issue if you have any question.
35+
You can also contact us on `support@leakix.net`.
36+
37+
If you need commercial support, have a look at https://leakix.net/pricing.
38+
1439
## Examples
1540

1641
```python

leakix/client.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from leakix.response import SuccessResponse, ErrorResponse, RateLimitResponse
99
from leakix.query import *
1010
from leakix.plugin import *
11+
from leakix.plugin import APIResult
1112
from leakix.field import *
1213

1314

@@ -58,6 +59,22 @@ def __get(self, url, params):
5859
return ErrorResponse(response=r, response_json=r.json())
5960

6061
def get(self, scope: Scope, queries: Optional[List[Query]] = None, page: int = 0):
62+
"""
63+
The function takes a scope (either "leaks" or "services"). The value can be constructed using `Scope.SERVICE` or
64+
`Scope.LEAK`.
65+
The second parameter is a list of queries. The default value will be considered as the wildcard `*`, which is
66+
also the default value on the web interface.
67+
Structured queries can be built using the different classes in `query.py` and `field.py`.
68+
If you want to build "raw" queries, like on the search bar on the website, use the class `RawQuery`.
69+
70+
The output will be an abstract response, which can be a successfull HTTP response (represented by the class
71+
`SuccessResponse`) or a failed HTTP response (represented by the class `ErrorResponse`).
72+
Methods `is_success` and `is_error` are provided to the user to verify in their application what the state of
73+
the response is.
74+
75+
The output of a query can be accessed using the method `json`, for instance `response.json()`.
76+
In the case of a successfull response, the output will be a list of L9Event.
77+
"""
6178
if page < 0:
6279
raise ValueError("Page argument must be a positive integer")
6380
if queries is None or len(queries) == 0:
@@ -73,6 +90,10 @@ def get(self, scope: Scope, queries: Optional[List[Query]] = None, page: int = 0
7390
return r
7491

7592
def get_service(self, queries: Optional[List[Query]] = None, page: int = 0):
93+
"""
94+
Shortcut for `get` with the scope `Scope.Service`.
95+
96+
"""
7697
r = self.get(Scope.SERVICE, queries=queries, page=page)
7798
if r.is_success():
7899
r.response_json = [
@@ -81,6 +102,9 @@ def get_service(self, queries: Optional[List[Query]] = None, page: int = 0):
81102
return r
82103

83104
def get_leak(self, queries: Optional[List[Query]] = None, page: int = 0):
105+
"""
106+
Shortcut for `get` with the scope `Scope.Leak`.
107+
"""
84108
r = self.get(Scope.LEAK, queries=queries, page=page)
85109
if r.is_success():
86110
r.response_json = [
@@ -89,6 +113,10 @@ def get_leak(self, queries: Optional[List[Query]] = None, page: int = 0):
89113
return r
90114

91115
def get_host(self, ipv4: str):
116+
"""
117+
Returns the list of services and associated leaks for a given host. Only the ipv4 format is supported at the
118+
moment.
119+
"""
92120
url = "%s/host/%s" % (self.base_url, ipv4)
93121
r = self.__get(url, params=None)
94122
if r.is_success():
@@ -102,6 +130,15 @@ def get_host(self, ipv4: str):
102130
return r
103131

104132
def get_plugins(self):
133+
"""
134+
Returns the list of plugins the authenticated user with the given API key has access to.
135+
136+
The output is a list of `APIResult` objects. The fields are `name` which is the plugin name, and `description`
137+
which contains a brief description of the plugin.
138+
Paid users have access to a broader list of plugins. The full list you can be found on
139+
https://leakix.net/plugins.
140+
For the paid plans, have a look at https://leakix.net/pricing.
141+
"""
105142
url = "%s/api/plugins" % (self.base_url)
106143
r = self.__get(url, params=None)
107144
if r.is_success():

leakix/plugin.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ class APIResult(Model):
88

99

1010
class Plugin(Enum):
11+
"""
12+
The list of plugins can be found on https://leakix.net/plugins. Some plugins are only available to paid users. Have
13+
a look at https://leakix.net/pricing for a detailled list.
14+
"""
15+
1116
ApacheStatusHttpPlugin = "ApacheStatusHttpPlugin"
1217
BitbucketPlugin = "BitbucketPlugin"
1318
CheckMkPlugin = "CheckMkPlugin"

leakix/query.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,72 @@
44

55

66
class AbstractQuery(metaclass=ABCMeta):
7+
"""
8+
An abstract query. Should not be instantiated.
9+
"""
10+
711
@abstractmethod
812
def serialize(self) -> str:
913
pass
1014

1115

1216
class EmptyQuery(AbstractQuery):
17+
"""
18+
Represents an empty query, which will be translated to a wildcard. Using an empty query means applying no filter on
19+
the results and the outputs of the query will be the latest results the engine found.
20+
"""
21+
1322
def serialize(self) -> str:
1423
return "*"
1524

1625

1726
class Query(AbstractQuery):
27+
"""
28+
A query for a custom field. Fields can be found on https://docs.leakix.net/docs/query/fields/
29+
A list of fields can be found in `field.py`.
30+
"""
31+
1832
def __init__(self, field: CustomField):
1933
self.field = field
2034

2135

2236
class MustQuery(Query):
37+
"""
38+
A MustQuery is a query that will impose a condition on the field, and will be translated to a `+query` in the API
39+
A list of fields can be found in `field.py`.
40+
"""
41+
2342
def serialize(self) -> str:
2443
return "+%s" % self.field.serialize()
2544

2645

2746
class MustNotQuery(Query):
47+
"""
48+
A MustNotQuery is a query that will exclude a condition on the field, and will be translated to a `-query` in the API
49+
A list of fields can be found in `field.py`.
50+
"""
51+
2852
def serialize(self) -> str:
2953
return "-%s" % self.field.serialize()
3054

3155

3256
class ShouldQuery(Query):
57+
"""
58+
A ShouldQuery is a query that will make the condition optional on the field, and will be translated to `query` in
59+
the API.
60+
A list of fields can be found in `field.py`.
61+
"""
62+
3363
def serialize(self) -> str:
3464
return "%s" % self.field.serialize()
3565

3666

3767
class RawQuery(AbstractQuery):
68+
"""
69+
A RawQuery is a query that can be used as on the website. For instance, to filter on the hosts `.be`, you can use
70+
RawQuery("+host:.be").
71+
"""
72+
3873
def __init__(self, raw_q: str):
3974
self.raw_q = raw_q
4075

0 commit comments

Comments
 (0)