Skip to content

Commit 495d80c

Browse files
authored
Merge pull request #10 from crowdsecurity/$main-3fc54ec
Update python SDK version: 1.30.1
2 parents 3fc54ec + 0557a84 commit 495d80c

File tree

15 files changed

+186
-9
lines changed

15 files changed

+186
-9
lines changed

crowdsec_service_api/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class Server(Enum):
2525
'BlocklistGetResponse',
2626
'BlocklistIncludeFilters',
2727
'BlocklistResponse',
28+
'BlocklistSearchRequest',
2829
'BlocklistShareRequest',
2930
'BlocklistSources',
3031
'BlocklistStats',
@@ -55,12 +56,15 @@ class Server(Enum):
5556
'OutputFormat',
5657
'Page_BlocklistResponse_',
5758
'Page_IntegrationGetResponse_',
59+
'PaginatedBlocklistResponse',
5860
'Permission',
5961
'PricingTiers',
6062
'Share',
6163
'Stats',
6264
'ValidationError',
65+
'HubItem',
6366
'HubType',
67+
'Index',
6468
'ApiKeyAuth',
6569
'Server',
6670
'Page'
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

crowdsec_service_api/models.py

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# generated by datamodel-codegen:
22
# filename: <stdin>
3-
# timestamp: 2024-09-18T10:03:17+00:00
3+
# timestamp: 2024-09-23T13:03:35+00:00
44

55
from __future__ import annotations
66

@@ -352,6 +352,10 @@ class ValidationError(BaseModelSdk):
352352
type: Annotated[str, Field(title='Error Type')]
353353

354354

355+
class HubItem(BaseModelSdk):
356+
pass
357+
358+
355359
class HubType(Enum):
356360
PARSERS = 'parsers'
357361
POSTOVERFLOWS = 'postoverflows'
@@ -362,6 +366,10 @@ class HubType(Enum):
362366
APPSEC_RULES = 'appsec-rules'
363367

364368

