Skip to content

Commit 1f9141a

Browse files
authored
Merge pull request #11 from crowdsecurity/$main-495d80c
Update python SDK version: 1.62.0
2 parents 495d80c + 1249122 commit 1f9141a

23 files changed

+2992
-398
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: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,48 @@
11
from enum import Enum
2-
from .base_model import Page
32
from .models import *
3+
from .base_model import Page
4+
from .services.allowlists import Allowlists
45
from .services.blocklists import Blocklists
56
from .services.integrations import Integrations
67
from .services.info import Info
8+
from .services.metrics import Metrics
79
from .services.hub import Hub
810
from .http_client import ApiKeyAuth
911

1012
class Server(Enum):
1113
production_server = 'https://admin.api.crowdsec.net/v1/'
1214

1315
__all__ = [
16+
'Allowlists',
1417
'Blocklists',
1518
'Integrations',
1619
'Info',
20+
'Metrics',
1721
'Hub',
22+
'AllowlistCreateRequest',
23+
'AllowlistCreateResponse',
24+
'AllowlistGetItemsResponse',
25+
'AllowlistGetResponse',
26+
'AllowlistItemUpdateRequest',
27+
'AllowlistItemUpdateResponse',
28+
'AllowlistItemsCreateRequest',
29+
'AllowlistScope',
30+
'AllowlistSubscriberEntity',
31+
'AllowlistSubscribersCount',
32+
'AllowlistSubscriptionRequest',
33+
'AllowlistSubscriptionResponse',
34+
'AllowlistUpdateRequest',
35+
'AllowlistUpdateResponse',
1836
'ApiKeyCredentials',
37+
'AttacksMetrics',
1938
'BasicAuthCredentials',
2039
'BlocklistAddIPsRequest',
40+
'BlocklistCategory',
2141
'BlocklistContentStats',
2242
'BlocklistCreateRequest',
23-
'BlocklistCreateResponse',
2443
'BlocklistDeleteIPsRequest',
25-
'BlocklistGetResponse',
2644
'BlocklistIncludeFilters',
27-
'BlocklistResponse',
45+
'BlocklistOrigin',
2846
'BlocklistSearchRequest',
2947
'BlocklistShareRequest',
3048
'BlocklistSources',
@@ -37,13 +55,16 @@ class Server(Enum):
3755
'BlocklistUpdateRequest',
3856
'BlocklistUsageStats',
3957
'Body_uploadBlocklistContent',
58+
'ComputedMetrics',
59+
'ComputedSavedMetrics',
4060
'CtiAs',
4161
'CtiBehavior',
4262
'CtiCategory',
4363
'CtiCountry',
4464
'CtiIp',
4565
'CtiScenario',
4666
'EntityType',
67+
'GetRemediationMetricsResponse',
4768
'HTTPValidationError',
4869
'InfoResponse',
4970
'IntegrationCreateRequest',
@@ -53,18 +74,36 @@ class Server(Enum):
5374
'IntegrationUpdateRequest',
5475
'IntegrationUpdateResponse',
5576
'Links',
77+
'MetricUnits',
78+
'OriginMetrics',
5679
'OutputFormat',
57-
'Page_BlocklistResponse_',
58-
'Page_IntegrationGetResponse_',
59-
'PaginatedBlocklistResponse',
80+
'PageAllowlistGetItemsResponse',
81+
'PageAllowlistGetResponse',
82+
'PageAllowlistSubscriberEntity',
83+
'PageIntegrationGetResponse',
84+
'PagePublicBlocklistResponse',
6085
'Permission',
6186
'PricingTiers',
87+
'PublicBlocklistResponse',
88+
'PublicPaginatedBlocklistResponse',
89+
'RawMetrics',
90+
'RemediationMetrics',
91+
'RemediationMetricsData',
6292
'Share',
93+
'SourceInfo',
94+
'SourceType',
6395
'Stats',
96+
'SubscriberEntityType',
6497
'ValidationError',
65-
'HubItem',
66-
'HubType',
98+
'AppsecConfigIndex',
99+
'AppsecRuleIndex',
100+
'CollectionIndex',
101+
'ContextIndex',
67102
'Index',
103+
'ParserIndex',
104+
'PostoverflowIndex',
105+
'ScenarioIndex',
106+
'VersionDetail',
68107
'ApiKeyAuth',
69108
'Server',
70109
'Page'
Binary file not shown.
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)