Skip to content

Commit

Permalink
Merge pull request #10 from crowdsecurity/$main-3fc54ec
Browse files Browse the repository at this point in the history
Update python SDK version: 1.30.1
  • Loading branch information
he2ss authored Sep 23, 2024
2 parents 3fc54ec + 0557a84 commit 495d80c
Show file tree
Hide file tree
Showing 15 changed files with 186 additions and 9 deletions.
4 changes: 4 additions & 0 deletions crowdsec_service_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Server(Enum):
'BlocklistGetResponse',
'BlocklistIncludeFilters',
'BlocklistResponse',
'BlocklistSearchRequest',
'BlocklistShareRequest',
'BlocklistSources',
'BlocklistStats',
Expand Down Expand Up @@ -55,12 +56,15 @@ class Server(Enum):
'OutputFormat',
'Page_BlocklistResponse_',
'Page_IntegrationGetResponse_',
'PaginatedBlocklistResponse',
'Permission',
'PricingTiers',
'Share',
'Stats',
'ValidationError',
'HubItem',
'HubType',
'Index',
'ApiKeyAuth',
'Server',
'Page'
Expand Down
Binary file modified crowdsec_service_api/__pycache__/base_model.cpython-311.pyc
Binary file not shown.
Binary file modified crowdsec_service_api/__pycache__/http_client.cpython-311.pyc
Binary file not shown.
65 changes: 64 additions & 1 deletion crowdsec_service_api/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# generated by datamodel-codegen:
# filename: <stdin>
# timestamp: 2024-09-18T10:03:17+00:00
# timestamp: 2024-09-23T13:03:35+00:00

from __future__ import annotations

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


class HubItem(BaseModelSdk):
pass


class HubType(Enum):
PARSERS = 'parsers'
POSTOVERFLOWS = 'postoverflows'
Expand All @@ -362,6 +366,10 @@ class HubType(Enum):
APPSEC_RULES = 'appsec-rules'


class Index(RootModel[Optional[Dict[str, Dict[str, HubItem]]]]):
root: Optional[Dict[str, Dict[str, HubItem]]] = None


