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

15 files changed

+186
-9
lines changed

crowdsec_service_api/__init__.py

+4
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'
Binary file not shown.
Binary file not shown.

crowdsec_service_api/models.py

+64-1
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')]
Binary file not shown.

crowdsec_service_api/services/blocklists.py

+21
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

+3-2
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

+1
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

+1
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

+46
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}`

doc/Hub.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ content is returned. |
2626
| tenant | str | | True | |
2727
| with_content | bool | Include content in the index | False | False |
2828
### Returns:
29-
[Response Getindex](./Models.md#response getindex)
29+
[Index](./Models.md#index)
3030
### Errors:
3131
| Code | Description |
3232
| ---- | ----------- |
@@ -64,7 +64,7 @@ cache expiration policies. No body content is returned.
6464
| tenant | str | | True | |
6565
| with_content | bool | Include content in the index | False | False |
6666
### Returns:
67-
[Response Headindex](./Models.md#response headindex)
67+
[Index](./Models.md#index)
6868
### Errors:
6969
| Code | Description |
7070
| ---- | ----------- |

doc/Models.md

+33-1
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,22 @@ id, created_at, updated_at, name, label, description, references, is_private, ta
142142
| organization_id | Optional[str] | Blocklists owner's organization id ||
143143
| subscribers | list[BlocklistSubscriberEntity] | List of subscribers to the blocklist. Only subscribers belonging to your organization are returned ||
144144

145+
# **BlocklistSearchRequest**
146+
## Properties
147+
| Property | Type | Description | Example |
148+
|----------|------|-------------|---------|
149+
| page | int | Page number ||
150+
| page_size | int | Page size ||
151+
| pricing_tiers | list[PricingTiers] | Pricing tiers ||
152+
| query | str | Search query ||
153+
| targeted_countries | list[str] | Targeted countries ||
154+
| classifications | list[str] | Classifications ||
155+
| behaviors | list[str] | Behaviors ||
156+
| min_ips | int | Minimum number of IPs ||
157+
| sources | list[BlocklistSources] | Sources ||
158+
| is_private | Optional[bool] | Private blocklist ||
159+
| is_subscribed | Optional[bool] | Subscribed blocklist (None: all) ||
160+
145161
# **BlocklistShareRequest**
146162
## Required:
147163
organizations
@@ -455,6 +471,18 @@ items, total, page, size, links
455471
| pages | Optional[int] | None ||
456472
| links | object | None ||
457473

474+
# **PaginatedBlocklistResponse**
475+
## Required:
476+
items, page, total, size, pages
477+
## Properties
478+
| Property | Type | Description | Example |
479+
|----------|------|-------------|---------|
480+
| items | list[BlocklistResponse] | List of blocklists ||
481+
| page | int | Page number ||
482+
| total | int | Total number of blocklists ||
483+
| size | int | Page size ||
484+
| pages | int | Total number of pages ||
485+
458486
# **Permission**
459487
## Enum:
460488
READ, WRITE
@@ -490,6 +518,10 @@ loc, msg, type
490518
| msg | str | None ||
491519
| type | str | None ||
492520

521+
# **HubItem**
522+
493523
# **HubType**
494524
## Enum:
495-
PARSERS, POSTOVERFLOWS, SCENARIOS, COLLECTIONS, CONTEXTS, APPSEC-CONFIGS, APPSEC-RULES
525+
PARSERS, POSTOVERFLOWS, SCENARIOS, COLLECTIONS, CONTEXTS, APPSEC-CONFIGS, APPSEC-RULES
526+
527+
# **Index**

doc/README.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ You can find a Quickstart about this SDK, following this [documentation](https:/
4141

4242
[BlocklistResponse](./Models.md#blocklistresponse)
4343

44+
[BlocklistSearchRequest](./Models.md#blocklistsearchrequest)
45+
4446
[BlocklistShareRequest](./Models.md#blocklistsharerequest)
4547

4648
[BlocklistSources](./Models.md#blocklistsources)
@@ -101,6 +103,8 @@ You can find a Quickstart about this SDK, following this [documentation](https:/
101103

102104
[Page_IntegrationGetResponse_](./Models.md#page_integrationgetresponse_)
103105

106+
[PaginatedBlocklistResponse](./Models.md#paginatedblocklistresponse)
107+
104108
[Permission](./Models.md#permission)
105109

106110
[PricingTiers](./Models.md#pricingtiers)
@@ -111,4 +115,8 @@ You can find a Quickstart about this SDK, following this [documentation](https:/
111115

112116
[ValidationError](./Models.md#validationerror)
113117

114-
[HubType](./Models.md#hubtype)
118+
[HubItem](./Models.md#hubitem)
119+
120+
[HubType](./Models.md#hubtype)
121+
122+
[Index](./Models.md#index)

openapi.json

+1-1
Large diffs are not rendered by default.

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "crowdsec_service_api"
7-
version = "1.29.0"
7+
version = "1.30.1"
88
license = { text = "MIT" }
99
authors = [
1010
{ name="crowdsec", email="[email protected]" }

0 commit comments

Comments
 (0)