Skip to content

Commit 4bfeb68

Browse files
nitescucgithub-actions[bot]
authored andcommitted
Update python SDK 1.16.4
1 parent 495d80c commit 4bfeb68

File tree

19 files changed

+1070
-431
lines changed

19 files changed

+1070
-431
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2024 Crowdsec
3+
Copyright (c) 2025 Crowdsec
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

crowdsec_service_api/__init__.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from enum import Enum
2-
from .base_model import Page
32
from .models import *
3+
from .base_model import Page
44
from .services.blocklists import Blocklists
55
from .services.integrations import Integrations
66
from .services.info import Info
@@ -18,13 +18,11 @@ class Server(Enum):
1818
'ApiKeyCredentials',
1919
'BasicAuthCredentials',
2020
'BlocklistAddIPsRequest',
21+
'BlocklistCategory',
2122
'BlocklistContentStats',
2223
'BlocklistCreateRequest',
23-
'BlocklistCreateResponse',
2424
'BlocklistDeleteIPsRequest',
25-
'BlocklistGetResponse',
2625
'BlocklistIncludeFilters',
27-
'BlocklistResponse',
2826
'BlocklistSearchRequest',
2927
'BlocklistShareRequest',
3028
'BlocklistSources',
@@ -43,7 +41,6 @@ class Server(Enum):
4341
'CtiCountry',
4442
'CtiIp',
4543
'CtiScenario',
46-
'EntityType',
4744
'HTTPValidationError',
4845
'InfoResponse',
4946
'IntegrationCreateRequest',
@@ -54,17 +51,25 @@ class Server(Enum):
5451
'IntegrationUpdateResponse',
5552
'Links',
5653
'OutputFormat',
57-
'Page_BlocklistResponse_',
58-
'Page_IntegrationGetResponse_',
59-
'PaginatedBlocklistResponse',
54+
'PageIntegrationGetResponse',
55+
'PagePublicBlocklistResponse',
6056
'Permission',
6157
'PricingTiers',
58+
'PublicBlocklistResponse',
59+
'PublicPaginatedBlocklistResponse',
6260
'Share',
6361
'Stats',
62+
'SubscriberEntityType',
6463
'ValidationError',
65-
'HubItem',
66-
'HubType',
64+
'AppsecConfigIndex',
65+
'AppsecRuleIndex',
66+
'CollectionIndex',
67+
'ContextIndex',
6768
'Index',
69+
'ParserIndex',
70+
'PostoverflowIndex',
71+
'ScenarioIndex',
72+
'VersionDetail',
6873
'ApiKeyAuth',
6974
'Server',
7075
'Page'
471 Bytes
Binary file not shown.
12 Bytes
Binary file not shown.

crowdsec_service_api/base_model.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,20 @@ class BaseModelSdk(BaseModel):
1515

1616

1717
class Page(BaseModelSdk, Generic[T]):
18+
_client: "Service"
1819
items: Sequence[T]
1920
total: Optional[int]
2021
page: Optional[int]
2122
size: Optional[int]
2223
pages: Optional[int] = None
2324
links: Optional[dict] = None
2425

25-
def next(self, client: "Service") -> "Page[T]":
26-
return client.next_page(self)
26+
def __init__(self, _client: "Service", **data):
27+
super().__init__(**data)
28+
self._client = _client
29+
30+
def next(self, client: "Service" = None) -> "Page[T]":
31+
return (client if client is not None else self._client).next_page(self)
2732

2833

2934
class Service:
@@ -39,7 +44,7 @@ def next_page(self, page: Page[T]) -> Page[T]:
3944
# links are relative to host not to full base url. We need to pass a full formatted url here
4045
parsed_url = urlparse(self.http_client.base_url)
4146
response = self.http_client.get(
42-
f"{parsed_url.scheme}://{parsed_url.netloc}{page.links['next']}"
47+
f"{parsed_url.scheme}://{parsed_url.netloc}{page.links['next']}", path_params=None, params=None, headers=None
4348
)
44-
return Page[T](**response.json())
49+
return page.__class__(_client=self, **response.json())
4550
return None

crowdsec_service_api/http_client.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,13 @@ def __init__(self, base_url: str, auth: httpx.Auth, aws_region="eu-west-1") -> N
5353
self.timeout = 30
5454

5555
def _replace_path_params(self, url: str, path_params: dict):
56-
for param, value in path_params.items():
57-
if not value:
58-
raise ValueError(
59-
f"Parameter {param} is required, cannot be empty or blank."
60-
)
61-
url = url.replace(f"{{{param}}}", quote(str(value)))
56+
if path_params:
57+
for param, value in path_params.items():
58+
if not value:
59+
raise ValueError(
60+
f"Parameter {param} is required, cannot be empty or blank."
61+
)
62+
url = url.replace(f"{{{param}}}", quote(str(value)))
6263
return url
6364

6465
def _normalize_url(self, url: str):
@@ -70,9 +71,9 @@ def _normalize_url(self, url: str):
7071
def get(
7172
self,
7273
url: str,
73-
path_params: dict = {},
74-
params: dict = {},
75-
headers: dict = {},
74+
path_params: dict = None,
75+
params: dict = None,
76+
headers: dict = None,
7677
):
7778
url = self._replace_path_params(
7879
url=self._normalize_url(url), path_params=path_params

0 commit comments

Comments
 (0)