369+
class Index(RootModel[Optional[Dict[str, Dict[str, HubItem]]]]):
370+
root: Optional[Dict[str, Dict[str, HubItem]]] = None
371+
372+
365373
class BlocklistsGetBlocklistsQueryParameters(BaseModelSdk):
366374
page: Annotated[
367375
Optional[int], Field(description='Page number', ge=1, title='Page')
@@ -648,6 +656,49 @@ class BlocklistContentStats(BaseModelSdk):
648656
updated_at: Annotated[Optional[AwareDatetime], Field(title='Updated At')] = None
649657

650658

659+
class BlocklistSearchRequest(BaseModelSdk):
660+
model_config = ConfigDict(
661+
extra='forbid',
662+
)
663+
page: Annotated[
664+
Optional[int], Field(description='Page number', ge=1, title='Page')
665+
] = 1
666+
page_size: Annotated[
667+
Optional[int], Field(description='Page size', le=1000, title='Page Size')
668+
] = 100
669+
pricing_tiers: Annotated[
670+
Optional[List[PricingTiers]],
671+
Field(description='Pricing tiers', title='Pricing Tiers'),
672+
] = []
673+
query: Annotated[
674+
Optional[str], Field(description='Search query', title='Query')
675+
] = ''
676+
targeted_countries: Annotated[
677+
Optional[List[str]],
678+
Field(description='Targeted countries', title='Targeted Countries'),
679+
] = []
680+
classifications: Annotated[
681+
Optional[List[str]],
682+
Field(description='Classifications', title='Classifications'),
683+
] = []
684+
behaviors: Annotated[
685+
Optional[List[str]], Field(description='Behaviors', title='Behaviors')
686+
] = []
687+
min_ips: Annotated[
688+
Optional[int], Field(description='Minimum number of IPs', ge=0, title='Min Ips')
689+
] = 0
690+
sources: Annotated[
691+
Optional[List[BlocklistSources]], Field(description='Sources', title='Sources')
692+
] = []
693+
is_private: Annotated[
694+
Optional[bool], Field(description='Private blocklist', title='Is Private')
695+
] = None
696+
is_subscribed: Annotated[
697+
Optional[bool],
698+
Field(description='Subscribed blocklist (None: all)', title='Is Subscribed'),
699+
] = None
700+
701+
651702
class BlocklistShareRequest(BaseModelSdk):
652703
model_config = ConfigDict(
653704
extra='forbid',
@@ -1175,3 +1226,15 @@ class PageBlocklistResponse(BaseModelSdk):
11751226
size: Annotated[Optional[Size], Field(title='Size')] = None
11761227
pages: Annotated[Optional[Pages], Field(title='Pages')] = None
11771228
links: Links
1229+
1230+
1231+
class PaginatedBlocklistResponse(BaseModelSdk):
1232+
items: Annotated[
1233+
List[BlocklistResponse], Field(description='List of blocklists', title='Items')
1234+
]
1235+
page: Annotated[int, Field(description='Page number', title='Page')]
1236+
total: Annotated[
1237+
int, Field(description='Total number of blocklists', title='Total')
1238+
]
1239+
size: Annotated[int, Field(description='Page size', title='Size')]
1240+
pages: Annotated[int, Field(description='Total number of pages', title='Pages')]
0 Bytes
Binary file not shown.

crowdsec_service_api/services/blocklists.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from httpx import Auth
33
from ..models import *
44
from ..base_model import Page, Service
5+
from pydantic import BaseModel
56
from ..http_client import HttpClient
67

78
class Blocklists(Service):
@@ -51,6 +52,26 @@ def create_blocklist(
5152

5253
return BlocklistCreateResponse(**response.json())
5354

55+
def search_blocklist(
56+
self,
57+
request: BlocklistSearchRequest,
58+
)-> PaginatedBlocklistResponse:
59+
endpoint_url = "/blocklists/search"
60+
loc = locals()
61+
headers = {}
62+
params = {}
63+
path_params = {}
64+
65+
response = self.http_client.post(
66+
url=endpoint_url, path_params=path_params, params=params, headers=headers, json=json.loads(
67+
request.model_dump_json(
68+
exclude_none=True
69+
)
70+
)
71+
)
72+
73+
return PaginatedBlocklistResponse(**response.json())
74+
5475
def get_blocklist(
5576
self,
5677
blocklist_id: str,

crowdsec_service_api/services/hub.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from httpx import Auth
33
from ..models import *
44
from ..base_model import Page, Service
5+
from pydantic import BaseModel
56
from ..http_client import HttpClient
67

78
class Hub(Service):
@@ -11,7 +12,7 @@ def get_index(
1112
branch: str,
1213
tenant: str,
1314
with_content: bool = False,
14-
)-> Response Getindex:
15+
)-> Index:
1516
endpoint_url = "/hub/index/{tenant}/{branch}/.index.json"
1617
loc = locals()
1718
headers = {}
@@ -30,7 +31,7 @@ def get_index(
3031
url=endpoint_url, path_params=path_params, params=params, headers=headers
3132
)
3233

33-
return Response Getindex(**response.json())
34+
return Index(**response.json())
3435

3536
def get_item_content(
3637
self,

crowdsec_service_api/services/info.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from httpx import Auth
33
from ..models import *
44
from ..base_model import Page, Service
5+
from pydantic import BaseModel
56
from ..http_client import HttpClient
67

78
class Info(Service):

crowdsec_service_api/services/integrations.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from httpx import Auth
33
from ..models import *
44
from ..base_model import Page, Service
5+
from pydantic import BaseModel
56
from ..http_client import HttpClient
67

78
class Integrations(Service):

doc/Blocklists.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
| ------ | ----------- |
66
| [get_blocklists](#get_blocklists) | Get multiple blocklists. Only blocklists owned by your organization, shared with your organization or public blocklists are returned. Filters and pagination are available as query parameters. |
77
| [create_blocklist](#create_blocklist) | Create a new blocklist owned by your organization. The name must be unique within your organization. The list will only be visible to your organization and organizations you shared the blocklist with. This operation is submitted to quotas |
8+
| [search_blocklist](#search_blocklist) | Search blocklists |
89
| [get_blocklist](#get_blocklist) | Get the details of a blocklist by ID. The content of the blocklist is not returned. |
910
| [delete_blocklist](#delete_blocklist) | Delete a blocklist by ID. If the blocklist is shared with other organizations or it has subscriptions, the operation will fail. If you want to force delete the blocklist, you can use the force query parameter, so the blocklists will be unshared / unsubscribed. |
1011
| [update_blocklist](#update_blocklist) | Update a blocklist's details by ID. It is not possible to update the blocklist content using this operation. |
@@ -101,6 +102,51 @@ print(response)
101102
```
102103

103104

105+
## **search_blocklist**
106+
### Search blocklists
107+
- Endpoint: `/blocklists/search`
108+
- Method: `POST`
109+
110+
### Parameters:
111+
| Parameter | Type | Description | Required | Default |
112+
| --------- | ---- | ----------- | -------- | ------- |
113+
| request | [BlocklistSearchRequest](./Models.md#blocklistsearchrequest) | Request body | Yes | - |
114+
### Returns:
115+
[PaginatedBlocklistResponse](./Models.md#paginatedblocklistresponse)
116+
### Errors:
117+
| Code | Description |
118+
| ---- | ----------- |
119+
| 422 | Validation Error |
120+
### Usage
121+
122+
```python
123+
from crowdsec_service_api import (
124+
Blocklists,
125+
Server,
126+
ApiKeyAuth,
127+
)
128+
auth = ApiKeyAuth(api_key='your_api_key')
129+
client = Blocklists(base_url=Server.production_server.value, auth=auth)
130+
request = BlocklistSearchRequest(
131+
page=1,
132+
page_size=100,
133+
pricing_tiers=None,
134+
query='query',
135+
targeted_countries=['sample-item'],
136+
classifications=['sample-item'],
137+
behaviors=['sample-item'],
138+
min_ips=1,
139+
sources=None,
140+
is_private=None,
141+
is_subscribed=None,
142+
)
143+
response = client.search_blocklist(
144+
request=request,
145+
)
146+
print(response)
147+
```
148+
149+
104150
## **get_blocklist**
105151
### Get the details of a blocklist by ID. The content of the blocklist is not returned.
106152
- Endpoint: `/blocklists/{blocklist_id}`

0 commit comments

Comments
 (0)