capo-codeguru-security 0.1.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.
- capo_codeguru_security/__init__.py +74 -0
- capo_codeguru_security/_async.py +25 -0
- capo_codeguru_security/_auth/_identity.py +16 -0
- capo_codeguru_security/_auth/_providers.py +886 -0
- capo_codeguru_security/_auth/_signers.py +88 -0
- capo_codeguru_security/_auth/_sigv4.py +434 -0
- capo_codeguru_security/_auth/_zapros_handler.py +80 -0
- capo_codeguru_security/_iter.py +113 -0
- capo_codeguru_security/_operations/aws_code_guru_security/batch_get_findings.py +167 -0
- capo_codeguru_security/_operations/aws_code_guru_security/create_scan.py +183 -0
- capo_codeguru_security/_operations/aws_code_guru_security/create_upload_url.py +165 -0
- capo_codeguru_security/_operations/aws_code_guru_security/get_account_configuration.py +161 -0
- capo_codeguru_security/_operations/aws_code_guru_security/get_findings.py +191 -0
- capo_codeguru_security/_operations/aws_code_guru_security/get_metrics_summary.py +176 -0
- capo_codeguru_security/_operations/aws_code_guru_security/get_scan.py +173 -0
- capo_codeguru_security/_operations/aws_code_guru_security/list_findings_metrics.py +185 -0
- capo_codeguru_security/_operations/aws_code_guru_security/list_scans.py +167 -0
- capo_codeguru_security/_operations/aws_code_guru_security/list_tags_for_resource.py +173 -0
- capo_codeguru_security/_operations/aws_code_guru_security/tag_resource.py +173 -0
- capo_codeguru_security/_operations/aws_code_guru_security/untag_resource.py +171 -0
- capo_codeguru_security/_operations/aws_code_guru_security/update_account_configuration.py +172 -0
- capo_codeguru_security/_pagination.py +21 -0
- capo_codeguru_security/_protocol/__init__.py +1 -0
- capo_codeguru_security/_protocol/errors.py +93 -0
- capo_codeguru_security/_protocol/eventstream.py +238 -0
- capo_codeguru_security/_protocol/serialize.py +47 -0
- capo_codeguru_security/_protocol/xml.py +33 -0
- capo_codeguru_security/_rule_engine/__init__.py +0 -0
- capo_codeguru_security/_rule_engine/_aws_partition.py +160 -0
- capo_codeguru_security/_rule_engine/_endpoint_rule_set.py +137 -0
- capo_codeguru_security/_rule_engine/_endpoint_runtime.py +389 -0
- capo_codeguru_security/_services/_aws_config.py +160 -0
- capo_codeguru_security/_services/_pipeline.py +198 -0
- capo_codeguru_security/_services/async_code_guru_security.py +934 -0
- capo_codeguru_security/_services/code_guru_security.py +921 -0
- capo_codeguru_security/errors/__init__.py +33 -0
- capo_codeguru_security/errors/_base.py +94 -0
- capo_codeguru_security/errors/access_denied_exception.py +67 -0
- capo_codeguru_security/errors/conflict_exception.py +67 -0
- capo_codeguru_security/errors/internal_server_exception.py +53 -0
- capo_codeguru_security/errors/resource_not_found_exception.py +69 -0
- capo_codeguru_security/errors/throttling_exception.py +65 -0
- capo_codeguru_security/errors/validation_exception.py +98 -0
- capo_codeguru_security/py.typed +0 -0
- capo_codeguru_security/types/_prelude/blob.py +12 -0
- capo_codeguru_security/types/_prelude/timestamp.py +17 -0
- capo_codeguru_security/types/account_findings_metric.py +118 -0
- capo_codeguru_security/types/analysis_type.py +17 -0
- capo_codeguru_security/types/batch_get_findings_error.py +61 -0
- capo_codeguru_security/types/batch_get_findings_errors.py +35 -0
- capo_codeguru_security/types/batch_get_findings_request.py +47 -0
- capo_codeguru_security/types/batch_get_findings_response.py +61 -0
- capo_codeguru_security/types/categories_with_most_findings.py +37 -0
- capo_codeguru_security/types/category_with_finding_num.py +29 -0
- capo_codeguru_security/types/client_token.py +5 -0
- capo_codeguru_security/types/code_line.py +29 -0
- capo_codeguru_security/types/code_snippet.py +29 -0
- capo_codeguru_security/types/create_scan_request.py +101 -0
- capo_codeguru_security/types/create_scan_response.py +78 -0
- capo_codeguru_security/types/create_upload_url_request.py +31 -0
- capo_codeguru_security/types/create_upload_url_response.py +59 -0
- capo_codeguru_security/types/detector_tags.py +14 -0
- capo_codeguru_security/types/encryption_config.py +28 -0
- capo_codeguru_security/types/error_code.py +20 -0
- capo_codeguru_security/types/error_message.py +5 -0
- capo_codeguru_security/types/file_path.py +62 -0
- capo_codeguru_security/types/finding.py +207 -0
- capo_codeguru_security/types/finding_identifier.py +33 -0
- capo_codeguru_security/types/finding_identifiers.py +33 -0
- capo_codeguru_security/types/finding_metrics_value_per_severity.py +87 -0
- capo_codeguru_security/types/findings.py +29 -0
- capo_codeguru_security/types/findings_metric_list.py +35 -0
- capo_codeguru_security/types/get_account_configuration_request.py +18 -0
- capo_codeguru_security/types/get_account_configuration_response.py +45 -0
- capo_codeguru_security/types/get_findings_request.py +32 -0
- capo_codeguru_security/types/get_findings_response.py +43 -0
- capo_codeguru_security/types/get_metrics_summary_request.py +24 -0
- capo_codeguru_security/types/get_metrics_summary_response.py +42 -0
- capo_codeguru_security/types/get_scan_request.py +27 -0
- capo_codeguru_security/types/get_scan_response.py +132 -0
- capo_codeguru_security/types/header_key.py +5 -0
- capo_codeguru_security/types/header_value.py +5 -0
- capo_codeguru_security/types/kms_key_arn.py +5 -0
- capo_codeguru_security/types/list_findings_metrics_request.py +32 -0
- capo_codeguru_security/types/list_findings_metrics_response.py +49 -0
- capo_codeguru_security/types/list_scans_request.py +26 -0
- capo_codeguru_security/types/list_scans_response.py +43 -0
- capo_codeguru_security/types/list_tags_for_resource_request.py +24 -0
- capo_codeguru_security/types/list_tags_for_resource_response.py +34 -0
- capo_codeguru_security/types/metrics_summary.py +121 -0
- capo_codeguru_security/types/next_token.py +5 -0
- capo_codeguru_security/types/recommendation.py +29 -0
- capo_codeguru_security/types/reference_urls.py +14 -0
- capo_codeguru_security/types/related_vulnerabilities.py +14 -0
- capo_codeguru_security/types/remediation.py +63 -0
- capo_codeguru_security/types/request_header_map.py +29 -0
- capo_codeguru_security/types/resource.py +29 -0
- capo_codeguru_security/types/resource_id.py +32 -0
- capo_codeguru_security/types/s3_url.py +5 -0
- capo_codeguru_security/types/scan_name.py +5 -0
- capo_codeguru_security/types/scan_name_arn.py +5 -0
- capo_codeguru_security/types/scan_name_with_finding_num.py +29 -0
- capo_codeguru_security/types/scan_state.py +18 -0
- capo_codeguru_security/types/scan_summaries.py +29 -0
- capo_codeguru_security/types/scan_summary.py +99 -0
- capo_codeguru_security/types/scan_type.py +17 -0
- capo_codeguru_security/types/scans_with_most_open_critical_findings.py +37 -0
- capo_codeguru_security/types/scans_with_most_open_findings.py +37 -0
- capo_codeguru_security/types/severity.py +20 -0
- capo_codeguru_security/types/status.py +18 -0
- capo_codeguru_security/types/suggested_fix.py +29 -0
- capo_codeguru_security/types/suggested_fixes.py +31 -0
- capo_codeguru_security/types/tag_key.py +5 -0
- capo_codeguru_security/types/tag_key_list.py +17 -0
- capo_codeguru_security/types/tag_map.py +29 -0
- capo_codeguru_security/types/tag_resource_request.py +40 -0
- capo_codeguru_security/types/tag_resource_response.py +18 -0
- capo_codeguru_security/types/tag_value.py +5 -0
- capo_codeguru_security/types/untag_resource_request.py +27 -0
- capo_codeguru_security/types/untag_resource_response.py +18 -0
- capo_codeguru_security/types/update_account_configuration_request.py +45 -0
- capo_codeguru_security/types/update_account_configuration_response.py +45 -0
- capo_codeguru_security/types/uuid.py +5 -0
- capo_codeguru_security/types/validation_exception_field.py +33 -0
- capo_codeguru_security/types/validation_exception_field_list.py +37 -0
- capo_codeguru_security/types/validation_exception_reason.py +20 -0
- capo_codeguru_security/types/vulnerability.py +90 -0
- capo_codeguru_security-0.1.0.dist-info/METADATA +101 -0
- capo_codeguru_security-0.1.0.dist-info/RECORD +132 -0
- capo_codeguru_security-0.1.0.dist-info/WHEEL +5 -0
- capo_codeguru_security-0.1.0.dist-info/licenses/LICENSE +21 -0
- capo_codeguru_security-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"""Iterator helpers used by generated streaming operations.
|
|
2
|
+
|
|
3
|
+
Hand-written, not regenerated.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
from collections.abc import AsyncIterable, AsyncIterator, Callable, Iterable, Iterator
|
|
9
|
+
from typing import Generic, TypeVar, cast
|
|
10
|
+
|
|
11
|
+
T = TypeVar("T")
|
|
12
|
+
U = TypeVar("U")
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class AnyIterator(AsyncIterator[T], Iterator[T], Generic[T]):
|
|
16
|
+
"""A type that is both a synchronous and asynchronous iterator.
|
|
17
|
+
|
|
18
|
+
Streaming output fields use this so the same TypedDict type works for
|
|
19
|
+
both sync and async operation variants.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
...
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class StaticAnyIterator(AnyIterator[T], Generic[T]):
|
|
26
|
+
"""An :class:`AnyIterator` backed by static, in-memory content.
|
|
27
|
+
|
|
28
|
+
Used when streaming output is produced from already-materialized bytes
|
|
29
|
+
rather than a live stream. The ``content`` is yielded once and remains
|
|
30
|
+
accessible as a public attribute.
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
def __init__(self, content: T) -> None:
|
|
34
|
+
self.content = content
|
|
35
|
+
self._consumed = False
|
|
36
|
+
|
|
37
|
+
def __next__(self) -> T:
|
|
38
|
+
if self._consumed:
|
|
39
|
+
raise StopIteration
|
|
40
|
+
self._consumed = True
|
|
41
|
+
return self.content
|
|
42
|
+
|
|
43
|
+
async def __anext__(self) -> T:
|
|
44
|
+
if self._consumed:
|
|
45
|
+
raise StopAsyncIteration
|
|
46
|
+
self._consumed = True
|
|
47
|
+
return self.content
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def map_sync_iterator(iterable: Iterable[T], fn: Callable[[T], U]) -> Iterator[U]:
|
|
51
|
+
"""Map ``fn`` over a synchronous iterable, yielding results lazily."""
|
|
52
|
+
for item in iterable:
|
|
53
|
+
yield fn(item)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
async def map_async_iterator(
|
|
57
|
+
async_iterable: AsyncIterable[T], fn: Callable[[T], U]
|
|
58
|
+
) -> AsyncIterator[U]:
|
|
59
|
+
"""Map ``fn`` over an asynchronous iterable, yielding results lazily."""
|
|
60
|
+
async for item in async_iterable:
|
|
61
|
+
yield fn(item)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def chain_sync_iterator(*iterables: Iterable[T]) -> Iterator[T]:
|
|
65
|
+
"""Yield items from each iterable in order."""
|
|
66
|
+
for iterable in iterables:
|
|
67
|
+
yield from iterable
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
async def chain_async_iterator(
|
|
71
|
+
prefix: Iterable[T], rest: AsyncIterable[T]
|
|
72
|
+
) -> AsyncIterator[T]:
|
|
73
|
+
"""Yield the synchronous ``prefix`` items, then the async ``rest`` items."""
|
|
74
|
+
for item in prefix:
|
|
75
|
+
yield item
|
|
76
|
+
async for item in rest:
|
|
77
|
+
yield item
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def ensure_async_iterator(value: AsyncIterator[T] | T) -> AnyIterator[T]:
|
|
81
|
+
"""Return ``value`` as an :class:`AnyIterator`.
|
|
82
|
+
|
|
83
|
+
An async iterator is returned unchanged; a single value is wrapped in a
|
|
84
|
+
fresh single-item async iterator.
|
|
85
|
+
"""
|
|
86
|
+
if isinstance(value, AsyncIterator):
|
|
87
|
+
return cast(AnyIterator[T], value)
|
|
88
|
+
|
|
89
|
+
return StaticAnyIterator(value)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def ensure_sync_iterator(value: Iterator[T] | T) -> AnyIterator[T]:
|
|
93
|
+
"""Return ``value`` as an :class:`AnyIterator`.
|
|
94
|
+
|
|
95
|
+
A sync iterator is returned unchanged; a single value is wrapped in a
|
|
96
|
+
fresh single-item sync iterator.
|
|
97
|
+
"""
|
|
98
|
+
if isinstance(value, Iterator):
|
|
99
|
+
return cast(AnyIterator[T], value)
|
|
100
|
+
|
|
101
|
+
return StaticAnyIterator(value)
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
__all__ = [
|
|
105
|
+
"AnyIterator",
|
|
106
|
+
"StaticAnyIterator",
|
|
107
|
+
"chain_async_iterator",
|
|
108
|
+
"chain_sync_iterator",
|
|
109
|
+
"ensure_async_iterator",
|
|
110
|
+
"ensure_sync_iterator",
|
|
111
|
+
"map_async_iterator",
|
|
112
|
+
"map_sync_iterator",
|
|
113
|
+
]
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
"""Generated from Smithy shape ``com.amazonaws.codegurusecurity#BatchGetFindings``."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
import zapros
|
|
9
|
+
from typing_extensions import Never
|
|
10
|
+
|
|
11
|
+
import capo_codeguru_security._auth._signers
|
|
12
|
+
import capo_codeguru_security._auth._sigv4
|
|
13
|
+
import capo_codeguru_security._protocol.eventstream
|
|
14
|
+
import capo_codeguru_security.errors.access_denied_exception
|
|
15
|
+
import capo_codeguru_security.errors.internal_server_exception
|
|
16
|
+
import capo_codeguru_security.errors.throttling_exception
|
|
17
|
+
import capo_codeguru_security.errors.validation_exception
|
|
18
|
+
import capo_codeguru_security.types.batch_get_findings_errors
|
|
19
|
+
import capo_codeguru_security.types.batch_get_findings_request
|
|
20
|
+
import capo_codeguru_security.types.batch_get_findings_response
|
|
21
|
+
import capo_codeguru_security.types.finding_identifiers
|
|
22
|
+
import capo_codeguru_security.types.findings
|
|
23
|
+
from capo_codeguru_security._protocol.errors import parse_error_metadata_json
|
|
24
|
+
from capo_codeguru_security._rule_engine._endpoint_rule_set import (
|
|
25
|
+
EndpointParams,
|
|
26
|
+
resolve,
|
|
27
|
+
)
|
|
28
|
+
from capo_codeguru_security._services._pipeline import (
|
|
29
|
+
AsyncOperationOptions,
|
|
30
|
+
OperationOptions,
|
|
31
|
+
)
|
|
32
|
+
from capo_codeguru_security.errors import UnknownServiceError
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def handle_error(response: zapros.Response) -> Never:
|
|
36
|
+
data = json.loads(response.read())
|
|
37
|
+
code, message = parse_error_metadata_json(response, data)
|
|
38
|
+
match code:
|
|
39
|
+
case "AccessDeniedException":
|
|
40
|
+
raise capo_codeguru_security.errors.access_denied_exception.AccessDeniedException.from_json(
|
|
41
|
+
data, message
|
|
42
|
+
)
|
|
43
|
+
case "InternalServerException":
|
|
44
|
+
raise capo_codeguru_security.errors.internal_server_exception.InternalServerException.from_json(
|
|
45
|
+
data, message
|
|
46
|
+
)
|
|
47
|
+
case "ThrottlingException":
|
|
48
|
+
raise capo_codeguru_security.errors.throttling_exception.ThrottlingException.from_json(
|
|
49
|
+
data, message
|
|
50
|
+
)
|
|
51
|
+
case "ValidationException":
|
|
52
|
+
raise capo_codeguru_security.errors.validation_exception.ValidationException.from_json(
|
|
53
|
+
data, message
|
|
54
|
+
)
|
|
55
|
+
case _:
|
|
56
|
+
raise UnknownServiceError(code=code, message=message, response=response)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def handle_response(
|
|
60
|
+
response: zapros.Response,
|
|
61
|
+
) -> capo_codeguru_security.types.batch_get_findings_response.BatchGetFindingsResponse:
|
|
62
|
+
out: capo_codeguru_security.types.batch_get_findings_response.BatchGetFindingsResponse = capo_codeguru_security.types.batch_get_findings_response.deserialize_json(
|
|
63
|
+
json.loads(response.read())
|
|
64
|
+
)
|
|
65
|
+
return out
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
async def async_handle_response(
|
|
69
|
+
response: zapros.Response,
|
|
70
|
+
) -> capo_codeguru_security.types.batch_get_findings_response.BatchGetFindingsResponse:
|
|
71
|
+
out: capo_codeguru_security.types.batch_get_findings_response.BatchGetFindingsResponse = capo_codeguru_security.types.batch_get_findings_response.deserialize_json(
|
|
72
|
+
json.loads(await response.aread())
|
|
73
|
+
)
|
|
74
|
+
return out
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def get_signer(
|
|
78
|
+
options: AsyncOperationOptions | OperationOptions,
|
|
79
|
+
auth_schemes: list[dict[str, Any]] | None = None,
|
|
80
|
+
) -> capo_codeguru_security._auth._signers.Signer | None:
|
|
81
|
+
name_to_schema = {s["name"]: s for s in (auth_schemes or [])} # noqa: F841
|
|
82
|
+
if (
|
|
83
|
+
options.credentials_provider is not None
|
|
84
|
+
and name_to_schema
|
|
85
|
+
and not name_to_schema.keys() & {"sigv4", "sigv4-s3express"}
|
|
86
|
+
):
|
|
87
|
+
raise RuntimeError(
|
|
88
|
+
"Endpoint requires an unsupported auth scheme: " + ", ".join(name_to_schema)
|
|
89
|
+
)
|
|
90
|
+
if options.credentials_provider is not None:
|
|
91
|
+
endpoint_scheme = name_to_schema.get("sigv4") or name_to_schema.get(
|
|
92
|
+
"sigv4-s3express"
|
|
93
|
+
)
|
|
94
|
+
if endpoint_scheme is not None or not name_to_schema:
|
|
95
|
+
sigv4_config = capo_codeguru_security._auth._sigv4.build_sigv4_auth_scheme(
|
|
96
|
+
"codeguru-security", options.region, endpoint_scheme
|
|
97
|
+
)
|
|
98
|
+
if sigv4_config is not None:
|
|
99
|
+
return capo_codeguru_security._auth._signers.SigV4Signer(
|
|
100
|
+
options.credentials_provider, auth_scheme=sigv4_config
|
|
101
|
+
)
|
|
102
|
+
raise RuntimeError("Auth was not resolved")
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def build_request(
|
|
106
|
+
options: OperationOptions | AsyncOperationOptions,
|
|
107
|
+
input_: capo_codeguru_security.types.batch_get_findings_request.BatchGetFindingsRequest,
|
|
108
|
+
) -> zapros.Request:
|
|
109
|
+
endpoint = resolve(
|
|
110
|
+
EndpointParams(
|
|
111
|
+
Region=options.region,
|
|
112
|
+
UseDualStack=options.use_dual_stack,
|
|
113
|
+
UseFIPS=options.use_fips,
|
|
114
|
+
Endpoint=options.endpoint,
|
|
115
|
+
)
|
|
116
|
+
) # noqa: F841
|
|
117
|
+
url = endpoint.url.rstrip("/") + "/batchGetFindings"
|
|
118
|
+
params: list[tuple[str, str]] = []
|
|
119
|
+
headers: dict[str, str] = {k: ", ".join(v) for k, v in endpoint.headers.items()}
|
|
120
|
+
body: bytes | None = json.dumps(
|
|
121
|
+
capo_codeguru_security.types.batch_get_findings_request.serialize_json(input_),
|
|
122
|
+
allow_nan=False,
|
|
123
|
+
).encode()
|
|
124
|
+
headers["content-type"] = "application/json"
|
|
125
|
+
signer = get_signer(options, auth_schemes=endpoint.properties.get("authSchemes"))
|
|
126
|
+
normalized_url = zapros.URL(url)
|
|
127
|
+
for k, v in params:
|
|
128
|
+
normalized_url.search_params.append(k, v)
|
|
129
|
+
return zapros.Request(
|
|
130
|
+
normalized_url, "POST", headers=headers, body=body, context={"signer": signer}
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def batch_get_findings(
|
|
135
|
+
options: OperationOptions,
|
|
136
|
+
input_: capo_codeguru_security.types.batch_get_findings_request.BatchGetFindingsRequest,
|
|
137
|
+
) -> tuple[
|
|
138
|
+
capo_codeguru_security.types.batch_get_findings_response.BatchGetFindingsResponse,
|
|
139
|
+
zapros.Response,
|
|
140
|
+
]:
|
|
141
|
+
response = options.client.handler.handle(build_request(options, input_))
|
|
142
|
+
try:
|
|
143
|
+
if response.status >= 300:
|
|
144
|
+
response.read()
|
|
145
|
+
handle_error(response)
|
|
146
|
+
return handle_response(response), response
|
|
147
|
+
except BaseException:
|
|
148
|
+
response.close()
|
|
149
|
+
raise
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
async def async_batch_get_findings(
|
|
153
|
+
options: AsyncOperationOptions,
|
|
154
|
+
input_: capo_codeguru_security.types.batch_get_findings_request.BatchGetFindingsRequest,
|
|
155
|
+
) -> tuple[
|
|
156
|
+
capo_codeguru_security.types.batch_get_findings_response.BatchGetFindingsResponse,
|
|
157
|
+
zapros.Response,
|
|
158
|
+
]:
|
|
159
|
+
response = await options.client.handler.ahandle(build_request(options, input_))
|
|
160
|
+
try:
|
|
161
|
+
if response.status >= 300:
|
|
162
|
+
await response.aread()
|
|
163
|
+
handle_error(response)
|
|
164
|
+
return await async_handle_response(response), response
|
|
165
|
+
except BaseException:
|
|
166
|
+
await response.aclose()
|
|
167
|
+
raise
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
"""Generated from Smithy shape ``com.amazonaws.codegurusecurity#CreateScan``."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
import zapros
|
|
9
|
+
from typing_extensions import Never
|
|
10
|
+
|
|
11
|
+
import capo_codeguru_security._auth._signers
|
|
12
|
+
import capo_codeguru_security._auth._sigv4
|
|
13
|
+
import capo_codeguru_security._protocol.eventstream
|
|
14
|
+
import capo_codeguru_security.errors.access_denied_exception
|
|
15
|
+
import capo_codeguru_security.errors.conflict_exception
|
|
16
|
+
import capo_codeguru_security.errors.internal_server_exception
|
|
17
|
+
import capo_codeguru_security.errors.resource_not_found_exception
|
|
18
|
+
import capo_codeguru_security.errors.throttling_exception
|
|
19
|
+
import capo_codeguru_security.errors.validation_exception
|
|
20
|
+
import capo_codeguru_security.types.analysis_type
|
|
21
|
+
import capo_codeguru_security.types.create_scan_request
|
|
22
|
+
import capo_codeguru_security.types.create_scan_response
|
|
23
|
+
import capo_codeguru_security.types.resource_id
|
|
24
|
+
import capo_codeguru_security.types.scan_state
|
|
25
|
+
import capo_codeguru_security.types.scan_type
|
|
26
|
+
import capo_codeguru_security.types.tag_map
|
|
27
|
+
from capo_codeguru_security._protocol.errors import parse_error_metadata_json
|
|
28
|
+
from capo_codeguru_security._rule_engine._endpoint_rule_set import (
|
|
29
|
+
EndpointParams,
|
|
30
|
+
resolve,
|
|
31
|
+
)
|
|
32
|
+
from capo_codeguru_security._services._pipeline import (
|
|
33
|
+
AsyncOperationOptions,
|
|
34
|
+
OperationOptions,
|
|
35
|
+
)
|
|
36
|
+
from capo_codeguru_security.errors import UnknownServiceError
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def handle_error(response: zapros.Response) -> Never:
|
|
40
|
+
data = json.loads(response.read())
|
|
41
|
+
code, message = parse_error_metadata_json(response, data)
|
|
42
|
+
match code:
|
|
43
|
+
case "AccessDeniedException":
|
|
44
|
+
raise capo_codeguru_security.errors.access_denied_exception.AccessDeniedException.from_json(
|
|
45
|
+
data, message
|
|
46
|
+
)
|
|
47
|
+
case "ConflictException":
|
|
48
|
+
raise capo_codeguru_security.errors.conflict_exception.ConflictException.from_json(
|
|
49
|
+
data, message
|
|
50
|
+
)
|
|
51
|
+
case "InternalServerException":
|
|
52
|
+
raise capo_codeguru_security.errors.internal_server_exception.InternalServerException.from_json(
|
|
53
|
+
data, message
|
|
54
|
+
)
|
|
55
|
+
case "ResourceNotFoundException":
|
|
56
|
+
raise capo_codeguru_security.errors.resource_not_found_exception.ResourceNotFoundException.from_json(
|
|
57
|
+
data, message
|
|
58
|
+
)
|
|
59
|
+
case "ThrottlingException":
|
|
60
|
+
raise capo_codeguru_security.errors.throttling_exception.ThrottlingException.from_json(
|
|
61
|
+
data, message
|
|
62
|
+
)
|
|
63
|
+
case "ValidationException":
|
|
64
|
+
raise capo_codeguru_security.errors.validation_exception.ValidationException.from_json(
|
|
65
|
+
data, message
|
|
66
|
+
)
|
|
67
|
+
case _:
|
|
68
|
+
raise UnknownServiceError(code=code, message=message, response=response)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def handle_response(
|
|
72
|
+
response: zapros.Response,
|
|
73
|
+
) -> capo_codeguru_security.types.create_scan_response.CreateScanResponse:
|
|
74
|
+
out: capo_codeguru_security.types.create_scan_response.CreateScanResponse = (
|
|
75
|
+
capo_codeguru_security.types.create_scan_response.deserialize_json(
|
|
76
|
+
json.loads(response.read())
|
|
77
|
+
)
|
|
78
|
+
)
|
|
79
|
+
return out
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
async def async_handle_response(
|
|
83
|
+
response: zapros.Response,
|
|
84
|
+
) -> capo_codeguru_security.types.create_scan_response.CreateScanResponse:
|
|
85
|
+
out: capo_codeguru_security.types.create_scan_response.CreateScanResponse = (
|
|
86
|
+
capo_codeguru_security.types.create_scan_response.deserialize_json(
|
|
87
|
+
json.loads(await response.aread())
|
|
88
|
+
)
|
|
89
|
+
)
|
|
90
|
+
return out
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def get_signer(
|
|
94
|
+
options: AsyncOperationOptions | OperationOptions,
|
|
95
|
+
auth_schemes: list[dict[str, Any]] | None = None,
|
|
96
|
+
) -> capo_codeguru_security._auth._signers.Signer | None:
|
|
97
|
+
name_to_schema = {s["name"]: s for s in (auth_schemes or [])} # noqa: F841
|
|
98
|
+
if (
|
|
99
|
+
options.credentials_provider is not None
|
|
100
|
+
and name_to_schema
|
|
101
|
+
and not name_to_schema.keys() & {"sigv4", "sigv4-s3express"}
|
|
102
|
+
):
|
|
103
|
+
raise RuntimeError(
|
|
104
|
+
"Endpoint requires an unsupported auth scheme: " + ", ".join(name_to_schema)
|
|
105
|
+
)
|
|
106
|
+
if options.credentials_provider is not None:
|
|
107
|
+
endpoint_scheme = name_to_schema.get("sigv4") or name_to_schema.get(
|
|
108
|
+
"sigv4-s3express"
|
|
109
|
+
)
|
|
110
|
+
if endpoint_scheme is not None or not name_to_schema:
|
|
111
|
+
sigv4_config = capo_codeguru_security._auth._sigv4.build_sigv4_auth_scheme(
|
|
112
|
+
"codeguru-security", options.region, endpoint_scheme
|
|
113
|
+
)
|
|
114
|
+
if sigv4_config is not None:
|
|
115
|
+
return capo_codeguru_security._auth._signers.SigV4Signer(
|
|
116
|
+
options.credentials_provider, auth_scheme=sigv4_config
|
|
117
|
+
)
|
|
118
|
+
raise RuntimeError("Auth was not resolved")
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def build_request(
|
|
122
|
+
options: OperationOptions | AsyncOperationOptions,
|
|
123
|
+
input_: capo_codeguru_security.types.create_scan_request.CreateScanRequest,
|
|
124
|
+
) -> zapros.Request:
|
|
125
|
+
endpoint = resolve(
|
|
126
|
+
EndpointParams(
|
|
127
|
+
Region=options.region,
|
|
128
|
+
UseDualStack=options.use_dual_stack,
|
|
129
|
+
UseFIPS=options.use_fips,
|
|
130
|
+
Endpoint=options.endpoint,
|
|
131
|
+
)
|
|
132
|
+
) # noqa: F841
|
|
133
|
+
url = endpoint.url.rstrip("/") + "/scans"
|
|
134
|
+
params: list[tuple[str, str]] = []
|
|
135
|
+
headers: dict[str, str] = {k: ", ".join(v) for k, v in endpoint.headers.items()}
|
|
136
|
+
body: bytes | None = json.dumps(
|
|
137
|
+
capo_codeguru_security.types.create_scan_request.serialize_json(input_),
|
|
138
|
+
allow_nan=False,
|
|
139
|
+
).encode()
|
|
140
|
+
headers["content-type"] = "application/json"
|
|
141
|
+
signer = get_signer(options, auth_schemes=endpoint.properties.get("authSchemes"))
|
|
142
|
+
normalized_url = zapros.URL(url)
|
|
143
|
+
for k, v in params:
|
|
144
|
+
normalized_url.search_params.append(k, v)
|
|
145
|
+
return zapros.Request(
|
|
146
|
+
normalized_url, "POST", headers=headers, body=body, context={"signer": signer}
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def create_scan(
|
|
151
|
+
options: OperationOptions,
|
|
152
|
+
input_: capo_codeguru_security.types.create_scan_request.CreateScanRequest,
|
|
153
|
+
) -> tuple[
|
|
154
|
+
capo_codeguru_security.types.create_scan_response.CreateScanResponse,
|
|
155
|
+
zapros.Response,
|
|
156
|
+
]:
|
|
157
|
+
response = options.client.handler.handle(build_request(options, input_))
|
|
158
|
+
try:
|
|
159
|
+
if response.status >= 300:
|
|
160
|
+
response.read()
|
|
161
|
+
handle_error(response)
|
|
162
|
+
return handle_response(response), response
|
|
163
|
+
except BaseException:
|
|
164
|
+
response.close()
|
|
165
|
+
raise
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
async def async_create_scan(
|
|
169
|
+
options: AsyncOperationOptions,
|
|
170
|
+
input_: capo_codeguru_security.types.create_scan_request.CreateScanRequest,
|
|
171
|
+
) -> tuple[
|
|
172
|
+
capo_codeguru_security.types.create_scan_response.CreateScanResponse,
|
|
173
|
+
zapros.Response,
|
|
174
|
+
]:
|
|
175
|
+
response = await options.client.handler.ahandle(build_request(options, input_))
|
|
176
|
+
try:
|
|
177
|
+
if response.status >= 300:
|
|
178
|
+
await response.aread()
|
|
179
|
+
handle_error(response)
|
|
180
|
+
return await async_handle_response(response), response
|
|
181
|
+
except BaseException:
|
|
182
|
+
await response.aclose()
|
|
183
|
+
raise
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"""Generated from Smithy shape ``com.amazonaws.codegurusecurity#CreateUploadUrl``."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
import zapros
|
|
9
|
+
from typing_extensions import Never
|
|
10
|
+
|
|
11
|
+
import capo_codeguru_security._auth._signers
|
|
12
|
+
import capo_codeguru_security._auth._sigv4
|
|
13
|
+
import capo_codeguru_security._protocol.eventstream
|
|
14
|
+
import capo_codeguru_security.errors.access_denied_exception
|
|
15
|
+
import capo_codeguru_security.errors.internal_server_exception
|
|
16
|
+
import capo_codeguru_security.errors.throttling_exception
|
|
17
|
+
import capo_codeguru_security.errors.validation_exception
|
|
18
|
+
import capo_codeguru_security.types.create_upload_url_request
|
|
19
|
+
import capo_codeguru_security.types.create_upload_url_response
|
|
20
|
+
import capo_codeguru_security.types.request_header_map
|
|
21
|
+
from capo_codeguru_security._protocol.errors import parse_error_metadata_json
|
|
22
|
+
from capo_codeguru_security._rule_engine._endpoint_rule_set import (
|
|
23
|
+
EndpointParams,
|
|
24
|
+
resolve,
|
|
25
|
+
)
|
|
26
|
+
from capo_codeguru_security._services._pipeline import (
|
|
27
|
+
AsyncOperationOptions,
|
|
28
|
+
OperationOptions,
|
|
29
|
+
)
|
|
30
|
+
from capo_codeguru_security.errors import UnknownServiceError
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def handle_error(response: zapros.Response) -> Never:
|
|
34
|
+
data = json.loads(response.read())
|
|
35
|
+
code, message = parse_error_metadata_json(response, data)
|
|
36
|
+
match code:
|
|
37
|
+
case "AccessDeniedException":
|
|
38
|
+
raise capo_codeguru_security.errors.access_denied_exception.AccessDeniedException.from_json(
|
|
39
|
+
data, message
|
|
40
|
+
)
|
|
41
|
+
case "InternalServerException":
|
|
42
|
+
raise capo_codeguru_security.errors.internal_server_exception.InternalServerException.from_json(
|
|
43
|
+
data, message
|
|
44
|
+
)
|
|
45
|
+
case "ThrottlingException":
|
|
46
|
+
raise capo_codeguru_security.errors.throttling_exception.ThrottlingException.from_json(
|
|
47
|
+
data, message
|
|
48
|
+
)
|
|
49
|
+
case "ValidationException":
|
|
50
|
+
raise capo_codeguru_security.errors.validation_exception.ValidationException.from_json(
|
|
51
|
+
data, message
|
|
52
|
+
)
|
|
53
|
+
case _:
|
|
54
|
+
raise UnknownServiceError(code=code, message=message, response=response)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def handle_response(
|
|
58
|
+
response: zapros.Response,
|
|
59
|
+
) -> capo_codeguru_security.types.create_upload_url_response.CreateUploadUrlResponse:
|
|
60
|
+
out: capo_codeguru_security.types.create_upload_url_response.CreateUploadUrlResponse = capo_codeguru_security.types.create_upload_url_response.deserialize_json(
|
|
61
|
+
json.loads(response.read())
|
|
62
|
+
)
|
|
63
|
+
return out
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
async def async_handle_response(
|
|
67
|
+
response: zapros.Response,
|
|
68
|
+
) -> capo_codeguru_security.types.create_upload_url_response.CreateUploadUrlResponse:
|
|
69
|
+
out: capo_codeguru_security.types.create_upload_url_response.CreateUploadUrlResponse = capo_codeguru_security.types.create_upload_url_response.deserialize_json(
|
|
70
|
+
json.loads(await response.aread())
|
|
71
|
+
)
|
|
72
|
+
return out
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def get_signer(
|
|
76
|
+
options: AsyncOperationOptions | OperationOptions,
|
|
77
|
+
auth_schemes: list[dict[str, Any]] | None = None,
|
|
78
|
+
) -> capo_codeguru_security._auth._signers.Signer | None:
|
|
79
|
+
name_to_schema = {s["name"]: s for s in (auth_schemes or [])} # noqa: F841
|
|
80
|
+
if (
|
|
81
|
+
options.credentials_provider is not None
|
|
82
|
+
and name_to_schema
|
|
83
|
+
and not name_to_schema.keys() & {"sigv4", "sigv4-s3express"}
|
|
84
|
+
):
|
|
85
|
+
raise RuntimeError(
|
|
86
|
+
"Endpoint requires an unsupported auth scheme: " + ", ".join(name_to_schema)
|
|
87
|
+
)
|
|
88
|
+
if options.credentials_provider is not None:
|
|
89
|
+
endpoint_scheme = name_to_schema.get("sigv4") or name_to_schema.get(
|
|
90
|
+
"sigv4-s3express"
|
|
91
|
+
)
|
|
92
|
+
if endpoint_scheme is not None or not name_to_schema:
|
|
93
|
+
sigv4_config = capo_codeguru_security._auth._sigv4.build_sigv4_auth_scheme(
|
|
94
|
+
"codeguru-security", options.region, endpoint_scheme
|
|
95
|
+
)
|
|
96
|
+
if sigv4_config is not None:
|
|
97
|
+
return capo_codeguru_security._auth._signers.SigV4Signer(
|
|
98
|
+
options.credentials_provider, auth_scheme=sigv4_config
|
|
99
|
+
)
|
|
100
|
+
raise RuntimeError("Auth was not resolved")
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def build_request(
|
|
104
|
+
options: OperationOptions | AsyncOperationOptions,
|
|
105
|
+
input_: capo_codeguru_security.types.create_upload_url_request.CreateUploadUrlRequest,
|
|
106
|
+
) -> zapros.Request:
|
|
107
|
+
endpoint = resolve(
|
|
108
|
+
EndpointParams(
|
|
109
|
+
Region=options.region,
|
|
110
|
+
UseDualStack=options.use_dual_stack,
|
|
111
|
+
UseFIPS=options.use_fips,
|
|
112
|
+
Endpoint=options.endpoint,
|
|
113
|
+
)
|
|
114
|
+
) # noqa: F841
|
|
115
|
+
url = endpoint.url.rstrip("/") + "/uploadUrl"
|
|
116
|
+
params: list[tuple[str, str]] = []
|
|
117
|
+
headers: dict[str, str] = {k: ", ".join(v) for k, v in endpoint.headers.items()}
|
|
118
|
+
body: bytes | None = json.dumps(
|
|
119
|
+
capo_codeguru_security.types.create_upload_url_request.serialize_json(input_),
|
|
120
|
+
allow_nan=False,
|
|
121
|
+
).encode()
|
|
122
|
+
headers["content-type"] = "application/json"
|
|
123
|
+
signer = get_signer(options, auth_schemes=endpoint.properties.get("authSchemes"))
|
|
124
|
+
normalized_url = zapros.URL(url)
|
|
125
|
+
for k, v in params:
|
|
126
|
+
normalized_url.search_params.append(k, v)
|
|
127
|
+
return zapros.Request(
|
|
128
|
+
normalized_url, "POST", headers=headers, body=body, context={"signer": signer}
|
|
129
|
+
)
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def create_upload_url(
|
|
133
|
+
options: OperationOptions,
|
|
134
|
+
input_: capo_codeguru_security.types.create_upload_url_request.CreateUploadUrlRequest,
|
|
135
|
+
) -> tuple[
|
|
136
|
+
capo_codeguru_security.types.create_upload_url_response.CreateUploadUrlResponse,
|
|
137
|
+
zapros.Response,
|
|
138
|
+
]:
|
|
139
|
+
response = options.client.handler.handle(build_request(options, input_))
|
|
140
|
+
try:
|
|
141
|
+
if response.status >= 300:
|
|
142
|
+
response.read()
|
|
143
|
+
handle_error(response)
|
|
144
|
+
return handle_response(response), response
|
|
145
|
+
except BaseException:
|
|
146
|
+
response.close()
|
|
147
|
+
raise
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
async def async_create_upload_url(
|
|
151
|
+
options: AsyncOperationOptions,
|
|
152
|
+
input_: capo_codeguru_security.types.create_upload_url_request.CreateUploadUrlRequest,
|
|
153
|
+
) -> tuple[
|
|
154
|
+
capo_codeguru_security.types.create_upload_url_response.CreateUploadUrlResponse,
|
|
155
|
+
zapros.Response,
|
|
156
|
+
]:
|
|
157
|
+
response = await options.client.handler.ahandle(build_request(options, input_))
|
|
158
|
+
try:
|
|
159
|
+
if response.status >= 300:
|
|
160
|
+
await response.aread()
|
|
161
|
+
handle_error(response)
|
|
162
|
+
return await async_handle_response(response), response
|
|
163
|
+
except BaseException:
|
|
164
|
+
await response.aclose()
|
|
165
|
+
raise
|