class BlocklistsGetBlocklistsQueryParameters(BaseModelSdk):
page: Annotated[
Optional[int], Field(description='Page number', ge=1, title='Page')
Expand Down Expand Up @@ -648,6 +656,49 @@ class BlocklistContentStats(BaseModelSdk):
updated_at: Annotated[Optional[AwareDatetime], Field(title='Updated At')] = None


class BlocklistSearchRequest(BaseModelSdk):
model_config = ConfigDict(
extra='forbid',
)
page: Annotated[
Optional[int], Field(description='Page number', ge=1, title='Page')
] = 1
page_size: Annotated[
Optional[int], Field(description='Page size', le=1000, title='Page Size')
] = 100
pricing_tiers: Annotated[
Optional[List[PricingTiers]],
Field(description='Pricing tiers', title='Pricing Tiers'),
] = []
query: Annotated[
Optional[str], Field(description='Search query', title='Query')
] = ''
targeted_countries: Annotated[
Optional[List[str]],
Field(description='Targeted countries', title='Targeted Countries'),
] = []
classifications: Annotated[
Optional[List[str]],
Field(description='Classifications', title='Classifications'),
] = []
behaviors: Annotated[
Optional[List[str]], Field(description='Behaviors', title='Behaviors')
] = []
min_ips: Annotated[
Optional[int], Field(description='Minimum number of IPs', ge=0, title='Min Ips')
] = 0
sources: Annotated[
Optional[List[BlocklistSources]], Field(description='Sources', title='Sources')
] = []
is_private: Annotated[
Optional[bool], Field(description='Private blocklist', title='Is Private')
] = None
is_subscribed: Annotated[
Optional[bool],
Field(description='Subscribed blocklist (None: all)', title='Is Subscribed'),
] = None


class BlocklistShareRequest(BaseModelSdk):
model_config = ConfigDict(
extra='forbid',
Expand Down Expand Up @@ -1175,3 +1226,15 @@ class PageBlocklistResponse(BaseModelSdk):
size: Annotated[Optional[Size], Field(title='Size')] = None
pages: Annotated[Optional[Pages], Field(title='Pages')] = None
links: Links


class PaginatedBlocklistResponse(BaseModelSdk):
items: Annotated[
List[BlocklistResponse], Field(description='List of blocklists', title='Items')
]
page: Annotated[int, Field(description='Page number', title='Page')]
total: Annotated[
int, Field(description='Total number of blocklists', title='Total')
]
size: Annotated[int, Field(description='Page size', title='Size')]
pages: Annotated[int, Field(description='Total number of pages', title='Pages')]
Binary file not shown.
21 changes: 21 additions & 0 deletions crowdsec_service_api/services/blocklists.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from httpx import Auth
from ..models import *
from ..base_model import Page, Service
from pydantic import BaseModel
from ..http_client import HttpClient

class Blocklists(Service):
Expand Down Expand Up @@ -51,6 +52,26 @@ def create_blocklist(

return BlocklistCreateResponse(**response.json())

def search_blocklist(
self,
request: BlocklistSearchRequest,
)-> PaginatedBlocklistResponse:
endpoint_url = "/blocklists/search"
loc = locals()
headers = {}
params = {}
path_params = {}

response = self.http_client.post(
url=endpoint_url, path_params=path_params, params=params, headers=headers, json=json.loads(
request.model_dump_json(
exclude_none=True
)
)
)

return PaginatedBlocklistResponse(**response.json())

def get_blocklist(
self,
blocklist_id: str,
Expand Down
5 changes: 3 additions & 2 deletions crowdsec_service_api/services/hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from httpx import Auth
from ..models import *
from ..base_model import Page, Service
from pydantic import BaseModel
from ..http_client import HttpClient

class Hub(Service):
Expand All @@ -11,7 +12,7 @@ def get_index(
branch: str,
tenant: str,
with_content: bool = False,
)-> Response Getindex:
)-> Index:
endpoint_url = "/hub/index/{tenant}/{branch}/.index.json"
loc = locals()
headers = {}
Expand All @@ -30,7 +31,7 @@ def get_index(
url=endpoint_url, path_params=path_params, params=params, headers=headers
)

return Response Getindex(**response.json())
return Index(**response.json())

def get_item_content(
self,
Expand Down
1 change: 1 addition & 0 deletions crowdsec_service_api/services/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from httpx import Auth
from ..models import *
from ..base_model import Page, Service
from pydantic import BaseModel
from ..http_client import HttpClient

class Info(Service):
Expand Down
1 change: 1 addition & 0 deletions crowdsec_service_api/services/integrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from httpx import Auth
from ..models import *
from ..base_model import Page, Service
from pydantic import BaseModel
from ..http_client import HttpClient

class Integrations(Service):
Expand Down
46 changes: 46 additions & 0 deletions doc/Blocklists.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
| ------ | ----------- |
| [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. |
| [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 |
| [search_blocklist](#search_blocklist) | Search blocklists |
| [get_blocklist](#get_blocklist) | Get the details of a blocklist by ID. The content of the blocklist is not returned. |
| [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. |
| [update_blocklist](#update_blocklist) | Update a blocklist's details by ID. It is not possible to update the blocklist content using this operation. |
Expand Down Expand Up @@ -101,6 +102,51 @@ print(response)
```


## **search_blocklist**
### Search blocklists
- Endpoint: `/blocklists/search`
- Method: `POST`

### Parameters:
| Parameter | Type | Description | Required | Default |
| --------- | ---- | ----------- | -------- | ------- |
| request | [BlocklistSearchRequest](./Models.md#blocklistsearchrequest) | Request body | Yes | - |
### Returns:
[PaginatedBlocklistResponse](./Models.md#paginatedblocklistresponse)
### Errors:
| Code | Description |
| ---- | ----------- |
| 422 | Validation Error |
### Usage

```python
from crowdsec_service_api import (
Blocklists,
Server,
ApiKeyAuth,
)
auth = ApiKeyAuth(api_key='your_api_key')
client = Blocklists(base_url=Server.production_server.value, auth=auth)
request = BlocklistSearchRequest(
page=1,
page_size=100,
pricing_tiers=None,
query='query',
targeted_countries=['sample-item'],
classifications=['sample-item'],
behaviors=['sample-item'],
min_ips=1,
sources=None,
is_private=None,
is_subscribed=None,
)
response = client.search_blocklist(
request=request,
)
print(response)
```


## **get_blocklist**
### Get the details of a blocklist by ID. The content of the blocklist is not returned.
- Endpoint: `/blocklists/{blocklist_id}`
Expand Down
4 changes: 2 additions & 2 deletions doc/Hub.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ content is returned. |
| tenant | str | | True | |
| with_content | bool | Include content in the index | False | False |
### Returns:
[Response Getindex](./Models.md#response getindex)
[Index](./Models.md#index)
### Errors:
| Code | Description |
| ---- | ----------- |
Expand Down Expand Up @@ -64,7 +64,7 @@ cache expiration policies. No body content is returned.
| tenant | str | | True | |
| with_content | bool | Include content in the index | False | False |
### Returns:
[Response Headindex](./Models.md#response headindex)
[Index](./Models.md#index)
### Errors:
| Code | Description |
| ---- | ----------- |
Expand Down
34 changes: 33 additions & 1 deletion doc/Models.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,22 @@ id, created_at, updated_at, name, label, description, references, is_private, ta
| organization_id | Optional[str] | Blocklists owner's organization id ||
| subscribers | list[BlocklistSubscriberEntity] | List of subscribers to the blocklist. Only subscribers belonging to your organization are returned ||

# **BlocklistSearchRequest**
## Properties
| Property | Type | Description | Example |
|----------|------|-------------|---------|
| page | int | Page number ||
| page_size | int | Page size ||
| pricing_tiers | list[PricingTiers] | Pricing tiers ||
| query | str | Search query ||
| targeted_countries | list[str] | Targeted countries ||
| classifications | list[str] | Classifications ||
| behaviors | list[str] | Behaviors ||
| min_ips | int | Minimum number of IPs ||
| sources | list[BlocklistSources] | Sources ||
| is_private | Optional[bool] | Private blocklist ||
| is_subscribed | Optional[bool] | Subscribed blocklist (None: all) ||

# **BlocklistShareRequest**
## Required:
organizations
Expand Down Expand Up @@ -455,6 +471,18 @@ items, total, page, size, links
| pages | Optional[int] | None ||
| links | object | None ||

# **PaginatedBlocklistResponse**
## Required:
items, page, total, size, pages
## Properties
| Property | Type | Description | Example |
|----------|------|-------------|---------|
| items | list[BlocklistResponse] | List of blocklists ||
| page | int | Page number ||
| total | int | Total number of blocklists ||
| size | int | Page size ||
| pages | int | Total number of pages ||

# **Permission**
## Enum:
READ, WRITE
Expand Down Expand Up @@ -490,6 +518,10 @@ loc, msg, type
| msg | str | None ||
| type | str | None ||

# **HubItem**

# **HubType**
## Enum:
PARSERS, POSTOVERFLOWS, SCENARIOS, COLLECTIONS, CONTEXTS, APPSEC-CONFIGS, APPSEC-RULES
PARSERS, POSTOVERFLOWS, SCENARIOS, COLLECTIONS, CONTEXTS, APPSEC-CONFIGS, APPSEC-RULES

# **Index**
10 changes: 9 additions & 1 deletion doc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ You can find a Quickstart about this SDK, following this [documentation](https:/

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

[BlocklistSearchRequest](./Models.md#blocklistsearchrequest)

[BlocklistShareRequest](./Models.md#blocklistsharerequest)

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

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

[PaginatedBlocklistResponse](./Models.md#paginatedblocklistresponse)

[Permission](./Models.md#permission)

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

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

[HubType](./Models.md#hubtype)
[HubItem](./Models.md#hubitem)

[HubType](./Models.md#hubtype)

[Index](./Models.md#index)
2 changes: 1 addition & 1 deletion openapi.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "crowdsec_service_api"
version = "1.29.0"
version = "1.30.1"
license = { text = "MIT" }
authors = [
{ name="crowdsec", email="[email protected]" }
Expand Down

0 comments on commit 495d80c

Please sign in to comment.