Skip to content

Commit f021ee3

Browse files
he2ssgithub-actions[bot]
authored andcommitted
Update python SDK 1.91.0
1 parent cdaecb2 commit f021ee3

24 files changed

+609
-1064
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# crowdsec_service_api
22

3-
**crowdsec_service_api** is a Python SDK for the [CrowdSec Service API](https://docs.crowdsec.net/u/service_api/intro/).
3+
**crowdsec_service_api** is a Python SDK for the [CrowdSec Service API](https://docs.crowdsec.net/u/console/service_api/getting_started).
44
This library enables you to manage CrowdSec resources such as blocklists, integrations in your python applications.
55

66
## Installation
@@ -11,10 +11,11 @@ pip install crowdsec_service_api
1111

1212
## Usage
1313

14-
You can follow this [documentation](https://docs.crowdsec.net/u/service_api/quickstart/blocklists) to see the basic usage of the SDK.
14+
You can follow this [documentation](https://docs.crowdsec.net/u/console/service_api/sdks/python) to see the basic usage of the SDK.
1515

1616
## Documentation
17-
You can access the full usage documentation [here](https://github.com/crowdsecurity/crowdsec-service-api-sdk-python/tree/main/doc).
17+
You can access [the quickstart guide here](https://docs.crowdsec.net/u/console/service_api/quickstart/authentication).
18+
Or you have the full usage documentation [here](https://github.com/crowdsecurity/crowdsec-service-api-sdk-python/tree/main/doc).
1819

1920
## Contributing
2021

crowdsec_service_api/__init__.py

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@
77
from .services.info import Info
88
from .services.metrics import Metrics
99
from .services.hub import Hub
10-
from .services.cves import Cves
1110
from .http_client import ApiKeyAuth
1211

1312
class Server(Enum):
14-
production_server = 'https://admin.api.crowdsec.net/v1/'
13+
production_server = 'https://admin.api.crowdsec.net/v1'
1514

1615
__all__ = [
1716
'Allowlists',
@@ -20,7 +19,6 @@ class Server(Enum):
2019
'Info',
2120
'Metrics',
2221
'Hub',
23-
'Cves',
2422
'AllowlistCreateRequest',
2523
'AllowlistCreateResponse',
2624
'AllowlistGetItemsResponse',
@@ -61,6 +59,7 @@ class Server(Enum):
6159
'BlocklistUpdateRequest',
6260
'BlocklistUsageStats',
6361
'Body_uploadBlocklistContent',
62+
'CVESubscription',
6463
'ComputedMetrics',
6564
'ComputedSavedMetrics',
6665
'CtiAs',
@@ -106,21 +105,6 @@ class Server(Enum):
106105
'PostoverflowIndex',
107106
'ScenarioIndex',
108107
'VersionDetail',
109-
'AffectedComponent',
110-
'AttackDetail',
111-
'Behavior',
112-
'Classification',
113-
'Classifications',
114-
'GetCVEIPsResponsePage',
115-
'GetCVEResponse',
116-
'History',
117-
'IPItem',
118-
'Location',
119-
'MitreTechnique',
120-
'Reference',
121-
'ScoreBreakdown',
122-
'Scores',
123-
'SubscribeCVEIntegrationRequest',
124108
'ApiKeyAuth',
125109
'Server',
126110
'Page'
687 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

crowdsec_service_api/base_model.py

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from urllib.parse import urlparse
2-
from pydantic import BaseModel, ConfigDict
3-
from typing import Generic, Sequence, Optional, TypeVar
2+
from pydantic import BaseModel, ConfigDict, PrivateAttr, RootModel
3+
from typing import Generic, Sequence, Optional, TypeVar, Any
44
from httpx import Auth
55
from .http_client import HttpClient
66

@@ -9,42 +9,50 @@ class BaseModelSdk(BaseModel):
99
model_config = ConfigDict(
1010
extra="ignore",
1111
)
12+
_client: Optional["Service"] = PrivateAttr(default=None)
13+
14+
def __init__(self, /, _client: "Service" = None, **data):
15+
super().__init__(**data)
16+
self._client = _client
17+
18+
def next(self, client: "Service" = None) -> Optional["BaseModelSdk"]:
19+
return (client if client is not None else self._client).next_page(self)
20+
21+
22+
class RootModelSdk(RootModel):
23+
def __getattr__(self, item: str) -> Any:
24+
return getattr(self.root, item)
1225

1326

1427
T = TypeVar("T")
1528

1629

1730
class Page(BaseModelSdk, Generic[T]):
18-
_client: "Service"
1931
items: Sequence[T]
2032
total: Optional[int]
2133
page: Optional[int]
2234
size: Optional[int]
2335
pages: Optional[int] = None
2436
links: Optional[dict] = None
2537

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)
32-
3338

3439
class Service:
3540
def __init__(self, base_url: str, auth: Auth) -> None:
3641
self.http_client = HttpClient(base_url=base_url, auth=auth)
3742

38-
def next_page(self, page: Page[T]) -> Page[T]:
39-
if not page.links:
43+
def next_page(self, page: BaseModelSdk) -> Optional[BaseModelSdk]:
44+
if not hasattr(page, "links") or not page.links:
4045
raise ValueError(
4146
"No links found in the response, this is not a paginated response."
4247
)
43-
if page.links.get("next"):
48+
if page.links.next:
4449
# links are relative to host not to full base url. We need to pass a full formatted url here
4550
parsed_url = urlparse(self.http_client.base_url)
4651
response = self.http_client.get(
47-
f"{parsed_url.scheme}://{parsed_url.netloc}{page.links['next']}", path_params=None, params=None, headers=None
52+
f"{parsed_url.scheme}://{parsed_url.netloc}{page.links.next}",
53+
path_params=None,
54+
params=None,
55+
headers=None,
4856
)
4957
return page.__class__(_client=self, **response.json())
5058
return None

0 commit comments

Comments
 (0)