cribl-control-plane 0.0.13__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of cribl-control-plane might be problematic. Click here for more details.
- cribl_control_plane/__init__.py +17 -0
- cribl_control_plane/_hooks/__init__.py +5 -0
- cribl_control_plane/_hooks/clientcredentials.py +211 -0
- cribl_control_plane/_hooks/registration.py +13 -0
- cribl_control_plane/_hooks/sdkhooks.py +81 -0
- cribl_control_plane/_hooks/types.py +112 -0
- cribl_control_plane/_version.py +15 -0
- cribl_control_plane/auth_sdk.py +184 -0
- cribl_control_plane/basesdk.py +358 -0
- cribl_control_plane/errors/__init__.py +60 -0
- cribl_control_plane/errors/apierror.py +38 -0
- cribl_control_plane/errors/criblcontrolplaneerror.py +26 -0
- cribl_control_plane/errors/error.py +24 -0
- cribl_control_plane/errors/healthstatus_error.py +38 -0
- cribl_control_plane/errors/no_response_error.py +13 -0
- cribl_control_plane/errors/responsevalidationerror.py +25 -0
- cribl_control_plane/health.py +166 -0
- cribl_control_plane/httpclient.py +126 -0
- cribl_control_plane/models/__init__.py +7305 -0
- cribl_control_plane/models/addhectokenrequest.py +34 -0
- cribl_control_plane/models/authtoken.py +13 -0
- cribl_control_plane/models/createinputhectokenbyidop.py +45 -0
- cribl_control_plane/models/createinputop.py +24 -0
- cribl_control_plane/models/createoutputop.py +24 -0
- cribl_control_plane/models/createoutputtestbyidop.py +46 -0
- cribl_control_plane/models/criblevent.py +14 -0
- cribl_control_plane/models/deleteinputbyidop.py +37 -0
- cribl_control_plane/models/deleteoutputbyidop.py +37 -0
- cribl_control_plane/models/deleteoutputpqbyidop.py +36 -0
- cribl_control_plane/models/getinputbyidop.py +37 -0
- cribl_control_plane/models/getoutputbyidop.py +37 -0
- cribl_control_plane/models/getoutputpqbyidop.py +36 -0
- cribl_control_plane/models/getoutputsamplesbyidop.py +37 -0
- cribl_control_plane/models/healthstatus.py +36 -0
- cribl_control_plane/models/input.py +199 -0
- cribl_control_plane/models/inputappscope.py +448 -0
- cribl_control_plane/models/inputazureblob.py +308 -0
- cribl_control_plane/models/inputcollection.py +208 -0
- cribl_control_plane/models/inputconfluentcloud.py +585 -0
- cribl_control_plane/models/inputcribl.py +165 -0
- cribl_control_plane/models/inputcriblhttp.py +341 -0
- cribl_control_plane/models/inputcribllakehttp.py +342 -0
- cribl_control_plane/models/inputcriblmetrics.py +175 -0
- cribl_control_plane/models/inputcribltcp.py +299 -0
- cribl_control_plane/models/inputcrowdstrike.py +410 -0
- cribl_control_plane/models/inputdatadogagent.py +364 -0
- cribl_control_plane/models/inputdatagen.py +180 -0
- cribl_control_plane/models/inputedgeprometheus.py +551 -0
- cribl_control_plane/models/inputelastic.py +494 -0
- cribl_control_plane/models/inputeventhub.py +360 -0
- cribl_control_plane/models/inputexec.py +213 -0
- cribl_control_plane/models/inputfile.py +259 -0
- cribl_control_plane/models/inputfirehose.py +341 -0
- cribl_control_plane/models/inputgooglepubsub.py +247 -0
- cribl_control_plane/models/inputgrafana_union.py +1247 -0
- cribl_control_plane/models/inputhttp.py +403 -0
- cribl_control_plane/models/inputhttpraw.py +407 -0
- cribl_control_plane/models/inputjournalfiles.py +208 -0
- cribl_control_plane/models/inputkafka.py +581 -0
- cribl_control_plane/models/inputkinesis.py +363 -0
- cribl_control_plane/models/inputkubeevents.py +182 -0
- cribl_control_plane/models/inputkubelogs.py +256 -0
- cribl_control_plane/models/inputkubemetrics.py +233 -0
- cribl_control_plane/models/inputloki.py +468 -0
- cribl_control_plane/models/inputmetrics.py +290 -0
- cribl_control_plane/models/inputmodeldriventelemetry.py +274 -0
- cribl_control_plane/models/inputmsk.py +654 -0
- cribl_control_plane/models/inputnetflow.py +224 -0
- cribl_control_plane/models/inputoffice365mgmt.py +384 -0
- cribl_control_plane/models/inputoffice365msgtrace.py +449 -0
- cribl_control_plane/models/inputoffice365service.py +377 -0
- cribl_control_plane/models/inputopentelemetry.py +516 -0
- cribl_control_plane/models/inputprometheus.py +464 -0
- cribl_control_plane/models/inputprometheusrw.py +470 -0
- cribl_control_plane/models/inputrawudp.py +207 -0
- cribl_control_plane/models/inputs3.py +416 -0
- cribl_control_plane/models/inputs3inventory.py +440 -0
- cribl_control_plane/models/inputsecuritylake.py +425 -0
- cribl_control_plane/models/inputsnmp.py +274 -0
- cribl_control_plane/models/inputsplunk.py +387 -0
- cribl_control_plane/models/inputsplunkhec.py +478 -0
- cribl_control_plane/models/inputsplunksearch.py +537 -0
- cribl_control_plane/models/inputsqs.py +320 -0
- cribl_control_plane/models/inputsyslog_union.py +759 -0
- cribl_control_plane/models/inputsystemmetrics.py +533 -0
- cribl_control_plane/models/inputsystemstate.py +417 -0
- cribl_control_plane/models/inputtcp.py +359 -0
- cribl_control_plane/models/inputtcpjson.py +334 -0
- cribl_control_plane/models/inputwef.py +498 -0
- cribl_control_plane/models/inputwindowsmetrics.py +457 -0
- cribl_control_plane/models/inputwineventlogs.py +222 -0
- cribl_control_plane/models/inputwiz.py +334 -0
- cribl_control_plane/models/inputzscalerhec.py +439 -0
- cribl_control_plane/models/listinputop.py +24 -0
- cribl_control_plane/models/listoutputop.py +24 -0
- cribl_control_plane/models/logininfo.py +16 -0
- cribl_control_plane/models/output.py +229 -0
- cribl_control_plane/models/outputazureblob.py +471 -0
- cribl_control_plane/models/outputazuredataexplorer.py +660 -0
- cribl_control_plane/models/outputazureeventhub.py +321 -0
- cribl_control_plane/models/outputazurelogs.py +386 -0
- cribl_control_plane/models/outputclickhouse.py +650 -0
- cribl_control_plane/models/outputcloudwatch.py +273 -0
- cribl_control_plane/models/outputconfluentcloud.py +591 -0
- cribl_control_plane/models/outputcriblhttp.py +494 -0
- cribl_control_plane/models/outputcribllake.py +396 -0
- cribl_control_plane/models/outputcribltcp.py +387 -0
- cribl_control_plane/models/outputcrowdstrikenextgensiem.py +410 -0
- cribl_control_plane/models/outputdatadog.py +472 -0
- cribl_control_plane/models/outputdataset.py +437 -0
- cribl_control_plane/models/outputdefault.py +55 -0
- cribl_control_plane/models/outputdevnull.py +50 -0
- cribl_control_plane/models/outputdiskspool.py +89 -0
- cribl_control_plane/models/outputdls3.py +560 -0
- cribl_control_plane/models/outputdynatracehttp.py +454 -0
- cribl_control_plane/models/outputdynatraceotlp.py +486 -0
- cribl_control_plane/models/outputelastic.py +494 -0
- cribl_control_plane/models/outputelasticcloud.py +407 -0
- cribl_control_plane/models/outputexabeam.py +297 -0
- cribl_control_plane/models/outputfilesystem.py +357 -0
- cribl_control_plane/models/outputgooglechronicle.py +486 -0
- cribl_control_plane/models/outputgooglecloudlogging.py +557 -0
- cribl_control_plane/models/outputgooglecloudstorage.py +499 -0
- cribl_control_plane/models/outputgooglepubsub.py +274 -0
- cribl_control_plane/models/outputgrafanacloud_union.py +1024 -0
- cribl_control_plane/models/outputgraphite.py +225 -0
- cribl_control_plane/models/outputhoneycomb.py +369 -0
- cribl_control_plane/models/outputhumiohec.py +389 -0
- cribl_control_plane/models/outputinfluxdb.py +523 -0
- cribl_control_plane/models/outputkafka.py +581 -0
- cribl_control_plane/models/outputkinesis.py +312 -0
- cribl_control_plane/models/outputloki.py +425 -0
- cribl_control_plane/models/outputminio.py +512 -0
- cribl_control_plane/models/outputmsk.py +654 -0
- cribl_control_plane/models/outputnetflow.py +80 -0
- cribl_control_plane/models/outputnewrelic.py +424 -0
- cribl_control_plane/models/outputnewrelicevents.py +401 -0
- cribl_control_plane/models/outputopentelemetry.py +669 -0
- cribl_control_plane/models/outputprometheus.py +485 -0
- cribl_control_plane/models/outputring.py +121 -0
- cribl_control_plane/models/outputrouter.py +83 -0
- cribl_control_plane/models/outputs3.py +556 -0
- cribl_control_plane/models/outputsamplesresponse.py +14 -0
- cribl_control_plane/models/outputsecuritylake.py +505 -0
- cribl_control_plane/models/outputsentinel.py +488 -0
- cribl_control_plane/models/outputsentineloneaisiem.py +505 -0
- cribl_control_plane/models/outputservicenow.py +543 -0
- cribl_control_plane/models/outputsignalfx.py +369 -0
- cribl_control_plane/models/outputsnmp.py +80 -0
- cribl_control_plane/models/outputsns.py +274 -0
- cribl_control_plane/models/outputsplunk.py +383 -0
- cribl_control_plane/models/outputsplunkhec.py +434 -0
- cribl_control_plane/models/outputsplunklb.py +558 -0
- cribl_control_plane/models/outputsqs.py +328 -0
- cribl_control_plane/models/outputstatsd.py +224 -0
- cribl_control_plane/models/outputstatsdext.py +225 -0
- cribl_control_plane/models/outputsumologic.py +378 -0
- cribl_control_plane/models/outputsyslog.py +415 -0
- cribl_control_plane/models/outputtcpjson.py +413 -0
- cribl_control_plane/models/outputtestrequest.py +15 -0
- cribl_control_plane/models/outputtestresponse.py +29 -0
- cribl_control_plane/models/outputwavefront.py +369 -0
- cribl_control_plane/models/outputwebhook.py +689 -0
- cribl_control_plane/models/outputxsiam.py +415 -0
- cribl_control_plane/models/schemeclientoauth.py +24 -0
- cribl_control_plane/models/security.py +36 -0
- cribl_control_plane/models/updatehectokenrequest.py +31 -0
- cribl_control_plane/models/updateinputbyidop.py +44 -0
- cribl_control_plane/models/updateinputhectokenbyidandtokenop.py +52 -0
- cribl_control_plane/models/updateoutputbyidop.py +44 -0
- cribl_control_plane/outputs.py +1615 -0
- cribl_control_plane/py.typed +1 -0
- cribl_control_plane/sdk.py +164 -0
- cribl_control_plane/sdkconfiguration.py +36 -0
- cribl_control_plane/sources.py +1355 -0
- cribl_control_plane/types/__init__.py +21 -0
- cribl_control_plane/types/basemodel.py +39 -0
- cribl_control_plane/utils/__init__.py +187 -0
- cribl_control_plane/utils/annotations.py +55 -0
- cribl_control_plane/utils/datetimes.py +23 -0
- cribl_control_plane/utils/enums.py +74 -0
- cribl_control_plane/utils/eventstreaming.py +238 -0
- cribl_control_plane/utils/forms.py +223 -0
- cribl_control_plane/utils/headers.py +136 -0
- cribl_control_plane/utils/logger.py +27 -0
- cribl_control_plane/utils/metadata.py +118 -0
- cribl_control_plane/utils/queryparams.py +205 -0
- cribl_control_plane/utils/requestbodies.py +66 -0
- cribl_control_plane/utils/retries.py +217 -0
- cribl_control_plane/utils/security.py +207 -0
- cribl_control_plane/utils/serializers.py +249 -0
- cribl_control_plane/utils/unmarshal_json_response.py +24 -0
- cribl_control_plane/utils/url.py +155 -0
- cribl_control_plane/utils/values.py +137 -0
- cribl_control_plane-0.0.13.dist-info/METADATA +489 -0
- cribl_control_plane-0.0.13.dist-info/RECORD +197 -0
- cribl_control_plane-0.0.13.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
2
|
+
|
|
3
|
+
from ._version import (
|
|
4
|
+
__title__,
|
|
5
|
+
__version__,
|
|
6
|
+
__openapi_doc_version__,
|
|
7
|
+
__gen_version__,
|
|
8
|
+
__user_agent__,
|
|
9
|
+
)
|
|
10
|
+
from .sdk import *
|
|
11
|
+
from .sdkconfiguration import *
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
VERSION: str = __version__
|
|
15
|
+
OPENAPI_DOC_VERSION = __openapi_doc_version__
|
|
16
|
+
SPEAKEASY_GENERATOR_VERSION = __gen_version__
|
|
17
|
+
USER_AGENT = __user_agent__
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import hashlib
|
|
2
|
+
import os
|
|
3
|
+
import httpx
|
|
4
|
+
import time
|
|
5
|
+
from .types import (
|
|
6
|
+
SDKInitHook,
|
|
7
|
+
BeforeRequestContext,
|
|
8
|
+
BeforeRequestHook,
|
|
9
|
+
AfterErrorContext,
|
|
10
|
+
AfterErrorHook,
|
|
11
|
+
HookContext,
|
|
12
|
+
)
|
|
13
|
+
from typing import Any, Dict, List, Tuple, Union, Optional
|
|
14
|
+
from urllib.parse import urlparse, urljoin
|
|
15
|
+
from cribl_control_plane.httpclient import HttpClient
|
|
16
|
+
from cribl_control_plane.sdkconfiguration import SDKConfiguration
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class Credentials:
|
|
20
|
+
client_id: str
|
|
21
|
+
client_secret: str
|
|
22
|
+
token_url: str
|
|
23
|
+
audience: str
|
|
24
|
+
|
|
25
|
+
def __init__(self, client_id: str, client_secret: str, token_url: str):
|
|
26
|
+
self.client_id = client_id
|
|
27
|
+
self.client_secret = client_secret
|
|
28
|
+
self.token_url = token_url
|
|
29
|
+
self.audience = os.getenv("CRIBLCONTROLPLANE_AUDIENCE", "https://api.cribl.cloud") # Set default audience here
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class Session:
|
|
33
|
+
credentials: Credentials
|
|
34
|
+
token: str
|
|
35
|
+
scopes: Optional[List[str]] = None
|
|
36
|
+
expires_at: Optional[int] = None
|
|
37
|
+
|
|
38
|
+
def __init__(
|
|
39
|
+
self,
|
|
40
|
+
credentials: Credentials,
|
|
41
|
+
token: str,
|
|
42
|
+
scopes: Optional[List[str]] = None,
|
|
43
|
+
expires_at: Optional[int] = None,
|
|
44
|
+
):
|
|
45
|
+
self.credentials = credentials
|
|
46
|
+
self.token = token
|
|
47
|
+
self.scopes = scopes
|
|
48
|
+
self.expires_at = expires_at
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
class ClientCredentialsHook(SDKInitHook, BeforeRequestHook, AfterErrorHook):
|
|
52
|
+
client: HttpClient
|
|
53
|
+
sessions: Dict[str, Session] = {}
|
|
54
|
+
|
|
55
|
+
def sdk_init(self, config: SDKConfiguration) -> SDKConfiguration:
|
|
56
|
+
if config.client is None:
|
|
57
|
+
raise Exception("Client is required")
|
|
58
|
+
|
|
59
|
+
self.client = config.client
|
|
60
|
+
return config
|
|
61
|
+
|
|
62
|
+
def before_request(
|
|
63
|
+
self, hook_ctx: BeforeRequestContext, request: httpx.Request
|
|
64
|
+
) -> httpx.Request:
|
|
65
|
+
if hook_ctx.oauth2_scopes is None:
|
|
66
|
+
# OAuth2 not in use
|
|
67
|
+
return request
|
|
68
|
+
|
|
69
|
+
credentials = self.get_credentials(hook_ctx)
|
|
70
|
+
if credentials is None:
|
|
71
|
+
return request
|
|
72
|
+
|
|
73
|
+
session_key = self.get_session_key(
|
|
74
|
+
credentials.client_id, credentials.client_secret
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
if (
|
|
78
|
+
session_key not in self.sessions
|
|
79
|
+
or not self.has_required_scopes(
|
|
80
|
+
self.sessions[session_key].scopes, hook_ctx.oauth2_scopes
|
|
81
|
+
)
|
|
82
|
+
or self.has_token_expired(self.sessions[session_key].expires_at)
|
|
83
|
+
):
|
|
84
|
+
sess = self.do_token_request(
|
|
85
|
+
hook_ctx,
|
|
86
|
+
credentials,
|
|
87
|
+
self.get_scopes(hook_ctx.oauth2_scopes, self.sessions.get(session_key)),
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
self.sessions[session_key] = sess
|
|
91
|
+
|
|
92
|
+
request.headers["Authorization"] = f"Bearer {self.sessions[session_key].token}"
|
|
93
|
+
|
|
94
|
+
return request
|
|
95
|
+
|
|
96
|
+
def after_error(
|
|
97
|
+
self,
|
|
98
|
+
hook_ctx: AfterErrorContext,
|
|
99
|
+
response: Optional[httpx.Response],
|
|
100
|
+
error: Optional[Exception],
|
|
101
|
+
) -> Union[Tuple[Optional[httpx.Response], Optional[Exception]], Exception]:
|
|
102
|
+
if hook_ctx.oauth2_scopes is None:
|
|
103
|
+
# OAuth2 not in use
|
|
104
|
+
return (response, error)
|
|
105
|
+
|
|
106
|
+
# We don't want to refresh the token if the error is not related to the token
|
|
107
|
+
if error is not None:
|
|
108
|
+
return (response, error)
|
|
109
|
+
|
|
110
|
+
credentials = self.get_credentials(hook_ctx)
|
|
111
|
+
if credentials is None:
|
|
112
|
+
return (response, error)
|
|
113
|
+
|
|
114
|
+
if response is not None and response.status_code == 401:
|
|
115
|
+
session_key = self.get_session_key(
|
|
116
|
+
credentials.client_id, credentials.client_secret
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
if session_key in self.sessions:
|
|
120
|
+
del self.sessions[session_key]
|
|
121
|
+
|
|
122
|
+
return (response, error)
|
|
123
|
+
|
|
124
|
+
def get_credentials(self, hook_ctx: HookContext) -> Optional[Credentials]:
|
|
125
|
+
source = hook_ctx.security_source
|
|
126
|
+
|
|
127
|
+
if source is None:
|
|
128
|
+
return None
|
|
129
|
+
|
|
130
|
+
security = source() if callable(source) else source
|
|
131
|
+
|
|
132
|
+
return self.get_credentials_global(security)
|
|
133
|
+
|
|
134
|
+
def get_credentials_global(self, security: Any) -> Optional[Credentials]:
|
|
135
|
+
if security is None or security.client_oauth is None:
|
|
136
|
+
return None
|
|
137
|
+
|
|
138
|
+
return Credentials(
|
|
139
|
+
client_id=security.client_oauth.client_id,
|
|
140
|
+
client_secret=security.client_oauth.client_secret,
|
|
141
|
+
token_url=security.client_oauth.token_url,
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
def do_token_request(
|
|
145
|
+
self,
|
|
146
|
+
hook_ctx: HookContext,
|
|
147
|
+
credentials: Credentials,
|
|
148
|
+
scopes: Optional[List[str]],
|
|
149
|
+
) -> Session:
|
|
150
|
+
payload = {
|
|
151
|
+
"grant_type": "client_credentials",
|
|
152
|
+
"client_id": credentials.client_id,
|
|
153
|
+
"client_secret": credentials.client_secret,
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if credentials.audience is not None:
|
|
157
|
+
payload["audience"] = credentials.audience
|
|
158
|
+
|
|
159
|
+
if scopes is not None and len(scopes) > 0:
|
|
160
|
+
payload["scope"] = " ".join(scopes)
|
|
161
|
+
|
|
162
|
+
token_url = credentials.token_url
|
|
163
|
+
if not bool(urlparse(credentials.token_url).netloc):
|
|
164
|
+
token_url = urljoin(hook_ctx.base_url, credentials.token_url)
|
|
165
|
+
response = self.client.send(
|
|
166
|
+
self.client.build_request(method="POST", url=token_url, data=payload)
|
|
167
|
+
)
|
|
168
|
+
|
|
169
|
+
if response.status_code < 200 or response.status_code >= 300:
|
|
170
|
+
raise Exception(
|
|
171
|
+
f"Unexpected status code {response.status_code} from token endpoint"
|
|
172
|
+
)
|
|
173
|
+
|
|
174
|
+
response_data = response.json()
|
|
175
|
+
|
|
176
|
+
if response_data.get("token_type") != "Bearer":
|
|
177
|
+
raise Exception("Unexpected token type from token endpoint")
|
|
178
|
+
|
|
179
|
+
expires_at = None
|
|
180
|
+
if "expires_in" in response_data:
|
|
181
|
+
expires_at = int(time.time()) + response_data.get("expires_in")
|
|
182
|
+
|
|
183
|
+
return Session(
|
|
184
|
+
credentials=credentials,
|
|
185
|
+
token=response_data.get("access_token"),
|
|
186
|
+
scopes=scopes,
|
|
187
|
+
expires_at=expires_at,
|
|
188
|
+
)
|
|
189
|
+
|
|
190
|
+
def get_session_key(self, client_id: str, client_secret: str) -> str:
|
|
191
|
+
return hashlib.md5(f"{client_id}:{client_secret}".encode()).hexdigest()
|
|
192
|
+
|
|
193
|
+
def has_required_scopes(
|
|
194
|
+
self, scopes: Optional[List[str]], required_scopes: List[str]
|
|
195
|
+
) -> bool:
|
|
196
|
+
if scopes is None:
|
|
197
|
+
return False
|
|
198
|
+
|
|
199
|
+
return all(scope in scopes for scope in required_scopes)
|
|
200
|
+
|
|
201
|
+
def get_scopes(
|
|
202
|
+
self, required_scopes: List[str], sess: Optional[Session]
|
|
203
|
+
) -> List[str]:
|
|
204
|
+
scopes = required_scopes.copy()
|
|
205
|
+
if sess is not None and sess.scopes is not None:
|
|
206
|
+
scopes.extend(sess.scopes)
|
|
207
|
+
scopes = list(set(scopes))
|
|
208
|
+
return scopes
|
|
209
|
+
|
|
210
|
+
def has_token_expired(self, expires_at: Optional[int]) -> bool:
|
|
211
|
+
return expires_at is None or time.time() + 60 >= expires_at
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
from .types import Hooks
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
# This file is only ever generated once on the first generation and then is free to be modified.
|
|
5
|
+
# Any hooks you wish to add should be registered in the init_hooks function. Feel free to define them
|
|
6
|
+
# in this file or in separate files in the hooks folder.
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def init_hooks(hooks: Hooks):
|
|
10
|
+
# pylint: disable=unused-argument
|
|
11
|
+
"""Add hooks by calling hooks.register{sdk_init/before_request/after_success/after_error}Hook
|
|
12
|
+
with an instance of a hook that implements that specific Hook interface
|
|
13
|
+
Hooks are registered per SDK instance, and are valid for the lifetime of the SDK instance"""
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
2
|
+
|
|
3
|
+
import httpx
|
|
4
|
+
from .clientcredentials import ClientCredentialsHook
|
|
5
|
+
from .types import (
|
|
6
|
+
SDKInitHook,
|
|
7
|
+
BeforeRequestContext,
|
|
8
|
+
BeforeRequestHook,
|
|
9
|
+
AfterSuccessContext,
|
|
10
|
+
AfterSuccessHook,
|
|
11
|
+
AfterErrorContext,
|
|
12
|
+
AfterErrorHook,
|
|
13
|
+
Hooks,
|
|
14
|
+
)
|
|
15
|
+
from .registration import init_hooks
|
|
16
|
+
from typing import List, Optional, Tuple
|
|
17
|
+
from cribl_control_plane.sdkconfiguration import SDKConfiguration
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class SDKHooks(Hooks):
|
|
21
|
+
def __init__(self) -> None:
|
|
22
|
+
self.sdk_init_hooks: List[SDKInitHook] = []
|
|
23
|
+
self.before_request_hooks: List[BeforeRequestHook] = []
|
|
24
|
+
self.after_success_hooks: List[AfterSuccessHook] = []
|
|
25
|
+
self.after_error_hooks: List[AfterErrorHook] = []
|
|
26
|
+
client_credentials = ClientCredentialsHook()
|
|
27
|
+
self.sdk_init_hooks.append(client_credentials)
|
|
28
|
+
self.before_request_hooks.append(client_credentials)
|
|
29
|
+
self.after_error_hooks.append(client_credentials)
|
|
30
|
+
init_hooks(self)
|
|
31
|
+
|
|
32
|
+
def register_sdk_init_hook(self, hook: SDKInitHook) -> None:
|
|
33
|
+
self.sdk_init_hooks.append(hook)
|
|
34
|
+
|
|
35
|
+
def register_before_request_hook(self, hook: BeforeRequestHook) -> None:
|
|
36
|
+
self.before_request_hooks.append(hook)
|
|
37
|
+
|
|
38
|
+
def register_after_success_hook(self, hook: AfterSuccessHook) -> None:
|
|
39
|
+
self.after_success_hooks.append(hook)
|
|
40
|
+
|
|
41
|
+
def register_after_error_hook(self, hook: AfterErrorHook) -> None:
|
|
42
|
+
self.after_error_hooks.append(hook)
|
|
43
|
+
|
|
44
|
+
def sdk_init(self, config: SDKConfiguration) -> SDKConfiguration:
|
|
45
|
+
for hook in self.sdk_init_hooks:
|
|
46
|
+
config = hook.sdk_init(config)
|
|
47
|
+
return config
|
|
48
|
+
|
|
49
|
+
def before_request(
|
|
50
|
+
self, hook_ctx: BeforeRequestContext, request: httpx.Request
|
|
51
|
+
) -> httpx.Request:
|
|
52
|
+
for hook in self.before_request_hooks:
|
|
53
|
+
out = hook.before_request(hook_ctx, request)
|
|
54
|
+
if isinstance(out, Exception):
|
|
55
|
+
raise out
|
|
56
|
+
request = out
|
|
57
|
+
|
|
58
|
+
return request
|
|
59
|
+
|
|
60
|
+
def after_success(
|
|
61
|
+
self, hook_ctx: AfterSuccessContext, response: httpx.Response
|
|
62
|
+
) -> httpx.Response:
|
|
63
|
+
for hook in self.after_success_hooks:
|
|
64
|
+
out = hook.after_success(hook_ctx, response)
|
|
65
|
+
if isinstance(out, Exception):
|
|
66
|
+
raise out
|
|
67
|
+
response = out
|
|
68
|
+
return response
|
|
69
|
+
|
|
70
|
+
def after_error(
|
|
71
|
+
self,
|
|
72
|
+
hook_ctx: AfterErrorContext,
|
|
73
|
+
response: Optional[httpx.Response],
|
|
74
|
+
error: Optional[Exception],
|
|
75
|
+
) -> Tuple[Optional[httpx.Response], Optional[Exception]]:
|
|
76
|
+
for hook in self.after_error_hooks:
|
|
77
|
+
result = hook.after_error(hook_ctx, response, error)
|
|
78
|
+
if isinstance(result, Exception):
|
|
79
|
+
raise result
|
|
80
|
+
response, error = result
|
|
81
|
+
return response, error
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
2
|
+
|
|
3
|
+
from abc import ABC, abstractmethod
|
|
4
|
+
from cribl_control_plane.sdkconfiguration import SDKConfiguration
|
|
5
|
+
import httpx
|
|
6
|
+
from typing import Any, Callable, List, Optional, Tuple, Union
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class HookContext:
|
|
10
|
+
config: SDKConfiguration
|
|
11
|
+
base_url: str
|
|
12
|
+
operation_id: str
|
|
13
|
+
oauth2_scopes: Optional[List[str]] = None
|
|
14
|
+
security_source: Optional[Union[Any, Callable[[], Any]]] = None
|
|
15
|
+
|
|
16
|
+
def __init__(
|
|
17
|
+
self,
|
|
18
|
+
config: SDKConfiguration,
|
|
19
|
+
base_url: str,
|
|
20
|
+
operation_id: str,
|
|
21
|
+
oauth2_scopes: Optional[List[str]],
|
|
22
|
+
security_source: Optional[Union[Any, Callable[[], Any]]],
|
|
23
|
+
):
|
|
24
|
+
self.config = config
|
|
25
|
+
self.base_url = base_url
|
|
26
|
+
self.operation_id = operation_id
|
|
27
|
+
self.oauth2_scopes = oauth2_scopes
|
|
28
|
+
self.security_source = security_source
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class BeforeRequestContext(HookContext):
|
|
32
|
+
def __init__(self, hook_ctx: HookContext):
|
|
33
|
+
super().__init__(
|
|
34
|
+
hook_ctx.config,
|
|
35
|
+
hook_ctx.base_url,
|
|
36
|
+
hook_ctx.operation_id,
|
|
37
|
+
hook_ctx.oauth2_scopes,
|
|
38
|
+
hook_ctx.security_source,
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class AfterSuccessContext(HookContext):
|
|
43
|
+
def __init__(self, hook_ctx: HookContext):
|
|
44
|
+
super().__init__(
|
|
45
|
+
hook_ctx.config,
|
|
46
|
+
hook_ctx.base_url,
|
|
47
|
+
hook_ctx.operation_id,
|
|
48
|
+
hook_ctx.oauth2_scopes,
|
|
49
|
+
hook_ctx.security_source,
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
class AfterErrorContext(HookContext):
|
|
54
|
+
def __init__(self, hook_ctx: HookContext):
|
|
55
|
+
super().__init__(
|
|
56
|
+
hook_ctx.config,
|
|
57
|
+
hook_ctx.base_url,
|
|
58
|
+
hook_ctx.operation_id,
|
|
59
|
+
hook_ctx.oauth2_scopes,
|
|
60
|
+
hook_ctx.security_source,
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
class SDKInitHook(ABC):
|
|
65
|
+
@abstractmethod
|
|
66
|
+
def sdk_init(self, config: SDKConfiguration) -> SDKConfiguration:
|
|
67
|
+
pass
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
class BeforeRequestHook(ABC):
|
|
71
|
+
@abstractmethod
|
|
72
|
+
def before_request(
|
|
73
|
+
self, hook_ctx: BeforeRequestContext, request: httpx.Request
|
|
74
|
+
) -> Union[httpx.Request, Exception]:
|
|
75
|
+
pass
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
class AfterSuccessHook(ABC):
|
|
79
|
+
@abstractmethod
|
|
80
|
+
def after_success(
|
|
81
|
+
self, hook_ctx: AfterSuccessContext, response: httpx.Response
|
|
82
|
+
) -> Union[httpx.Response, Exception]:
|
|
83
|
+
pass
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
class AfterErrorHook(ABC):
|
|
87
|
+
@abstractmethod
|
|
88
|
+
def after_error(
|
|
89
|
+
self,
|
|
90
|
+
hook_ctx: AfterErrorContext,
|
|
91
|
+
response: Optional[httpx.Response],
|
|
92
|
+
error: Optional[Exception],
|
|
93
|
+
) -> Union[Tuple[Optional[httpx.Response], Optional[Exception]], Exception]:
|
|
94
|
+
pass
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
class Hooks(ABC):
|
|
98
|
+
@abstractmethod
|
|
99
|
+
def register_sdk_init_hook(self, hook: SDKInitHook):
|
|
100
|
+
pass
|
|
101
|
+
|
|
102
|
+
@abstractmethod
|
|
103
|
+
def register_before_request_hook(self, hook: BeforeRequestHook):
|
|
104
|
+
pass
|
|
105
|
+
|
|
106
|
+
@abstractmethod
|
|
107
|
+
def register_after_success_hook(self, hook: AfterSuccessHook):
|
|
108
|
+
pass
|
|
109
|
+
|
|
110
|
+
@abstractmethod
|
|
111
|
+
def register_after_error_hook(self, hook: AfterErrorHook):
|
|
112
|
+
pass
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
2
|
+
|
|
3
|
+
import importlib.metadata
|
|
4
|
+
|
|
5
|
+
__title__: str = "cribl-control-plane"
|
|
6
|
+
__version__: str = "0.0.13"
|
|
7
|
+
__openapi_doc_version__: str = "4.14.0-alpha.1753295778758-ebd92ad1"
|
|
8
|
+
__gen_version__: str = "2.660.0"
|
|
9
|
+
__user_agent__: str = "speakeasy-sdk/python 0.0.13 2.660.0 4.14.0-alpha.1753295778758-ebd92ad1 cribl-control-plane"
|
|
10
|
+
|
|
11
|
+
try:
|
|
12
|
+
if __package__ is not None:
|
|
13
|
+
__version__ = importlib.metadata.version(__package__)
|
|
14
|
+
except importlib.metadata.PackageNotFoundError:
|
|
15
|
+
pass
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
2
|
+
|
|
3
|
+
from .basesdk import BaseSDK
|
|
4
|
+
from cribl_control_plane import errors, models, utils
|
|
5
|
+
from cribl_control_plane._hooks import HookContext
|
|
6
|
+
from cribl_control_plane.types import OptionalNullable, UNSET
|
|
7
|
+
from cribl_control_plane.utils.unmarshal_json_response import unmarshal_json_response
|
|
8
|
+
from typing import Mapping, Optional
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class AuthSDK(BaseSDK):
|
|
12
|
+
r"""Actions related to authentication. Do not use the /auth endpoints in Cribl.Cloud deployments. Instead, follow the instructions at https://docs.cribl.io/stream/api-tutorials/#criblcloud to authenticate for Cribl.Cloud."""
|
|
13
|
+
|
|
14
|
+
def login(
|
|
15
|
+
self,
|
|
16
|
+
*,
|
|
17
|
+
username: str,
|
|
18
|
+
password: str,
|
|
19
|
+
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
20
|
+
server_url: Optional[str] = None,
|
|
21
|
+
timeout_ms: Optional[int] = None,
|
|
22
|
+
http_headers: Optional[Mapping[str, str]] = None,
|
|
23
|
+
) -> models.AuthToken:
|
|
24
|
+
r"""Log in and obtain Auth token
|
|
25
|
+
|
|
26
|
+
This endpoint is unavailable on Cribl.Cloud. Instead, follow the instructions at https://docs.cribl.io/stream/api-tutorials/#criblcloud to get an Auth token for Cribl.Cloud.
|
|
27
|
+
|
|
28
|
+
:param username:
|
|
29
|
+
:param password:
|
|
30
|
+
:param retries: Override the default retry configuration for this method
|
|
31
|
+
:param server_url: Override the default server URL for this method
|
|
32
|
+
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
|
33
|
+
:param http_headers: Additional headers to set or replace on requests.
|
|
34
|
+
"""
|
|
35
|
+
base_url = None
|
|
36
|
+
url_variables = None
|
|
37
|
+
if timeout_ms is None:
|
|
38
|
+
timeout_ms = self.sdk_configuration.timeout_ms
|
|
39
|
+
|
|
40
|
+
if server_url is not None:
|
|
41
|
+
base_url = server_url
|
|
42
|
+
else:
|
|
43
|
+
base_url = self._get_url(base_url, url_variables)
|
|
44
|
+
|
|
45
|
+
request = models.LoginInfo(
|
|
46
|
+
username=username,
|
|
47
|
+
password=password,
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
req = self._build_request(
|
|
51
|
+
method="POST",
|
|
52
|
+
path="/auth/login",
|
|
53
|
+
base_url=base_url,
|
|
54
|
+
url_variables=url_variables,
|
|
55
|
+
request=request,
|
|
56
|
+
request_body_required=True,
|
|
57
|
+
request_has_path_params=False,
|
|
58
|
+
request_has_query_params=False,
|
|
59
|
+
user_agent_header="user-agent",
|
|
60
|
+
accept_header_value="application/json",
|
|
61
|
+
http_headers=http_headers,
|
|
62
|
+
get_serialized_body=lambda: utils.serialize_request_body(
|
|
63
|
+
request, False, False, "json", models.LoginInfo
|
|
64
|
+
),
|
|
65
|
+
timeout_ms=timeout_ms,
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
if retries == UNSET:
|
|
69
|
+
if self.sdk_configuration.retry_config is not UNSET:
|
|
70
|
+
retries = self.sdk_configuration.retry_config
|
|
71
|
+
|
|
72
|
+
retry_config = None
|
|
73
|
+
if isinstance(retries, utils.RetryConfig):
|
|
74
|
+
retry_config = (retries, ["429", "500", "502", "503", "504"])
|
|
75
|
+
|
|
76
|
+
http_res = self.do_request(
|
|
77
|
+
hook_ctx=HookContext(
|
|
78
|
+
config=self.sdk_configuration,
|
|
79
|
+
base_url=base_url or "",
|
|
80
|
+
operation_id="login",
|
|
81
|
+
oauth2_scopes=[],
|
|
82
|
+
security_source=None,
|
|
83
|
+
),
|
|
84
|
+
request=req,
|
|
85
|
+
error_status_codes=["401", "403", "429", "4XX", "5XX"],
|
|
86
|
+
retry_config=retry_config,
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
if utils.match_response(http_res, "200", "application/json"):
|
|
90
|
+
return unmarshal_json_response(models.AuthToken, http_res)
|
|
91
|
+
if utils.match_response(http_res, ["401", "403", "429", "4XX"], "*"):
|
|
92
|
+
http_res_text = utils.stream_to_text(http_res)
|
|
93
|
+
raise errors.APIError("API error occurred", http_res, http_res_text)
|
|
94
|
+
if utils.match_response(http_res, "5XX", "*"):
|
|
95
|
+
http_res_text = utils.stream_to_text(http_res)
|
|
96
|
+
raise errors.APIError("API error occurred", http_res, http_res_text)
|
|
97
|
+
|
|
98
|
+
raise errors.APIError("Unexpected response received", http_res)
|
|
99
|
+
|
|
100
|
+
async def login_async(
|
|
101
|
+
self,
|
|
102
|
+
*,
|
|
103
|
+
username: str,
|
|
104
|
+
password: str,
|
|
105
|
+
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
106
|
+
server_url: Optional[str] = None,
|
|
107
|
+
timeout_ms: Optional[int] = None,
|
|
108
|
+
http_headers: Optional[Mapping[str, str]] = None,
|
|
109
|
+
) -> models.AuthToken:
|
|
110
|
+
r"""Log in and obtain Auth token
|
|
111
|
+
|
|
112
|
+
This endpoint is unavailable on Cribl.Cloud. Instead, follow the instructions at https://docs.cribl.io/stream/api-tutorials/#criblcloud to get an Auth token for Cribl.Cloud.
|
|
113
|
+
|
|
114
|
+
:param username:
|
|
115
|
+
:param password:
|
|
116
|
+
:param retries: Override the default retry configuration for this method
|
|
117
|
+
:param server_url: Override the default server URL for this method
|
|
118
|
+
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
|
119
|
+
:param http_headers: Additional headers to set or replace on requests.
|
|
120
|
+
"""
|
|
121
|
+
base_url = None
|
|
122
|
+
url_variables = None
|
|
123
|
+
if timeout_ms is None:
|
|
124
|
+
timeout_ms = self.sdk_configuration.timeout_ms
|
|
125
|
+
|
|
126
|
+
if server_url is not None:
|
|
127
|
+
base_url = server_url
|
|
128
|
+
else:
|
|
129
|
+
base_url = self._get_url(base_url, url_variables)
|
|
130
|
+
|
|
131
|
+
request = models.LoginInfo(
|
|
132
|
+
username=username,
|
|
133
|
+
password=password,
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
req = self._build_request_async(
|
|
137
|
+
method="POST",
|
|
138
|
+
path="/auth/login",
|
|
139
|
+
base_url=base_url,
|
|
140
|
+
url_variables=url_variables,
|
|
141
|
+
request=request,
|
|
142
|
+
request_body_required=True,
|
|
143
|
+
request_has_path_params=False,
|
|
144
|
+
request_has_query_params=False,
|
|
145
|
+
user_agent_header="user-agent",
|
|
146
|
+
accept_header_value="application/json",
|
|
147
|
+
http_headers=http_headers,
|
|
148
|
+
get_serialized_body=lambda: utils.serialize_request_body(
|
|
149
|
+
request, False, False, "json", models.LoginInfo
|
|
150
|
+
),
|
|
151
|
+
timeout_ms=timeout_ms,
|
|
152
|
+
)
|
|
153
|
+
|
|
154
|
+
if retries == UNSET:
|
|
155
|
+
if self.sdk_configuration.retry_config is not UNSET:
|
|
156
|
+
retries = self.sdk_configuration.retry_config
|
|
157
|
+
|
|
158
|
+
retry_config = None
|
|
159
|
+
if isinstance(retries, utils.RetryConfig):
|
|
160
|
+
retry_config = (retries, ["429", "500", "502", "503", "504"])
|
|
161
|
+
|
|
162
|
+
http_res = await self.do_request_async(
|
|
163
|
+
hook_ctx=HookContext(
|
|
164
|
+
config=self.sdk_configuration,
|
|
165
|
+
base_url=base_url or "",
|
|
166
|
+
operation_id="login",
|
|
167
|
+
oauth2_scopes=[],
|
|
168
|
+
security_source=None,
|
|
169
|
+
),
|
|
170
|
+
request=req,
|
|
171
|
+
error_status_codes=["401", "403", "429", "4XX", "5XX"],
|
|
172
|
+
retry_config=retry_config,
|
|
173
|
+
)
|
|
174
|
+
|
|
175
|
+
if utils.match_response(http_res, "200", "application/json"):
|
|
176
|
+
return unmarshal_json_response(models.AuthToken, http_res)
|
|
177
|
+
if utils.match_response(http_res, ["401", "403", "429", "4XX"], "*"):
|
|
178
|
+
http_res_text = await utils.stream_to_text_async(http_res)
|
|
179
|
+
raise errors.APIError("API error occurred", http_res, http_res_text)
|
|
180
|
+
if utils.match_response(http_res, "5XX", "*"):
|
|
181
|
+
http_res_text = await utils.stream_to_text_async(http_res)
|
|
182
|
+
raise errors.APIError("API error occurred", http_res, http_res_text)
|
|
183
|
+
|
|
184
|
+
raise errors.APIError("Unexpected response received", http_res)
|