method-security-sdk 0.35.0__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.
- method_sdk/__init__.py +0 -0
- method_sdk/configuration.py +654 -0
- method_sdk/errors.py +55 -0
- method_sdk/exceptions.py +220 -0
- method_sdk/inventory/__init__.py +94 -0
- method_sdk/inventory/api/__init__.py +5 -0
- method_sdk/inventory/api/inventory_api.py +1508 -0
- method_sdk/inventory/api_client.py +833 -0
- method_sdk/inventory/api_response.py +21 -0
- method_sdk/inventory/configuration.py +654 -0
- method_sdk/inventory/exceptions.py +1 -0
- method_sdk/inventory/models/__init__.py +39 -0
- method_sdk/inventory/models/access_denied_response_content.py +90 -0
- method_sdk/inventory/models/create_environment400_error_response_content.py +151 -0
- method_sdk/inventory/models/create_environment_request_content.py +88 -0
- method_sdk/inventory/models/create_environment_response_content.py +92 -0
- method_sdk/inventory/models/delete_environment400_error_response_content.py +151 -0
- method_sdk/inventory/models/delete_environment_response_content.py +92 -0
- method_sdk/inventory/models/environment.py +101 -0
- method_sdk/inventory/models/environment_not_found_response_content.py +90 -0
- method_sdk/inventory/models/environment_state.py +38 -0
- method_sdk/inventory/models/get_environment400_error_response_content.py +151 -0
- method_sdk/inventory/models/get_environment_response_content.py +92 -0
- method_sdk/inventory/models/internal_server_response_content.py +90 -0
- method_sdk/inventory/models/invalid_parameter.py +90 -0
- method_sdk/inventory/models/list_environments400_error_response_content.py +151 -0
- method_sdk/inventory/models/list_environments_response_content.py +97 -0
- method_sdk/inventory/models/malformed_request.py +90 -0
- method_sdk/inventory/models/missing_parameter.py +90 -0
- method_sdk/inventory/models/service_unavailable_response_content.py +90 -0
- method_sdk/inventory/models/throttling_response_content.py +90 -0
- method_sdk/inventory/models/unauthenticated_response_content.py +90 -0
- method_sdk/inventory/models/update_environment400_error_response_content.py +151 -0
- method_sdk/inventory/models/update_environment_request_content.py +88 -0
- method_sdk/inventory/models/update_environment_response_content.py +92 -0
- method_sdk/inventory/paginators.py +12 -0
- method_sdk/inventory/py.typed +0 -0
- method_sdk/inventory/rest.py +334 -0
- method_sdk/method_auth.py +116 -0
- method_sdk/method_error.py +36 -0
- method_sdk/pagination.py +20 -0
- method_sdk/py.typed +0 -0
- method_security_sdk-0.35.0.dist-info/METADATA +23 -0
- method_security_sdk-0.35.0.dist-info/RECORD +46 -0
- method_security_sdk-0.35.0.dist-info/WHEEL +5 -0
- method_security_sdk-0.35.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
|
|
3
|
+
"""
|
|
4
|
+
InventoryService
|
|
5
|
+
|
|
6
|
+
Attack surface, assets, and environments
|
|
7
|
+
|
|
8
|
+
The version of the OpenAPI document: 3
|
|
9
|
+
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
|
10
|
+
|
|
11
|
+
Do not edit the class manually.
|
|
12
|
+
""" # noqa: E501
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
import ipaddress
|
|
16
|
+
import io
|
|
17
|
+
import json
|
|
18
|
+
import re
|
|
19
|
+
import ssl
|
|
20
|
+
from urllib.parse import urlparse
|
|
21
|
+
|
|
22
|
+
import urllib3
|
|
23
|
+
|
|
24
|
+
from method_sdk.inventory.exceptions import ApiException, ApiValueError
|
|
25
|
+
|
|
26
|
+
SUPPORTED_SOCKS_PROXIES = {"socks5", "socks5h", "socks4", "socks4a"}
|
|
27
|
+
RESTResponseType = urllib3.HTTPResponse
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def is_socks_proxy_url(url):
|
|
31
|
+
if url is None:
|
|
32
|
+
return False
|
|
33
|
+
split_section = url.split("://")
|
|
34
|
+
if len(split_section) < 2:
|
|
35
|
+
return False
|
|
36
|
+
else:
|
|
37
|
+
return split_section[0].lower() in SUPPORTED_SOCKS_PROXIES
|
|
38
|
+
|
|
39
|
+
def contenttype_matches(contenttype, maintype, subtype):
|
|
40
|
+
"""Matches the given contenttype against the given type and subtype
|
|
41
|
+
|
|
42
|
+
:param contenttype: the content type to match
|
|
43
|
+
:param maintype: the expected maintype
|
|
44
|
+
:param subtype: the expected subtype
|
|
45
|
+
:return: `true` when the given content type matches the given type and subtype,
|
|
46
|
+
regardless of the presence of mime type parameters, otherwise returns `false`.
|
|
47
|
+
:rtype: bool
|
|
48
|
+
"""
|
|
49
|
+
pattern = '{type}/(?:[^+;]+\\+)?{subtype}(?:[ \t]*;.*)?'.format(
|
|
50
|
+
type = re.escape(maintype),
|
|
51
|
+
subtype = re.escape(subtype),
|
|
52
|
+
)
|
|
53
|
+
return re.fullmatch(pattern, contenttype, re.IGNORECASE) is not None
|
|
54
|
+
|
|
55
|
+
def should_bypass_proxies(url: str, no_proxy: str) -> bool:
|
|
56
|
+
"""Return whether ``url`` matches the comma-separated ``no_proxy`` rules."""
|
|
57
|
+
parsed_url = urlparse(url)
|
|
58
|
+
if not parsed_url.hostname:
|
|
59
|
+
return True
|
|
60
|
+
|
|
61
|
+
host = parsed_url.hostname.lower()
|
|
62
|
+
host_and_port = parsed_url.netloc.lower()
|
|
63
|
+
try:
|
|
64
|
+
host_ip = ipaddress.ip_address(host)
|
|
65
|
+
except ValueError:
|
|
66
|
+
host_ip = None
|
|
67
|
+
|
|
68
|
+
for entry in (entry.strip().lower() for entry in no_proxy.split(',')):
|
|
69
|
+
if not entry:
|
|
70
|
+
continue
|
|
71
|
+
if entry == '*':
|
|
72
|
+
return True
|
|
73
|
+
|
|
74
|
+
if host_ip is not None:
|
|
75
|
+
try:
|
|
76
|
+
if host_ip in ipaddress.ip_network(entry, strict=False):
|
|
77
|
+
return True
|
|
78
|
+
except ValueError:
|
|
79
|
+
pass
|
|
80
|
+
|
|
81
|
+
entry = entry.lstrip('.')
|
|
82
|
+
if (
|
|
83
|
+
host == entry
|
|
84
|
+
or host.endswith('.' + entry)
|
|
85
|
+
or host_and_port == entry
|
|
86
|
+
or host_and_port.endswith('.' + entry)
|
|
87
|
+
):
|
|
88
|
+
return True
|
|
89
|
+
|
|
90
|
+
return False
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
class RESTResponse(io.IOBase):
|
|
94
|
+
|
|
95
|
+
def __init__(self, resp) -> None:
|
|
96
|
+
self.response = resp
|
|
97
|
+
self.status = resp.status
|
|
98
|
+
self.reason = resp.reason
|
|
99
|
+
self.data = None
|
|
100
|
+
|
|
101
|
+
def read(self):
|
|
102
|
+
if self.data is None:
|
|
103
|
+
self.data = self.response.data
|
|
104
|
+
return self.data
|
|
105
|
+
|
|
106
|
+
@property
|
|
107
|
+
def headers(self):
|
|
108
|
+
"""Returns a dictionary of response headers."""
|
|
109
|
+
return self.response.headers
|
|
110
|
+
|
|
111
|
+
def getheaders(self):
|
|
112
|
+
"""Returns a dictionary of the response headers; use ``headers`` instead."""
|
|
113
|
+
return self.response.headers
|
|
114
|
+
|
|
115
|
+
def getheader(self, name, default=None):
|
|
116
|
+
"""Returns a given response header; use ``headers.get()`` instead."""
|
|
117
|
+
return self.response.headers.get(name, default)
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
class RESTClientObject:
|
|
121
|
+
|
|
122
|
+
def __init__(self, configuration) -> None:
|
|
123
|
+
# urllib3.PoolManager will pass all kw parameters to connectionpool
|
|
124
|
+
# https://github.com/shazow/urllib3/blob/f9409436f83aeb79fbaf090181cd81b784f1b8ce/urllib3/poolmanager.py#L75 # noqa: E501
|
|
125
|
+
# https://github.com/shazow/urllib3/blob/f9409436f83aeb79fbaf090181cd81b784f1b8ce/urllib3/connectionpool.py#L680 # noqa: E501
|
|
126
|
+
# Custom SSL certificates and client certificates: http://urllib3.readthedocs.io/en/latest/advanced-usage.html # noqa: E501
|
|
127
|
+
|
|
128
|
+
# cert_reqs
|
|
129
|
+
if configuration.verify_ssl:
|
|
130
|
+
cert_reqs = ssl.CERT_REQUIRED
|
|
131
|
+
else:
|
|
132
|
+
cert_reqs = ssl.CERT_NONE
|
|
133
|
+
|
|
134
|
+
pool_args = {
|
|
135
|
+
"cert_reqs": cert_reqs,
|
|
136
|
+
"ca_certs": configuration.ssl_ca_cert,
|
|
137
|
+
"cert_file": configuration.cert_file,
|
|
138
|
+
"key_file": configuration.key_file,
|
|
139
|
+
"ca_cert_data": configuration.ca_cert_data,
|
|
140
|
+
}
|
|
141
|
+
if configuration.assert_hostname is not None:
|
|
142
|
+
pool_args['assert_hostname'] = (
|
|
143
|
+
configuration.assert_hostname
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
if configuration.retries is not None:
|
|
147
|
+
pool_args['retries'] = configuration.retries
|
|
148
|
+
|
|
149
|
+
if configuration.tls_server_name:
|
|
150
|
+
pool_args['server_hostname'] = configuration.tls_server_name
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
if configuration.socket_options is not None:
|
|
154
|
+
pool_args['socket_options'] = configuration.socket_options
|
|
155
|
+
|
|
156
|
+
if configuration.connection_pool_maxsize is not None:
|
|
157
|
+
pool_args['maxsize'] = configuration.connection_pool_maxsize
|
|
158
|
+
|
|
159
|
+
# https pool manager
|
|
160
|
+
self.pool_manager: urllib3.PoolManager
|
|
161
|
+
|
|
162
|
+
if configuration.proxy and not should_bypass_proxies(
|
|
163
|
+
configuration.host, configuration.no_proxy or ''
|
|
164
|
+
):
|
|
165
|
+
if is_socks_proxy_url(configuration.proxy):
|
|
166
|
+
from urllib3.contrib.socks import SOCKSProxyManager
|
|
167
|
+
pool_args["proxy_url"] = configuration.proxy
|
|
168
|
+
pool_args["headers"] = configuration.proxy_headers
|
|
169
|
+
self.pool_manager = SOCKSProxyManager(**pool_args)
|
|
170
|
+
else:
|
|
171
|
+
pool_args["proxy_url"] = configuration.proxy
|
|
172
|
+
pool_args["proxy_headers"] = configuration.proxy_headers
|
|
173
|
+
if configuration.proxy_ssl_context is not None:
|
|
174
|
+
pool_args["proxy_ssl_context"] = configuration.proxy_ssl_context
|
|
175
|
+
self.pool_manager = urllib3.ProxyManager(**pool_args)
|
|
176
|
+
else:
|
|
177
|
+
self.pool_manager = urllib3.PoolManager(**pool_args)
|
|
178
|
+
|
|
179
|
+
def request(
|
|
180
|
+
self,
|
|
181
|
+
method,
|
|
182
|
+
url,
|
|
183
|
+
headers=None,
|
|
184
|
+
body=None,
|
|
185
|
+
post_params=None,
|
|
186
|
+
_request_timeout=None
|
|
187
|
+
):
|
|
188
|
+
"""Perform requests.
|
|
189
|
+
|
|
190
|
+
:param method: http request method
|
|
191
|
+
:param url: http request url
|
|
192
|
+
:param headers: http request headers
|
|
193
|
+
:param body: request json body, for `application/json`
|
|
194
|
+
:param post_params: request post parameters,
|
|
195
|
+
`application/x-www-form-urlencoded`
|
|
196
|
+
and `multipart/form-data`
|
|
197
|
+
:param _request_timeout: timeout setting for this request. If one
|
|
198
|
+
number provided, it will be total request
|
|
199
|
+
timeout. It can also be a pair (tuple) of
|
|
200
|
+
(connection, read) timeouts.
|
|
201
|
+
"""
|
|
202
|
+
method = method.upper()
|
|
203
|
+
assert method in [
|
|
204
|
+
'GET',
|
|
205
|
+
'HEAD',
|
|
206
|
+
'DELETE',
|
|
207
|
+
'POST',
|
|
208
|
+
'PUT',
|
|
209
|
+
'PATCH',
|
|
210
|
+
'OPTIONS'
|
|
211
|
+
]
|
|
212
|
+
|
|
213
|
+
if post_params and body:
|
|
214
|
+
raise ApiValueError(
|
|
215
|
+
"body parameter cannot be used with post_params parameter."
|
|
216
|
+
)
|
|
217
|
+
|
|
218
|
+
post_params = post_params or {}
|
|
219
|
+
headers = headers or {}
|
|
220
|
+
|
|
221
|
+
timeout = None
|
|
222
|
+
if _request_timeout:
|
|
223
|
+
if isinstance(_request_timeout, (int, float)):
|
|
224
|
+
timeout = urllib3.Timeout(total=_request_timeout)
|
|
225
|
+
elif (
|
|
226
|
+
isinstance(_request_timeout, tuple)
|
|
227
|
+
and len(_request_timeout) == 2
|
|
228
|
+
):
|
|
229
|
+
timeout = urllib3.Timeout(
|
|
230
|
+
connect=_request_timeout[0],
|
|
231
|
+
read=_request_timeout[1]
|
|
232
|
+
)
|
|
233
|
+
|
|
234
|
+
try:
|
|
235
|
+
# For `POST`, `PUT`, `PATCH`, `OPTIONS`, `DELETE`
|
|
236
|
+
if method in ['POST', 'PUT', 'PATCH', 'OPTIONS', 'DELETE']:
|
|
237
|
+
|
|
238
|
+
content_type = headers.get('Content-Type')
|
|
239
|
+
is_json = (
|
|
240
|
+
not content_type
|
|
241
|
+
or contenttype_matches(content_type, 'application', 'json')
|
|
242
|
+
)
|
|
243
|
+
# JSON is valid YAML 1.2, so structured YAML bodies can use
|
|
244
|
+
# the existing JSON serializer:
|
|
245
|
+
# https://yaml.org/spec/1.2.2/#13-relation-to-json
|
|
246
|
+
is_structured_yaml = (
|
|
247
|
+
content_type
|
|
248
|
+
and (
|
|
249
|
+
contenttype_matches(content_type, 'application', 'yaml')
|
|
250
|
+
or contenttype_matches(content_type, 'text', 'yaml')
|
|
251
|
+
or contenttype_matches(content_type, 'text', 'x-yaml')
|
|
252
|
+
)
|
|
253
|
+
and not isinstance(body, (str, bytes))
|
|
254
|
+
)
|
|
255
|
+
if is_json or is_structured_yaml:
|
|
256
|
+
request_body = None
|
|
257
|
+
if body is not None:
|
|
258
|
+
request_body = json.dumps(body)
|
|
259
|
+
r = self.pool_manager.request(
|
|
260
|
+
method,
|
|
261
|
+
url,
|
|
262
|
+
body=request_body,
|
|
263
|
+
timeout=timeout,
|
|
264
|
+
headers=headers,
|
|
265
|
+
preload_content=False
|
|
266
|
+
)
|
|
267
|
+
elif contenttype_matches(content_type, 'application', 'x-www-form-urlencoded'):
|
|
268
|
+
r = self.pool_manager.request(
|
|
269
|
+
method,
|
|
270
|
+
url,
|
|
271
|
+
fields=post_params,
|
|
272
|
+
encode_multipart=False,
|
|
273
|
+
timeout=timeout,
|
|
274
|
+
headers=headers,
|
|
275
|
+
preload_content=False
|
|
276
|
+
)
|
|
277
|
+
elif contenttype_matches(content_type, 'multipart', 'form-data'):
|
|
278
|
+
# must del headers['Content-Type'], or the correct
|
|
279
|
+
# Content-Type which generated by urllib3 will be
|
|
280
|
+
# overwritten.
|
|
281
|
+
del headers['Content-Type']
|
|
282
|
+
# Ensures that dict objects are serialized
|
|
283
|
+
post_params = [(a, json.dumps(b)) if isinstance(b, dict) else (a,b) for a, b in post_params]
|
|
284
|
+
r = self.pool_manager.request(
|
|
285
|
+
method,
|
|
286
|
+
url,
|
|
287
|
+
fields=post_params,
|
|
288
|
+
encode_multipart=True,
|
|
289
|
+
timeout=timeout,
|
|
290
|
+
headers=headers,
|
|
291
|
+
preload_content=False
|
|
292
|
+
)
|
|
293
|
+
# Pass a `string` parameter directly in the body to support
|
|
294
|
+
# other content types than JSON when `body` argument is
|
|
295
|
+
# provided in serialized form.
|
|
296
|
+
elif isinstance(body, str) or isinstance(body, bytes):
|
|
297
|
+
r = self.pool_manager.request(
|
|
298
|
+
method,
|
|
299
|
+
url,
|
|
300
|
+
body=body,
|
|
301
|
+
timeout=timeout,
|
|
302
|
+
headers=headers,
|
|
303
|
+
preload_content=False
|
|
304
|
+
)
|
|
305
|
+
elif content_type.startswith('text/') and isinstance(body, bool):
|
|
306
|
+
request_body = "true" if body else "false"
|
|
307
|
+
r = self.pool_manager.request(
|
|
308
|
+
method,
|
|
309
|
+
url,
|
|
310
|
+
body=request_body,
|
|
311
|
+
preload_content=False,
|
|
312
|
+
timeout=timeout,
|
|
313
|
+
headers=headers)
|
|
314
|
+
else:
|
|
315
|
+
# Cannot generate the request from given parameters
|
|
316
|
+
msg = """Cannot prepare a request message for provided
|
|
317
|
+
arguments. Please check that your arguments match
|
|
318
|
+
declared content type."""
|
|
319
|
+
raise ApiException(status=0, reason=msg)
|
|
320
|
+
# For `GET`, `HEAD`
|
|
321
|
+
else:
|
|
322
|
+
r = self.pool_manager.request(
|
|
323
|
+
method,
|
|
324
|
+
url,
|
|
325
|
+
fields={},
|
|
326
|
+
timeout=timeout,
|
|
327
|
+
headers=headers,
|
|
328
|
+
preload_content=False
|
|
329
|
+
)
|
|
330
|
+
except urllib3.exceptions.SSLError as e:
|
|
331
|
+
msg = "\n".join([type(e).__name__, str(e)])
|
|
332
|
+
raise ApiException(status=0, reason=msg)
|
|
333
|
+
|
|
334
|
+
return RESTResponse(r)
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"""OAuth 2.0 client credentials for the Method SDK."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import os
|
|
5
|
+
import threading
|
|
6
|
+
import time
|
|
7
|
+
from typing import Any, Dict, Optional
|
|
8
|
+
|
|
9
|
+
import urllib3
|
|
10
|
+
|
|
11
|
+
from method_sdk.configuration import Configuration
|
|
12
|
+
|
|
13
|
+
CLIENT_ID_ENV = "METHOD_CLIENT_ID"
|
|
14
|
+
CLIENT_SECRET_ENV = "METHOD_CLIENT_SECRET"
|
|
15
|
+
|
|
16
|
+
_TOKEN_PATH = "/auth/getToken"
|
|
17
|
+
_REFRESH_WINDOW_SECONDS = 30
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class ClientCredentials:
|
|
21
|
+
"""Fetches a token on first use, caches it, and refreshes it before it expires."""
|
|
22
|
+
|
|
23
|
+
def __init__(
|
|
24
|
+
self,
|
|
25
|
+
client_id: str,
|
|
26
|
+
client_secret: str,
|
|
27
|
+
token_url: str,
|
|
28
|
+
pool_manager: Optional[urllib3.PoolManager] = None,
|
|
29
|
+
) -> None:
|
|
30
|
+
self._client_id = client_id
|
|
31
|
+
self._client_secret = client_secret
|
|
32
|
+
self._token_url = token_url
|
|
33
|
+
self._pool_manager = pool_manager or urllib3.PoolManager()
|
|
34
|
+
self._lock = threading.Lock()
|
|
35
|
+
self._token: Optional[str] = None
|
|
36
|
+
self._expires_at = 0.0
|
|
37
|
+
|
|
38
|
+
@classmethod
|
|
39
|
+
def from_env(cls, host: str, pool_manager: Optional[urllib3.PoolManager] = None) -> "ClientCredentials":
|
|
40
|
+
"""Reads METHOD_CLIENT_ID and METHOD_CLIENT_SECRET; the token URL is derived from the API host."""
|
|
41
|
+
return cls(_require_env(CLIENT_ID_ENV), _require_env(CLIENT_SECRET_ENV), token_url(host), pool_manager)
|
|
42
|
+
|
|
43
|
+
def token(self) -> str:
|
|
44
|
+
with self._lock:
|
|
45
|
+
if self._token is None or self._expires_at - time.time() < _REFRESH_WINDOW_SECONDS:
|
|
46
|
+
self._fetch()
|
|
47
|
+
assert self._token is not None
|
|
48
|
+
return self._token
|
|
49
|
+
|
|
50
|
+
def _fetch(self) -> None:
|
|
51
|
+
requested_at = time.time()
|
|
52
|
+
# Form body rather than Basic: the rubix AuthResource only reads credentials from the form.
|
|
53
|
+
response = self._pool_manager.request(
|
|
54
|
+
"POST",
|
|
55
|
+
self._token_url,
|
|
56
|
+
fields={
|
|
57
|
+
"grant_type": "client_credentials",
|
|
58
|
+
"client_id": self._client_id,
|
|
59
|
+
"client_secret": self._client_secret,
|
|
60
|
+
},
|
|
61
|
+
encode_multipart=False,
|
|
62
|
+
headers={"Accept": "application/json"},
|
|
63
|
+
)
|
|
64
|
+
body = response.data.decode("utf-8")
|
|
65
|
+
if response.status < 200 or response.status >= 300:
|
|
66
|
+
raise RuntimeError(f"Method token endpoint returned {response.status}: {body}")
|
|
67
|
+
parsed = json.loads(body)
|
|
68
|
+
self._token = parsed["access_token"]
|
|
69
|
+
self._expires_at = requested_at + parsed["expires_in"]
|
|
70
|
+
|
|
71
|
+
def __deepcopy__(self, memo: Dict[int, Any]) -> "ClientCredentials":
|
|
72
|
+
# Copies of a configuration share one token cache.
|
|
73
|
+
return self
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
class MethodConfiguration(Configuration):
|
|
77
|
+
"""Configuration that authenticates with client credentials unless an access token is given."""
|
|
78
|
+
|
|
79
|
+
def __init__(
|
|
80
|
+
self,
|
|
81
|
+
host: str,
|
|
82
|
+
credentials: Optional[ClientCredentials] = None,
|
|
83
|
+
access_token: Optional[str] = None,
|
|
84
|
+
**kwargs: Any,
|
|
85
|
+
) -> None:
|
|
86
|
+
self._credentials = credentials
|
|
87
|
+
super().__init__(host=host, access_token=access_token, **kwargs)
|
|
88
|
+
|
|
89
|
+
@property
|
|
90
|
+
def access_token(self) -> Optional[str]:
|
|
91
|
+
if self._access_token is not None:
|
|
92
|
+
return self._access_token
|
|
93
|
+
if self._credentials is None:
|
|
94
|
+
self._credentials = ClientCredentials.from_env(self.host, self._token_pool_manager())
|
|
95
|
+
return self._credentials.token()
|
|
96
|
+
|
|
97
|
+
@access_token.setter
|
|
98
|
+
def access_token(self, value: Optional[str]) -> None:
|
|
99
|
+
self._access_token = value
|
|
100
|
+
|
|
101
|
+
def _token_pool_manager(self) -> urllib3.PoolManager:
|
|
102
|
+
return urllib3.PoolManager(
|
|
103
|
+
cert_reqs="CERT_REQUIRED" if self.verify_ssl else "CERT_NONE",
|
|
104
|
+
ca_certs=self.ssl_ca_cert,
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def token_url(host: str) -> str:
|
|
109
|
+
return host.rstrip("/") + _TOKEN_PATH
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def _require_env(name: str) -> str:
|
|
113
|
+
value = os.environ.get(name)
|
|
114
|
+
if not value:
|
|
115
|
+
raise ValueError(f"{name} is not set")
|
|
116
|
+
return value
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"""Base of the typed errors in method_sdk.errors, which is generated from the model."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
from typing import Any, Dict, Optional
|
|
5
|
+
|
|
6
|
+
from method_sdk.exceptions import ApiException
|
|
7
|
+
|
|
8
|
+
_ERROR_TYPE_HEADER = "X-Amzn-Errortype"
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class MethodError(ApiException):
|
|
12
|
+
"""An error a Method API returned. Each also extends the generic exception for its status code."""
|
|
13
|
+
|
|
14
|
+
def __init__(self, *args: Any, **kwargs: Any) -> None:
|
|
15
|
+
super().__init__(*args, **kwargs)
|
|
16
|
+
self.error_code = type(self).__name__
|
|
17
|
+
self.message: Optional[str] = _json_object(self.body).get("message")
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def raise_typed_error(http_resp: Any, body: Optional[str], data: Any) -> None:
|
|
21
|
+
"""Raises the typed error the response's error type header names, if any. Called by ApiException.from_response."""
|
|
22
|
+
from method_sdk.errors import ERRORS
|
|
23
|
+
|
|
24
|
+
# restJson1 allows a `:`-separated suffix after the shape ID.
|
|
25
|
+
shape_id = (http_resp.headers or {}).get(_ERROR_TYPE_HEADER, "").split(":")[0].strip()
|
|
26
|
+
error = ERRORS.get(shape_id)
|
|
27
|
+
if error is not None:
|
|
28
|
+
raise error(http_resp=http_resp, body=body, data=data)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _json_object(body: Optional[str]) -> Dict[str, Any]:
|
|
32
|
+
try:
|
|
33
|
+
parsed = json.loads(body or "")
|
|
34
|
+
except ValueError:
|
|
35
|
+
return {}
|
|
36
|
+
return parsed if isinstance(parsed, dict) else {}
|
method_sdk/pagination.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"""Follows pagination tokens for the generated paginators in each service's paginators module."""
|
|
2
|
+
|
|
3
|
+
from typing import Any, Callable, Iterator, Optional, Sequence, TypeVar
|
|
4
|
+
|
|
5
|
+
Page = TypeVar("Page")
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def paginate(operation: Callable[..., Page], input_token: str, output_token: Sequence[str], **kwargs: Any) -> Iterator[Page]:
|
|
9
|
+
"""Yields each page of operation, passing the last page's output token as input_token until there's none."""
|
|
10
|
+
token: Optional[str] = kwargs.pop(input_token, None)
|
|
11
|
+
while True:
|
|
12
|
+
page = operation(**kwargs, **({input_token: token} if token else {}))
|
|
13
|
+
yield page
|
|
14
|
+
next_token: Any = page
|
|
15
|
+
for name in output_token:
|
|
16
|
+
next_token = getattr(next_token, name, None)
|
|
17
|
+
# A repeated token would loop forever.
|
|
18
|
+
if not next_token or next_token == token:
|
|
19
|
+
return
|
|
20
|
+
token = next_token
|
method_sdk/py.typed
ADDED
|
File without changes
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: method-security-sdk
|
|
3
|
+
Version: 0.35.0
|
|
4
|
+
Summary: Python SDK for the Method API.
|
|
5
|
+
Home-page:
|
|
6
|
+
Author: Method Security
|
|
7
|
+
Author-email: team@openapitools.org
|
|
8
|
+
Project-URL: Repository, https://github.com/method-security/method-python-sdk
|
|
9
|
+
Keywords: Method
|
|
10
|
+
Classifier: License :: Other/Proprietary License
|
|
11
|
+
Requires-Python: >=3.10
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
Requires-Dist: urllib3<3.0.0,>=2.7.0
|
|
14
|
+
Requires-Dist: python-dateutil>=2.8.2
|
|
15
|
+
Requires-Dist: pydantic>=2.11
|
|
16
|
+
Requires-Dist: typing-extensions>=4.7.1
|
|
17
|
+
Dynamic: author-email
|
|
18
|
+
|
|
19
|
+
# Method Python SDK
|
|
20
|
+
|
|
21
|
+
Python SDK for the Method API, one module per service:
|
|
22
|
+
|
|
23
|
+
- `method_sdk.inventory`
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
method_sdk/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
method_sdk/configuration.py,sha256=U6ZtrWwhzmd1bfd4yAbZYLcpnPTedmNvcpsvcPmVCqE,21957
|
|
3
|
+
method_sdk/errors.py,sha256=JhphWreT5xgElA03CVQ60AlV9JXFu92B98mhXI7126E,1940
|
|
4
|
+
method_sdk/exceptions.py,sha256=no0EJi60VAbOO4wQkzNND0iv-VNCx0xC0hQJY3SGyeQ,6566
|
|
5
|
+
method_sdk/method_auth.py,sha256=LJmDX-ZSH06fzrw1a_ia4QGxE07i8ALgQwoPbBNO6v8,3920
|
|
6
|
+
method_sdk/method_error.py,sha256=IkH1kM2-AhqKqfvbyrEXyeAAH-tipZbBzxzAqY_3pBA,1316
|
|
7
|
+
method_sdk/pagination.py,sha256=k4fBj9V7GVojDzClEn-1C4bX30FzTM9lnG3bGa15VyA,871
|
|
8
|
+
method_sdk/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
|
+
method_sdk/inventory/__init__.py,sha256=Kj7-SFWzYflgUhVXdd93H3ZWeMH0VW4sTVH0KmXO4yA,5355
|
|
10
|
+
method_sdk/inventory/api_client.py,sha256=sAAzMRvbKkNVu9jzd05crvJhL79q7hs2SMNB311uPs4,29511
|
|
11
|
+
method_sdk/inventory/api_response.py,sha256=eMxw1mpmJcoGZ3gs9z6jM4oYoZ10Gjk333s9sKxGv7s,652
|
|
12
|
+
method_sdk/inventory/configuration.py,sha256=dEuTZzAWmEmYd6H8sF_w7fKLGmJrPprVa8pF2iCinZw,21963
|
|
13
|
+
method_sdk/inventory/exceptions.py,sha256=jxAuKOlVBY9IO-vPBMbKP47dGqI6q1aCQ7MI2TdnW1Y,55
|
|
14
|
+
method_sdk/inventory/paginators.py,sha256=_qLH7Yo8riNXKE4_jklGYvB89COT5cTg9bjJSRlXdmI,600
|
|
15
|
+
method_sdk/inventory/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
16
|
+
method_sdk/inventory/rest.py,sha256=aiSVSKn1MItGOfIBj3A2SG_57abGorfP88IhSNPabiQ,12291
|
|
17
|
+
method_sdk/inventory/api/__init__.py,sha256=vOIBYYk_qycoXce6KD1aw9K1HTgFfj_pH4Bntfu1L1Q,112
|
|
18
|
+
method_sdk/inventory/api/inventory_api.py,sha256=bDNR140jX4UuRq1mULC6Uf0DgTkU4ib8ysWB0Y_Dm3A,62581
|
|
19
|
+
method_sdk/inventory/models/__init__.py,sha256=aKH1lmEZO6WuFho8U9E43ilSwCuwjEDB5_2IEnui9QI,2669
|
|
20
|
+
method_sdk/inventory/models/access_denied_response_content.py,sha256=TG3Hv09RuTjVfOeOg4gVjWMFPo3vfMYtxLjHQG9IPJ8,2700
|
|
21
|
+
method_sdk/inventory/models/create_environment400_error_response_content.py,sha256=tx13UpXXzE6DlN4Dr6zx1TiPtcbpBEXxg7cNgTk-VeQ,6343
|
|
22
|
+
method_sdk/inventory/models/create_environment_request_content.py,sha256=AmCMHPw4VpXMMv0hDWBLSxNULydwott4GpCYtYC0jlM,2546
|
|
23
|
+
method_sdk/inventory/models/create_environment_response_content.py,sha256=27CUhFELkwWA8Yu9iRGKK0liISq90aC7PWnRr1orDW0,2818
|
|
24
|
+
method_sdk/inventory/models/delete_environment400_error_response_content.py,sha256=guCSDMLkVW60B28KUz58hiG4eqecsXdMkEgSUF-rm-M,6343
|
|
25
|
+
method_sdk/inventory/models/delete_environment_response_content.py,sha256=3YXFcmNLGB7FF2N_2fddXrqXP6XdjvGbnuSFsO45rhs,2818
|
|
26
|
+
method_sdk/inventory/models/environment.py,sha256=VdxAUGi3JCb2Al7x9HejMZX699zmmQ29jxPpLxXG3QE,3423
|
|
27
|
+
method_sdk/inventory/models/environment_not_found_response_content.py,sha256=vrnA0Qk1kplmLElaAt5_uspa26Ld1aKWMiHJk2rmkbQ,2712
|
|
28
|
+
method_sdk/inventory/models/environment_state.py,sha256=wASlZlKGZMpVjjxj2DaXuxHSpiiuHdzQgLk35gfK7NI,730
|
|
29
|
+
method_sdk/inventory/models/get_environment400_error_response_content.py,sha256=L4U0XedPJSZorQl1NYr2C1OL8IUZlgIb9P_zN0Glz-4,6319
|
|
30
|
+
method_sdk/inventory/models/get_environment_response_content.py,sha256=lfSmv8Adpan0x6XDn_6SafbqW-v3-6d2yMQZ8hIYsU0,2806
|
|
31
|
+
method_sdk/inventory/models/internal_server_response_content.py,sha256=9s1jPiIIuS1cNjUnI3h5pUpwPp7RElB727lT0dzKuLE,2722
|
|
32
|
+
method_sdk/inventory/models/invalid_parameter.py,sha256=gAGr2panN0JYQh4xT1xrHy-d5npBsGT4qRtT1VvdU8M,2710
|
|
33
|
+
method_sdk/inventory/models/list_environments400_error_response_content.py,sha256=6QfDwc9ZCd4hnz3fn9_Z3x-8Tpin4MIqWIZOoPwBJhs,6335
|
|
34
|
+
method_sdk/inventory/models/list_environments_response_content.py,sha256=CwvUviS1O8a4zWvZVfYS184wYyrk0JPdoDyrcA9AVbg,3260
|
|
35
|
+
method_sdk/inventory/models/malformed_request.py,sha256=4GulHNxmHudOQ3fdaR33iCnQneO9UzmFgPV4Qwnxg00,2707
|
|
36
|
+
method_sdk/inventory/models/missing_parameter.py,sha256=0evyBLY9TRiNDHmXGDm9zZoEg-VRoZV7bUvhtVYGKVE,2663
|
|
37
|
+
method_sdk/inventory/models/service_unavailable_response_content.py,sha256=FS5HQRrgJtf99i0f617lE1zMeHxoUg8tH1_A4SDqKPs,2755
|
|
38
|
+
method_sdk/inventory/models/throttling_response_content.py,sha256=-0Ia9FEKX5bEIODLCOs1gfv46iGEkhDMWWZnxm94kHg,2712
|
|
39
|
+
method_sdk/inventory/models/unauthenticated_response_content.py,sha256=gtkGC4JuQxYdBbT92qwt2dzKcN76AAyxaYS4gdoHHbg,2711
|
|
40
|
+
method_sdk/inventory/models/update_environment400_error_response_content.py,sha256=PMaoz0S0QKRZq5VWl6dCC9hQG1DzAX_nvWXsQ14ylzg,6343
|
|
41
|
+
method_sdk/inventory/models/update_environment_request_content.py,sha256=Uhxu42VcnC4xXxDay0aw1wrGrtaSdEfasYHTCO2yvms,2580
|
|
42
|
+
method_sdk/inventory/models/update_environment_response_content.py,sha256=9ocdC9R330wGfKlNpwa7Dx20ud3BaAu-UlAXYKM6ur8,2818
|
|
43
|
+
method_security_sdk-0.35.0.dist-info/METADATA,sha256=7BbnJPoDB5wJUpnuvSFxCkajSiJldKeF6btSn2Hzrkk,654
|
|
44
|
+
method_security_sdk-0.35.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
45
|
+
method_security_sdk-0.35.0.dist-info/top_level.txt,sha256=edCs-EJn7YHTVT7VfG46yovzNMlBIeTYQIRLkDy3Ih4,11
|
|
46
|
+
method_security_sdk-0.35.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
method_sdk
|