capo-codeartifact 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_codeartifact/__init__.py +72 -0
- capo_codeartifact/_async.py +25 -0
- capo_codeartifact/_auth/_identity.py +16 -0
- capo_codeartifact/_auth/_providers.py +886 -0
- capo_codeartifact/_auth/_signers.py +88 -0
- capo_codeartifact/_auth/_sigv4.py +434 -0
- capo_codeartifact/_auth/_zapros_handler.py +80 -0
- capo_codeartifact/_iter.py +113 -0
- capo_codeartifact/_operations/code_artifact_control_plane_service/associate_external_connection.py +181 -0
- capo_codeartifact/_operations/code_artifact_control_plane_service/copy_package_versions.py +202 -0
- capo_codeartifact/_operations/code_artifact_control_plane_service/create_domain.py +182 -0
- capo_codeartifact/_operations/code_artifact_control_plane_service/create_package_group.py +182 -0
- capo_codeartifact/_operations/code_artifact_control_plane_service/create_repository.py +189 -0
- capo_codeartifact/_operations/code_artifact_control_plane_service/delete_domain.py +169 -0
- capo_codeartifact/_operations/code_artifact_control_plane_service/delete_domain_permissions_policy.py +174 -0
- capo_codeartifact/_operations/code_artifact_control_plane_service/delete_package.py +190 -0
- capo_codeartifact/_operations/code_artifact_control_plane_service/delete_package_group.py +179 -0
- capo_codeartifact/_operations/code_artifact_control_plane_service/delete_package_versions.py +195 -0
- capo_codeartifact/_operations/code_artifact_control_plane_service/delete_repository.py +178 -0
- capo_codeartifact/_operations/code_artifact_control_plane_service/delete_repository_permissions_policy.py +176 -0
- capo_codeartifact/_operations/code_artifact_control_plane_service/describe_domain.py +169 -0
- capo_codeartifact/_operations/code_artifact_control_plane_service/describe_package.py +187 -0
- capo_codeartifact/_operations/code_artifact_control_plane_service/describe_package_group.py +169 -0
- capo_codeartifact/_operations/code_artifact_control_plane_service/describe_package_version.py +194 -0
- capo_codeartifact/_operations/code_artifact_control_plane_service/describe_repository.py +173 -0
- capo_codeartifact/_operations/code_artifact_control_plane_service/disassociate_external_connection.py +181 -0
- capo_codeartifact/_operations/code_artifact_control_plane_service/dispose_package_versions.py +200 -0
- capo_codeartifact/_operations/code_artifact_control_plane_service/get_associated_package_group.py +177 -0
- capo_codeartifact/_operations/code_artifact_control_plane_service/get_authorization_token.py +169 -0
- capo_codeartifact/_operations/code_artifact_control_plane_service/get_domain_permissions_policy.py +167 -0
- capo_codeartifact/_operations/code_artifact_control_plane_service/get_package_version_asset.py +208 -0
- capo_codeartifact/_operations/code_artifact_control_plane_service/get_package_version_readme.py +184 -0
- capo_codeartifact/_operations/code_artifact_control_plane_service/get_repository_endpoint.py +189 -0
- capo_codeartifact/_operations/code_artifact_control_plane_service/get_repository_permissions_policy.py +169 -0
- capo_codeartifact/_operations/code_artifact_control_plane_service/list_allowed_repositories_for_group.py +190 -0
- capo_codeartifact/_operations/code_artifact_control_plane_service/list_associated_packages.py +174 -0
- capo_codeartifact/_operations/code_artifact_control_plane_service/list_domains.py +164 -0
- capo_codeartifact/_operations/code_artifact_control_plane_service/list_package_groups.py +177 -0
- capo_codeartifact/_operations/code_artifact_control_plane_service/list_package_version_assets.py +189 -0
- capo_codeartifact/_operations/code_artifact_control_plane_service/list_package_version_dependencies.py +187 -0
- capo_codeartifact/_operations/code_artifact_control_plane_service/list_package_versions.py +220 -0
- capo_codeartifact/_operations/code_artifact_control_plane_service/list_packages.py +209 -0
- capo_codeartifact/_operations/code_artifact_control_plane_service/list_repositories.py +168 -0
- capo_codeartifact/_operations/code_artifact_control_plane_service/list_repositories_in_domain.py +175 -0
- capo_codeartifact/_operations/code_artifact_control_plane_service/list_sub_package_groups.py +173 -0
- capo_codeartifact/_operations/code_artifact_control_plane_service/list_tags_for_resource.py +160 -0
- capo_codeartifact/_operations/code_artifact_control_plane_service/publish_package_version.py +209 -0
- capo_codeartifact/_operations/code_artifact_control_plane_service/put_domain_permissions_policy.py +179 -0
- capo_codeartifact/_operations/code_artifact_control_plane_service/put_package_origin_configuration.py +190 -0
- capo_codeartifact/_operations/code_artifact_control_plane_service/put_repository_permissions_policy.py +185 -0
- capo_codeartifact/_operations/code_artifact_control_plane_service/tag_resource.py +163 -0
- capo_codeartifact/_operations/code_artifact_control_plane_service/untag_resource.py +158 -0
- capo_codeartifact/_operations/code_artifact_control_plane_service/update_package_group.py +176 -0
- capo_codeartifact/_operations/code_artifact_control_plane_service/update_package_group_origin_configuration.py +183 -0
- capo_codeartifact/_operations/code_artifact_control_plane_service/update_package_versions_status.py +198 -0
- capo_codeartifact/_operations/code_artifact_control_plane_service/update_repository.py +188 -0
- capo_codeartifact/_pagination.py +21 -0
- capo_codeartifact/_protocol/__init__.py +1 -0
- capo_codeartifact/_protocol/errors.py +93 -0
- capo_codeartifact/_protocol/eventstream.py +238 -0
- capo_codeartifact/_protocol/serialize.py +47 -0
- capo_codeartifact/_protocol/xml.py +33 -0
- capo_codeartifact/_rule_engine/__init__.py +0 -0
- capo_codeartifact/_rule_engine/_aws_partition.py +160 -0
- capo_codeartifact/_rule_engine/_endpoint_rule_set.py +138 -0
- capo_codeartifact/_rule_engine/_endpoint_runtime.py +389 -0
- capo_codeartifact/_services/_aws_config.py +160 -0
- capo_codeartifact/_services/_pipeline.py +198 -0
- capo_codeartifact/_services/async_codeartifact.py +3870 -0
- capo_codeartifact/_services/codeartifact.py +3822 -0
- capo_codeartifact/errors/__init__.py +36 -0
- capo_codeartifact/errors/_base.py +94 -0
- capo_codeartifact/errors/access_denied_exception.py +52 -0
- capo_codeartifact/errors/conflict_exception.py +71 -0
- capo_codeartifact/errors/internal_server_exception.py +52 -0
- capo_codeartifact/errors/resource_not_found_exception.py +73 -0
- capo_codeartifact/errors/service_quota_exceeded_exception.py +75 -0
- capo_codeartifact/errors/throttling_exception.py +55 -0
- capo_codeartifact/errors/validation_exception.py +71 -0
- capo_codeartifact/py.typed +0 -0
- capo_codeartifact/types/_prelude/blob.py +12 -0
- capo_codeartifact/types/_prelude/timestamp.py +17 -0
- capo_codeartifact/types/account_id.py +5 -0
- capo_codeartifact/types/allow_publish.py +17 -0
- capo_codeartifact/types/allow_upstream.py +17 -0
- capo_codeartifact/types/arn.py +5 -0
- capo_codeartifact/types/asset.py +7 -0
- capo_codeartifact/types/asset_hashes.py +33 -0
- capo_codeartifact/types/asset_name.py +5 -0
- capo_codeartifact/types/asset_summary.py +53 -0
- capo_codeartifact/types/asset_summary_list.py +29 -0
- capo_codeartifact/types/associate_external_connection_request.py +35 -0
- capo_codeartifact/types/associate_external_connection_result.py +42 -0
- capo_codeartifact/types/associated_package.py +71 -0
- capo_codeartifact/types/associated_package_list.py +31 -0
- capo_codeartifact/types/authorization_token_duration_seconds.py +5 -0
- capo_codeartifact/types/boolean_optional.py +5 -0
- capo_codeartifact/types/copy_package_versions_request.py +96 -0
- capo_codeartifact/types/copy_package_versions_result.py +63 -0
- capo_codeartifact/types/create_domain_request.py +42 -0
- capo_codeartifact/types/create_domain_result.py +36 -0
- capo_codeartifact/types/create_package_group_request.py +64 -0
- capo_codeartifact/types/create_package_group_result.py +42 -0
- capo_codeartifact/types/create_repository_request.py +69 -0
- capo_codeartifact/types/create_repository_result.py +42 -0
- capo_codeartifact/types/delete_domain_permissions_policy_request.py +32 -0
- capo_codeartifact/types/delete_domain_permissions_policy_result.py +36 -0
- capo_codeartifact/types/delete_domain_request.py +27 -0
- capo_codeartifact/types/delete_domain_result.py +36 -0
- capo_codeartifact/types/delete_package_group_request.py +30 -0
- capo_codeartifact/types/delete_package_group_result.py +42 -0
- capo_codeartifact/types/delete_package_request.py +39 -0
- capo_codeartifact/types/delete_package_result.py +39 -0
- capo_codeartifact/types/delete_package_versions_request.py +78 -0
- capo_codeartifact/types/delete_package_versions_result.py +63 -0
- capo_codeartifact/types/delete_repository_permissions_policy_request.py +35 -0
- capo_codeartifact/types/delete_repository_permissions_policy_result.py +36 -0
- capo_codeartifact/types/delete_repository_request.py +30 -0
- capo_codeartifact/types/delete_repository_result.py +42 -0
- capo_codeartifact/types/describe_domain_request.py +27 -0
- capo_codeartifact/types/describe_domain_result.py +35 -0
- capo_codeartifact/types/describe_package_group_request.py +30 -0
- capo_codeartifact/types/describe_package_group_result.py +42 -0
- capo_codeartifact/types/describe_package_request.py +39 -0
- capo_codeartifact/types/describe_package_result.py +39 -0
- capo_codeartifact/types/describe_package_version_request.py +42 -0
- capo_codeartifact/types/describe_package_version_result.py +47 -0
- capo_codeartifact/types/describe_repository_request.py +30 -0
- capo_codeartifact/types/describe_repository_result.py +42 -0
- capo_codeartifact/types/description.py +5 -0
- capo_codeartifact/types/disassociate_external_connection_request.py +35 -0
- capo_codeartifact/types/disassociate_external_connection_result.py +42 -0
- capo_codeartifact/types/dispose_package_versions_request.py +99 -0
- capo_codeartifact/types/dispose_package_versions_result.py +63 -0
- capo_codeartifact/types/domain_description.py +100 -0
- capo_codeartifact/types/domain_entry_point.py +39 -0
- capo_codeartifact/types/domain_name.py +5 -0
- capo_codeartifact/types/domain_status.py +17 -0
- capo_codeartifact/types/domain_summary.py +78 -0
- capo_codeartifact/types/domain_summary_list.py +31 -0
- capo_codeartifact/types/endpoint_type.py +17 -0
- capo_codeartifact/types/error_message.py +5 -0
- capo_codeartifact/types/external_connection_name.py +5 -0
- capo_codeartifact/types/external_connection_status.py +14 -0
- capo_codeartifact/types/get_associated_package_group_request.py +36 -0
- capo_codeartifact/types/get_associated_package_group_result.py +63 -0
- capo_codeartifact/types/get_authorization_token_request.py +32 -0
- capo_codeartifact/types/get_authorization_token_result.py +43 -0
- capo_codeartifact/types/get_domain_permissions_policy_request.py +27 -0
- capo_codeartifact/types/get_domain_permissions_policy_result.py +36 -0
- capo_codeartifact/types/get_package_version_asset_request.py +50 -0
- capo_codeartifact/types/get_package_version_asset_result.py +26 -0
- capo_codeartifact/types/get_package_version_readme_request.py +42 -0
- capo_codeartifact/types/get_package_version_readme_result.py +73 -0
- capo_codeartifact/types/get_repository_endpoint_request.py +36 -0
- capo_codeartifact/types/get_repository_endpoint_result.py +28 -0
- capo_codeartifact/types/get_repository_permissions_policy_request.py +30 -0
- capo_codeartifact/types/get_repository_permissions_policy_result.py +36 -0
- capo_codeartifact/types/hash_algorithm.py +19 -0
- capo_codeartifact/types/hash_value.py +5 -0
- capo_codeartifact/types/integer.py +5 -0
- capo_codeartifact/types/license_info.py +34 -0
- capo_codeartifact/types/license_info_list.py +29 -0
- capo_codeartifact/types/list_allowed_repositories_for_group_max_results.py +5 -0
- capo_codeartifact/types/list_allowed_repositories_for_group_request.py +41 -0
- capo_codeartifact/types/list_allowed_repositories_for_group_result.py +49 -0
- capo_codeartifact/types/list_associated_packages_request.py +41 -0
- capo_codeartifact/types/list_associated_packages_result.py +49 -0
- capo_codeartifact/types/list_domains_max_results.py +5 -0
- capo_codeartifact/types/list_domains_request.py +37 -0
- capo_codeartifact/types/list_domains_result.py +45 -0
- capo_codeartifact/types/list_package_groups_max_results.py +5 -0
- capo_codeartifact/types/list_package_groups_request.py +40 -0
- capo_codeartifact/types/list_package_groups_result.py +49 -0
- capo_codeartifact/types/list_package_version_assets_max_results.py +5 -0
- capo_codeartifact/types/list_package_version_assets_request.py +50 -0
- capo_codeartifact/types/list_package_version_assets_result.py +88 -0
- capo_codeartifact/types/list_package_version_dependencies_request.py +45 -0
- capo_codeartifact/types/list_package_version_dependencies_result.py +94 -0
- capo_codeartifact/types/list_package_versions_max_results.py +5 -0
- capo_codeartifact/types/list_package_versions_request.py +62 -0
- capo_codeartifact/types/list_package_versions_result.py +87 -0
- capo_codeartifact/types/list_packages_max_results.py +5 -0
- capo_codeartifact/types/list_packages_request.py +53 -0
- capo_codeartifact/types/list_packages_result.py +45 -0
- capo_codeartifact/types/list_repositories_in_domain_max_results.py +5 -0
- capo_codeartifact/types/list_repositories_in_domain_request.py +42 -0
- capo_codeartifact/types/list_repositories_in_domain_result.py +49 -0
- capo_codeartifact/types/list_repositories_max_results.py +5 -0
- capo_codeartifact/types/list_repositories_request.py +34 -0
- capo_codeartifact/types/list_repositories_result.py +49 -0
- capo_codeartifact/types/list_sub_package_groups_request.py +38 -0
- capo_codeartifact/types/list_sub_package_groups_result.py +49 -0
- capo_codeartifact/types/list_tags_for_resource_request.py +24 -0
- capo_codeartifact/types/list_tags_for_resource_result.py +32 -0
- capo_codeartifact/types/long.py +5 -0
- capo_codeartifact/types/long_optional.py +5 -0
- capo_codeartifact/types/origin_restrictions.py +48 -0
- capo_codeartifact/types/package_dependency.py +48 -0
- capo_codeartifact/types/package_dependency_list.py +31 -0
- capo_codeartifact/types/package_description.py +71 -0
- capo_codeartifact/types/package_format.py +23 -0
- capo_codeartifact/types/package_group_allowed_repository.py +51 -0
- capo_codeartifact/types/package_group_allowed_repository_list.py +39 -0
- capo_codeartifact/types/package_group_allowed_repository_update.py +44 -0
- capo_codeartifact/types/package_group_allowed_repository_update_type.py +17 -0
- capo_codeartifact/types/package_group_allowed_repository_updates.py +48 -0
- capo_codeartifact/types/package_group_association_type.py +17 -0
- capo_codeartifact/types/package_group_contact_info.py +5 -0
- capo_codeartifact/types/package_group_description.py +122 -0
- capo_codeartifact/types/package_group_origin_configuration.py +42 -0
- capo_codeartifact/types/package_group_origin_restriction.py +92 -0
- capo_codeartifact/types/package_group_origin_restriction_mode.py +19 -0
- capo_codeartifact/types/package_group_origin_restriction_type.py +18 -0
- capo_codeartifact/types/package_group_origin_restrictions.py +48 -0
- capo_codeartifact/types/package_group_pattern.py +5 -0
- capo_codeartifact/types/package_group_pattern_prefix.py +5 -0
- capo_codeartifact/types/package_group_reference.py +37 -0
- capo_codeartifact/types/package_group_summary.py +122 -0
- capo_codeartifact/types/package_group_summary_list.py +31 -0
- capo_codeartifact/types/package_name.py +5 -0
- capo_codeartifact/types/package_namespace.py +5 -0
- capo_codeartifact/types/package_origin_configuration.py +42 -0
- capo_codeartifact/types/package_origin_restrictions.py +55 -0
- capo_codeartifact/types/package_summary.py +71 -0
- capo_codeartifact/types/package_summary_list.py +31 -0
- capo_codeartifact/types/package_version.py +5 -0
- capo_codeartifact/types/package_version_description.py +156 -0
- capo_codeartifact/types/package_version_error.py +49 -0
- capo_codeartifact/types/package_version_error_code.py +21 -0
- capo_codeartifact/types/package_version_error_map.py +33 -0
- capo_codeartifact/types/package_version_list.py +19 -0
- capo_codeartifact/types/package_version_origin.py +63 -0
- capo_codeartifact/types/package_version_origin_type.py +18 -0
- capo_codeartifact/types/package_version_revision.py +5 -0
- capo_codeartifact/types/package_version_revision_map.py +29 -0
- capo_codeartifact/types/package_version_sort_type.py +14 -0
- capo_codeartifact/types/package_version_status.py +21 -0
- capo_codeartifact/types/package_version_summary.py +73 -0
- capo_codeartifact/types/package_version_summary_list.py +33 -0
- capo_codeartifact/types/pagination_token.py +5 -0
- capo_codeartifact/types/policy_document.py +5 -0
- capo_codeartifact/types/policy_revision.py +5 -0
- capo_codeartifact/types/publish_package_version_request.py +43 -0
- capo_codeartifact/types/publish_package_version_result.py +98 -0
- capo_codeartifact/types/put_domain_permissions_policy_request.py +57 -0
- capo_codeartifact/types/put_domain_permissions_policy_result.py +36 -0
- capo_codeartifact/types/put_package_origin_configuration_request.py +65 -0
- capo_codeartifact/types/put_package_origin_configuration_result.py +42 -0
- capo_codeartifact/types/put_repository_permissions_policy_request.py +51 -0
- capo_codeartifact/types/put_repository_permissions_policy_result.py +36 -0
- capo_codeartifact/types/repository_description.py +119 -0
- capo_codeartifact/types/repository_external_connection_info.py +66 -0
- capo_codeartifact/types/repository_external_connection_info_list.py +39 -0
- capo_codeartifact/types/repository_name.py +5 -0
- capo_codeartifact/types/repository_name_list.py +19 -0
- capo_codeartifact/types/repository_summary.py +77 -0
- capo_codeartifact/types/repository_summary_list.py +31 -0
- capo_codeartifact/types/resource_policy.py +42 -0
- capo_codeartifact/types/resource_type.py +20 -0
- capo_codeartifact/types/retry_after_seconds.py +5 -0
- capo_codeartifact/types/sha256.py +5 -0
- capo_codeartifact/types/string.py +5 -0
- capo_codeartifact/types/string255.py +5 -0
- capo_codeartifact/types/successful_package_version_info.py +45 -0
- capo_codeartifact/types/successful_package_version_info_map.py +41 -0
- capo_codeartifact/types/tag.py +39 -0
- capo_codeartifact/types/tag_key.py +5 -0
- capo_codeartifact/types/tag_key_list.py +17 -0
- capo_codeartifact/types/tag_list.py +29 -0
- capo_codeartifact/types/tag_resource_request.py +38 -0
- capo_codeartifact/types/tag_resource_result.py +18 -0
- capo_codeartifact/types/tag_value.py +5 -0
- capo_codeartifact/types/timestamp.py +20 -0
- capo_codeartifact/types/untag_resource_request.py +42 -0
- capo_codeartifact/types/untag_resource_result.py +18 -0
- capo_codeartifact/types/update_package_group_origin_configuration_request.py +92 -0
- capo_codeartifact/types/update_package_group_origin_configuration_result.py +63 -0
- capo_codeartifact/types/update_package_group_request.py +53 -0
- capo_codeartifact/types/update_package_group_result.py +42 -0
- capo_codeartifact/types/update_package_versions_status_request.py +120 -0
- capo_codeartifact/types/update_package_versions_status_result.py +63 -0
- capo_codeartifact/types/update_repository_request.py +58 -0
- capo_codeartifact/types/update_repository_result.py +42 -0
- capo_codeartifact/types/upstream_repository.py +31 -0
- capo_codeartifact/types/upstream_repository_info.py +30 -0
- capo_codeartifact/types/upstream_repository_info_list.py +35 -0
- capo_codeartifact/types/upstream_repository_list.py +31 -0
- capo_codeartifact/types/validation_exception_reason.py +20 -0
- capo_codeartifact-0.1.0.dist-info/METADATA +139 -0
- capo_codeartifact-0.1.0.dist-info/RECORD +294 -0
- capo_codeartifact-0.1.0.dist-info/WHEEL +5 -0
- capo_codeartifact-0.1.0.dist-info/licenses/LICENSE +21 -0
- capo_codeartifact-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
"""Shared Amazon eventstream binary-format runtime.
|
|
2
|
+
|
|
3
|
+
Hand-written, not regenerated. Provides framing, header encoding, and
|
|
4
|
+
checksum validation for Smithy event-stream messages.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import datetime
|
|
10
|
+
import uuid
|
|
11
|
+
import zlib
|
|
12
|
+
from collections.abc import AsyncIterator, Callable, Iterator
|
|
13
|
+
from dataclasses import dataclass, field
|
|
14
|
+
from typing import TypeVar, Union
|
|
15
|
+
|
|
16
|
+
HeaderValue = Union[bool, int, bytes, str, datetime.datetime, uuid.UUID]
|
|
17
|
+
T = TypeVar("T")
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
# Header type constants from the Amazon eventstream specification.
|
|
21
|
+
_TRUE_HEADER = 0x00
|
|
22
|
+
_FALSE_HEADER = 0x01
|
|
23
|
+
_BYTE_HEADER = 0x02
|
|
24
|
+
_SHORT_HEADER = 0x03
|
|
25
|
+
_INTEGER_HEADER = 0x04
|
|
26
|
+
_LONG_HEADER = 0x05
|
|
27
|
+
_BYTE_ARRAY_HEADER = 0x06
|
|
28
|
+
_STRING_HEADER = 0x07
|
|
29
|
+
_TIMESTAMP_HEADER = 0x08
|
|
30
|
+
_UUID_HEADER = 0x09
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def _encode_header_value(value: HeaderValue) -> bytes:
|
|
34
|
+
if isinstance(value, bool):
|
|
35
|
+
return bytes([_TRUE_HEADER if value else _FALSE_HEADER])
|
|
36
|
+
if isinstance(value, int):
|
|
37
|
+
if -128 <= value <= 127:
|
|
38
|
+
return bytes([_BYTE_HEADER]) + value.to_bytes(1, "big", signed=True)
|
|
39
|
+
if -32768 <= value <= 32767:
|
|
40
|
+
return bytes([_SHORT_HEADER]) + value.to_bytes(2, "big", signed=True)
|
|
41
|
+
if -2147483648 <= value <= 2147483647:
|
|
42
|
+
return bytes([_INTEGER_HEADER]) + value.to_bytes(4, "big", signed=True)
|
|
43
|
+
# Fall through to signed 64-bit.
|
|
44
|
+
return bytes([_LONG_HEADER]) + value.to_bytes(8, "big", signed=True)
|
|
45
|
+
if isinstance(value, bytes):
|
|
46
|
+
return bytes([_BYTE_ARRAY_HEADER]) + len(value).to_bytes(2, "big") + value
|
|
47
|
+
if isinstance(value, str):
|
|
48
|
+
encoded = value.encode("utf-8")
|
|
49
|
+
return bytes([_STRING_HEADER]) + len(encoded).to_bytes(2, "big") + encoded
|
|
50
|
+
if isinstance(value, datetime.datetime):
|
|
51
|
+
millis = int(value.timestamp() * 1000)
|
|
52
|
+
return bytes([_TIMESTAMP_HEADER]) + millis.to_bytes(8, "big", signed=True)
|
|
53
|
+
if isinstance(value, uuid.UUID):
|
|
54
|
+
return bytes([_UUID_HEADER]) + value.bytes
|
|
55
|
+
raise TypeError(f"unsupported eventstream header value: {value!r}")
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def _decode_header_value(
|
|
59
|
+
type_byte: int, data: bytes | bytearray, pos: int
|
|
60
|
+
) -> tuple[HeaderValue, int]:
|
|
61
|
+
if type_byte == _TRUE_HEADER:
|
|
62
|
+
return True, pos
|
|
63
|
+
if type_byte == _FALSE_HEADER:
|
|
64
|
+
return False, pos
|
|
65
|
+
if type_byte == _BYTE_HEADER:
|
|
66
|
+
return int.from_bytes(data[pos : pos + 1], "big", signed=True), pos + 1
|
|
67
|
+
if type_byte == _SHORT_HEADER:
|
|
68
|
+
return int.from_bytes(data[pos : pos + 2], "big", signed=True), pos + 2
|
|
69
|
+
if type_byte == _INTEGER_HEADER:
|
|
70
|
+
return int.from_bytes(data[pos : pos + 4], "big", signed=True), pos + 4
|
|
71
|
+
if type_byte == _LONG_HEADER:
|
|
72
|
+
return int.from_bytes(data[pos : pos + 8], "big", signed=True), pos + 8
|
|
73
|
+
if type_byte == _BYTE_ARRAY_HEADER:
|
|
74
|
+
length = int.from_bytes(data[pos : pos + 2], "big")
|
|
75
|
+
pos += 2
|
|
76
|
+
return bytes(data[pos : pos + length]), pos + length
|
|
77
|
+
if type_byte == _STRING_HEADER:
|
|
78
|
+
length = int.from_bytes(data[pos : pos + 2], "big")
|
|
79
|
+
pos += 2
|
|
80
|
+
return data[pos : pos + length].decode("utf-8"), pos + length
|
|
81
|
+
if type_byte == _TIMESTAMP_HEADER:
|
|
82
|
+
millis = int.from_bytes(data[pos : pos + 8], "big", signed=True)
|
|
83
|
+
return (
|
|
84
|
+
datetime.datetime.fromtimestamp(millis / 1000, tz=datetime.timezone.utc),
|
|
85
|
+
pos + 8,
|
|
86
|
+
)
|
|
87
|
+
if type_byte == _UUID_HEADER:
|
|
88
|
+
return uuid.UUID(bytes=bytes(data[pos : pos + 16])), pos + 16
|
|
89
|
+
raise ValueError(f"unsupported eventstream header type: {type_byte:#x}")
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def _encode_headers(headers: dict[str, HeaderValue]) -> bytes:
|
|
93
|
+
parts: list[bytes] = []
|
|
94
|
+
for name, value in headers.items():
|
|
95
|
+
name_bytes = name.encode("utf-8")
|
|
96
|
+
if len(name_bytes) > 255:
|
|
97
|
+
raise ValueError(f"eventstream header name too long: {name!r}")
|
|
98
|
+
parts.append(bytes([len(name_bytes)]) + name_bytes)
|
|
99
|
+
parts.append(_encode_header_value(value))
|
|
100
|
+
return b"".join(parts)
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def _decode_headers(data: bytes | bytearray) -> dict[str, HeaderValue]:
|
|
104
|
+
pos = 0
|
|
105
|
+
headers: dict[str, HeaderValue] = {}
|
|
106
|
+
while pos < len(data):
|
|
107
|
+
name_len = data[pos]
|
|
108
|
+
pos += 1
|
|
109
|
+
name = data[pos : pos + name_len].decode("utf-8")
|
|
110
|
+
pos += name_len
|
|
111
|
+
type_byte = data[pos]
|
|
112
|
+
pos += 1
|
|
113
|
+
value, pos = _decode_header_value(type_byte, data, pos)
|
|
114
|
+
headers[name] = value
|
|
115
|
+
return headers
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
@dataclass
|
|
119
|
+
class Message:
|
|
120
|
+
"""A single Amazon eventstream message."""
|
|
121
|
+
|
|
122
|
+
headers: dict[str, HeaderValue] = field(default_factory=dict)
|
|
123
|
+
payload: bytes = b""
|
|
124
|
+
|
|
125
|
+
def encode(self) -> bytes:
|
|
126
|
+
"""Serialize this message into eventstream framing bytes."""
|
|
127
|
+
headers_bytes = _encode_headers(self.headers)
|
|
128
|
+
headers_length = len(headers_bytes)
|
|
129
|
+
payload = self.payload
|
|
130
|
+
total_length = 12 + headers_length + len(payload)
|
|
131
|
+
|
|
132
|
+
prelude = total_length.to_bytes(4, "big") + headers_length.to_bytes(4, "big")
|
|
133
|
+
prelude_crc = zlib.crc32(prelude).to_bytes(4, "big")
|
|
134
|
+
message_body = prelude + prelude_crc + headers_bytes + payload
|
|
135
|
+
message_crc = zlib.crc32(message_body).to_bytes(4, "big")
|
|
136
|
+
return message_body + message_crc
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
@dataclass
|
|
140
|
+
class MessageDecoder:
|
|
141
|
+
"""Stateful decoder that turns byte chunks into :class:`Message` objects.
|
|
142
|
+
|
|
143
|
+
``feed`` may emit zero, one, or many messages for each chunk. Partial
|
|
144
|
+
frames are buffered until the next chunk completes them.
|
|
145
|
+
"""
|
|
146
|
+
|
|
147
|
+
_buffer: bytearray = field(default_factory=bytearray, init=False)
|
|
148
|
+
|
|
149
|
+
def feed(self, data: bytes) -> Iterator[Message]:
|
|
150
|
+
"""Append ``data`` to the internal buffer and yield any full messages."""
|
|
151
|
+
self._buffer.extend(data)
|
|
152
|
+
while True:
|
|
153
|
+
if len(self._buffer) < 12:
|
|
154
|
+
return
|
|
155
|
+
|
|
156
|
+
total_length = int.from_bytes(self._buffer[:4], "big")
|
|
157
|
+
headers_length = int.from_bytes(self._buffer[4:8], "big")
|
|
158
|
+
prelude = bytes(self._buffer[:8])
|
|
159
|
+
prelude_crc = int.from_bytes(self._buffer[8:12], "big")
|
|
160
|
+
|
|
161
|
+
if total_length < 12 + headers_length:
|
|
162
|
+
raise ValueError(
|
|
163
|
+
f"invalid eventstream message: total_length={total_length} "
|
|
164
|
+
f"is smaller than minimum {12 + headers_length}"
|
|
165
|
+
)
|
|
166
|
+
|
|
167
|
+
message_end = total_length + 4
|
|
168
|
+
if len(self._buffer) < message_end:
|
|
169
|
+
return
|
|
170
|
+
|
|
171
|
+
computed_prelude_crc = zlib.crc32(prelude) & 0xFFFFFFFF
|
|
172
|
+
if computed_prelude_crc != prelude_crc:
|
|
173
|
+
raise ValueError("eventstream prelude checksum mismatch")
|
|
174
|
+
|
|
175
|
+
message_bytes = bytes(self._buffer[:total_length])
|
|
176
|
+
message_crc = int.from_bytes(
|
|
177
|
+
self._buffer[total_length : total_length + 4], "big"
|
|
178
|
+
)
|
|
179
|
+
computed_message_crc = zlib.crc32(message_bytes) & 0xFFFFFFFF
|
|
180
|
+
if computed_message_crc != message_crc:
|
|
181
|
+
raise ValueError("eventstream message checksum mismatch")
|
|
182
|
+
|
|
183
|
+
headers = _decode_headers(self._buffer[12 : 12 + headers_length])
|
|
184
|
+
payload = bytes(self._buffer[12 + headers_length : total_length])
|
|
185
|
+
del self._buffer[:message_end]
|
|
186
|
+
yield Message(headers=headers, payload=payload)
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
def raw_stream_to_events(
|
|
190
|
+
raw_stream: Iterator[bytes], decoder: MessageDecoder, deser: Callable[[Message], T]
|
|
191
|
+
) -> Iterator[T]:
|
|
192
|
+
"""Map a raw byte iterator into deserialized event objects."""
|
|
193
|
+
for chunk in raw_stream:
|
|
194
|
+
for message in decoder.feed(chunk):
|
|
195
|
+
yield deser(message)
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
async def async_raw_stream_to_events(
|
|
199
|
+
raw_stream: AsyncIterator[bytes],
|
|
200
|
+
decoder: MessageDecoder,
|
|
201
|
+
deser: Callable[[Message], T],
|
|
202
|
+
) -> AsyncIterator[T]:
|
|
203
|
+
"""Map an async raw byte iterator into deserialized event objects."""
|
|
204
|
+
async for chunk in raw_stream:
|
|
205
|
+
for message in decoder.feed(chunk):
|
|
206
|
+
yield deser(message)
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
def read_messages(
|
|
210
|
+
raw_stream: Iterator[bytes], decoder: MessageDecoder
|
|
211
|
+
) -> Iterator[Message]:
|
|
212
|
+
"""Yield :class:`Message` objects framed out of a raw byte iterator.
|
|
213
|
+
|
|
214
|
+
Used by RPC event streams (e.g. awsJson) where the first message may be an
|
|
215
|
+
initial-response that must be pulled off before consuming the events.
|
|
216
|
+
"""
|
|
217
|
+
for chunk in raw_stream:
|
|
218
|
+
yield from decoder.feed(chunk)
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
async def async_read_messages(
|
|
222
|
+
raw_stream: AsyncIterator[bytes], decoder: MessageDecoder
|
|
223
|
+
) -> AsyncIterator[Message]:
|
|
224
|
+
"""Async variant of :func:`read_messages`."""
|
|
225
|
+
async for chunk in raw_stream:
|
|
226
|
+
for message in decoder.feed(chunk):
|
|
227
|
+
yield message
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
__all__ = [
|
|
231
|
+
"HeaderValue",
|
|
232
|
+
"Message",
|
|
233
|
+
"MessageDecoder",
|
|
234
|
+
"async_raw_stream_to_events",
|
|
235
|
+
"async_read_messages",
|
|
236
|
+
"raw_stream_to_events",
|
|
237
|
+
"read_messages",
|
|
238
|
+
]
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"""Shared request-binding serialization runtime.
|
|
2
|
+
|
|
3
|
+
Hand-written, not regenerated. Text encodings for values bound to HTTP
|
|
4
|
+
labels, query parameters, and headers by the generated operations.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import base64
|
|
10
|
+
import datetime
|
|
11
|
+
from email.utils import format_datetime
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def as_utc(value: datetime.datetime) -> datetime.datetime:
|
|
15
|
+
"""Normalize to an aware UTC datetime; naive values are taken as UTC."""
|
|
16
|
+
if value.tzinfo is None:
|
|
17
|
+
return value.replace(tzinfo=datetime.timezone.utc)
|
|
18
|
+
return value.astimezone(datetime.timezone.utc)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def fmt_date_time(value: datetime.datetime) -> str:
|
|
22
|
+
"""RFC 3339 with a ``Z`` designator, e.g. ``2015-01-25T08:00:00Z``."""
|
|
23
|
+
return as_utc(value).isoformat().replace("+00:00", "Z")
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def fmt_http_date(value: datetime.datetime) -> str:
|
|
27
|
+
"""IMF-fixdate, e.g. ``Sun, 25 Jan 2015 08:00:00 GMT``."""
|
|
28
|
+
return format_datetime(as_utc(value), usegmt=True)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def fmt_epoch_seconds(value: datetime.datetime) -> str:
|
|
32
|
+
"""Seconds since the epoch; whole seconds carry no ``.0`` suffix."""
|
|
33
|
+
ts = as_utc(value).timestamp()
|
|
34
|
+
return str(int(ts)) if ts == int(ts) else str(ts)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def b64(value: bytes) -> str:
|
|
38
|
+
return base64.b64encode(value).decode("ascii")
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
__all__ = [
|
|
42
|
+
"as_utc",
|
|
43
|
+
"b64",
|
|
44
|
+
"fmt_date_time",
|
|
45
|
+
"fmt_epoch_seconds",
|
|
46
|
+
"fmt_http_date",
|
|
47
|
+
]
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"""Shared XML protocol runtime.
|
|
2
|
+
|
|
3
|
+
Hand-written, not regenerated. Holds re-exports of
|
|
4
|
+
``xml.etree.ElementTree`` primitives generated code depends on.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from xml.etree.ElementTree import Element, SubElement, tostring
|
|
8
|
+
from xml.etree.ElementTree import fromstring as _fromstring
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def fromstring(text: str | bytes) -> Element:
|
|
12
|
+
"""Parse XML and strip namespaces so generated ``el.find("Tag")`` and
|
|
13
|
+
``el.get("attr")`` lookups match. AWS restXml responses use a default
|
|
14
|
+
namespace which ElementTree otherwise qualifies onto every tag as
|
|
15
|
+
``{ns}Tag``; prefixed attributes (e.g. ``xsi:type``) get the same
|
|
16
|
+
treatment on their keys."""
|
|
17
|
+
root = _fromstring(text)
|
|
18
|
+
for el in root.iter():
|
|
19
|
+
if el.tag.startswith("{"):
|
|
20
|
+
el.tag = el.tag.rpartition("}")[2]
|
|
21
|
+
if any(key.startswith("{") for key in el.attrib):
|
|
22
|
+
el.attrib = {
|
|
23
|
+
key.rpartition("}")[2]: value for key, value in el.attrib.items()
|
|
24
|
+
}
|
|
25
|
+
return root
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
__all__ = [
|
|
29
|
+
"Element",
|
|
30
|
+
"SubElement",
|
|
31
|
+
"fromstring",
|
|
32
|
+
"tostring",
|
|
33
|
+
]
|
|
File without changes
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"""AWS partitions table and ``aws.partition`` rules-engine function.
|
|
2
|
+
|
|
3
|
+
Data sourced from AWS SDK ``partitions.json``. All dispatch tables are
|
|
4
|
+
materialised at codegen time:
|
|
5
|
+
|
|
6
|
+
* ``_REGION_LOOKUP`` — O(1) dict of explicit region name -> partition outputs.
|
|
7
|
+
* ``_REGEX_LOOKUP`` — compiled-regex / outputs pairs for unknown regions.
|
|
8
|
+
* ``_DEFAULT_OUTPUTS`` — fallback partition (``aws``)."""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import re
|
|
13
|
+
from typing import Any
|
|
14
|
+
|
|
15
|
+
_PARTITION_AWS: dict[str, Any] = {
|
|
16
|
+
"dnsSuffix": "amazonaws.com",
|
|
17
|
+
"dualStackDnsSuffix": "api.aws",
|
|
18
|
+
"implicitGlobalRegion": "us-east-1",
|
|
19
|
+
"name": "aws",
|
|
20
|
+
"supportsDualStack": True,
|
|
21
|
+
"supportsFIPS": True,
|
|
22
|
+
}
|
|
23
|
+
_PARTITION_AWS_CN: dict[str, Any] = {
|
|
24
|
+
"dnsSuffix": "amazonaws.com.cn",
|
|
25
|
+
"dualStackDnsSuffix": "api.amazonwebservices.com.cn",
|
|
26
|
+
"implicitGlobalRegion": "cn-northwest-1",
|
|
27
|
+
"name": "aws-cn",
|
|
28
|
+
"supportsDualStack": True,
|
|
29
|
+
"supportsFIPS": True,
|
|
30
|
+
}
|
|
31
|
+
_PARTITION_AWS_EUSC: dict[str, Any] = {
|
|
32
|
+
"dnsSuffix": "amazonaws.eu",
|
|
33
|
+
"dualStackDnsSuffix": "api.amazonwebservices.eu",
|
|
34
|
+
"implicitGlobalRegion": "eusc-de-east-1",
|
|
35
|
+
"name": "aws-eusc",
|
|
36
|
+
"supportsDualStack": True,
|
|
37
|
+
"supportsFIPS": True,
|
|
38
|
+
}
|
|
39
|
+
_PARTITION_AWS_ISO: dict[str, Any] = {
|
|
40
|
+
"dnsSuffix": "c2s.ic.gov",
|
|
41
|
+
"dualStackDnsSuffix": "api.aws.ic.gov",
|
|
42
|
+
"implicitGlobalRegion": "us-iso-east-1",
|
|
43
|
+
"name": "aws-iso",
|
|
44
|
+
"supportsDualStack": True,
|
|
45
|
+
"supportsFIPS": True,
|
|
46
|
+
}
|
|
47
|
+
_PARTITION_AWS_ISO_B: dict[str, Any] = {
|
|
48
|
+
"dnsSuffix": "sc2s.sgov.gov",
|
|
49
|
+
"dualStackDnsSuffix": "api.aws.scloud",
|
|
50
|
+
"implicitGlobalRegion": "us-isob-east-1",
|
|
51
|
+
"name": "aws-iso-b",
|
|
52
|
+
"supportsDualStack": True,
|
|
53
|
+
"supportsFIPS": True,
|
|
54
|
+
}
|
|
55
|
+
_PARTITION_AWS_ISO_E: dict[str, Any] = {
|
|
56
|
+
"dnsSuffix": "cloud.adc-e.uk",
|
|
57
|
+
"dualStackDnsSuffix": "api.cloud-aws.adc-e.uk",
|
|
58
|
+
"implicitGlobalRegion": "eu-isoe-west-1",
|
|
59
|
+
"name": "aws-iso-e",
|
|
60
|
+
"supportsDualStack": True,
|
|
61
|
+
"supportsFIPS": True,
|
|
62
|
+
}
|
|
63
|
+
_PARTITION_AWS_ISO_F: dict[str, Any] = {
|
|
64
|
+
"dnsSuffix": "csp.hci.ic.gov",
|
|
65
|
+
"dualStackDnsSuffix": "api.aws.hci.ic.gov",
|
|
66
|
+
"implicitGlobalRegion": "us-isof-south-1",
|
|
67
|
+
"name": "aws-iso-f",
|
|
68
|
+
"supportsDualStack": True,
|
|
69
|
+
"supportsFIPS": True,
|
|
70
|
+
}
|
|
71
|
+
_PARTITION_AWS_US_GOV: dict[str, Any] = {
|
|
72
|
+
"dnsSuffix": "amazonaws.com",
|
|
73
|
+
"dualStackDnsSuffix": "api.aws",
|
|
74
|
+
"implicitGlobalRegion": "us-gov-west-1",
|
|
75
|
+
"name": "aws-us-gov",
|
|
76
|
+
"supportsDualStack": True,
|
|
77
|
+
"supportsFIPS": True,
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
_REGION_LOOKUP: dict[str, dict[str, Any]] = {
|
|
81
|
+
"af-south-1": _PARTITION_AWS,
|
|
82
|
+
"ap-east-1": _PARTITION_AWS,
|
|
83
|
+
"ap-east-2": _PARTITION_AWS,
|
|
84
|
+
"ap-northeast-1": _PARTITION_AWS,
|
|
85
|
+
"ap-northeast-2": _PARTITION_AWS,
|
|
86
|
+
"ap-northeast-3": _PARTITION_AWS,
|
|
87
|
+
"ap-south-1": _PARTITION_AWS,
|
|
88
|
+
"ap-south-2": _PARTITION_AWS,
|
|
89
|
+
"ap-southeast-1": _PARTITION_AWS,
|
|
90
|
+
"ap-southeast-2": _PARTITION_AWS,
|
|
91
|
+
"ap-southeast-3": _PARTITION_AWS,
|
|
92
|
+
"ap-southeast-4": _PARTITION_AWS,
|
|
93
|
+
"ap-southeast-5": _PARTITION_AWS,
|
|
94
|
+
"ap-southeast-6": _PARTITION_AWS,
|
|
95
|
+
"ap-southeast-7": _PARTITION_AWS,
|
|
96
|
+
"aws-global": _PARTITION_AWS,
|
|
97
|
+
"ca-central-1": _PARTITION_AWS,
|
|
98
|
+
"ca-west-1": _PARTITION_AWS,
|
|
99
|
+
"eu-central-1": _PARTITION_AWS,
|
|
100
|
+
"eu-central-2": _PARTITION_AWS,
|
|
101
|
+
"eu-north-1": _PARTITION_AWS,
|
|
102
|
+
"eu-south-1": _PARTITION_AWS,
|
|
103
|
+
"eu-south-2": _PARTITION_AWS,
|
|
104
|
+
"eu-west-1": _PARTITION_AWS,
|
|
105
|
+
"eu-west-2": _PARTITION_AWS,
|
|
106
|
+
"eu-west-3": _PARTITION_AWS,
|
|
107
|
+
"il-central-1": _PARTITION_AWS,
|
|
108
|
+
"me-central-1": _PARTITION_AWS,
|
|
109
|
+
"me-south-1": _PARTITION_AWS,
|
|
110
|
+
"mx-central-1": _PARTITION_AWS,
|
|
111
|
+
"sa-east-1": _PARTITION_AWS,
|
|
112
|
+
"us-east-1": _PARTITION_AWS,
|
|
113
|
+
"us-east-2": _PARTITION_AWS,
|
|
114
|
+
"us-west-1": _PARTITION_AWS,
|
|
115
|
+
"us-west-2": _PARTITION_AWS,
|
|
116
|
+
"aws-cn-global": _PARTITION_AWS_CN,
|
|
117
|
+
"cn-north-1": _PARTITION_AWS_CN,
|
|
118
|
+
"cn-northwest-1": _PARTITION_AWS_CN,
|
|
119
|
+
"eusc-de-east-1": _PARTITION_AWS_EUSC,
|
|
120
|
+
"aws-iso-global": _PARTITION_AWS_ISO,
|
|
121
|
+
"us-iso-east-1": _PARTITION_AWS_ISO,
|
|
122
|
+
"us-iso-west-1": _PARTITION_AWS_ISO,
|
|
123
|
+
"aws-iso-b-global": _PARTITION_AWS_ISO_B,
|
|
124
|
+
"us-isob-east-1": _PARTITION_AWS_ISO_B,
|
|
125
|
+
"us-isob-west-1": _PARTITION_AWS_ISO_B,
|
|
126
|
+
"aws-iso-e-global": _PARTITION_AWS_ISO_E,
|
|
127
|
+
"eu-isoe-west-1": _PARTITION_AWS_ISO_E,
|
|
128
|
+
"aws-iso-f-global": _PARTITION_AWS_ISO_F,
|
|
129
|
+
"us-isof-east-1": _PARTITION_AWS_ISO_F,
|
|
130
|
+
"us-isof-south-1": _PARTITION_AWS_ISO_F,
|
|
131
|
+
"aws-us-gov-global": _PARTITION_AWS_US_GOV,
|
|
132
|
+
"us-gov-east-1": _PARTITION_AWS_US_GOV,
|
|
133
|
+
"us-gov-west-1": _PARTITION_AWS_US_GOV,
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
_REGEX_LOOKUP: tuple[tuple[re.Pattern[str], dict[str, Any]], ...] = (
|
|
137
|
+
(re.compile(r"^(us|eu|ap|sa|ca|me|af|il|mx)\-\w+\-\d+$"), _PARTITION_AWS),
|
|
138
|
+
(re.compile(r"^cn\-\w+\-\d+$"), _PARTITION_AWS_CN),
|
|
139
|
+
(re.compile(r"^eusc\-(de)\-\w+\-\d+$"), _PARTITION_AWS_EUSC),
|
|
140
|
+
(re.compile(r"^us\-iso\-\w+\-\d+$"), _PARTITION_AWS_ISO),
|
|
141
|
+
(re.compile(r"^us\-isob\-\w+\-\d+$"), _PARTITION_AWS_ISO_B),
|
|
142
|
+
(re.compile(r"^eu\-isoe\-\w+\-\d+$"), _PARTITION_AWS_ISO_E),
|
|
143
|
+
(re.compile(r"^us\-isof\-\w+\-\d+$"), _PARTITION_AWS_ISO_F),
|
|
144
|
+
(re.compile(r"^us\-gov\-\w+\-\d+$"), _PARTITION_AWS_US_GOV),
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
_DEFAULT_OUTPUTS: dict[str, Any] = _PARTITION_AWS
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def aws_partition(region: Any) -> dict[str, Any] | None:
|
|
151
|
+
"""Resolve ``region`` to a partition outputs dict."""
|
|
152
|
+
if not isinstance(region, str):
|
|
153
|
+
return None
|
|
154
|
+
outputs = _REGION_LOOKUP.get(region)
|
|
155
|
+
if outputs is not None:
|
|
156
|
+
return outputs
|
|
157
|
+
for pattern, outputs in _REGEX_LOOKUP:
|
|
158
|
+
if pattern.fullmatch(region):
|
|
159
|
+
return outputs
|
|
160
|
+
return _DEFAULT_OUTPUTS
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
from ._aws_partition import aws_partition
|
|
6
|
+
from ._endpoint_runtime import (
|
|
7
|
+
Endpoint,
|
|
8
|
+
EndpointError,
|
|
9
|
+
get_attr,
|
|
10
|
+
interpolate,
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class EndpointParams:
|
|
15
|
+
def __init__(
|
|
16
|
+
self,
|
|
17
|
+
*,
|
|
18
|
+
UseDualStack: bool | None = None,
|
|
19
|
+
UseFIPS: bool | None = None,
|
|
20
|
+
Region: str | None = None,
|
|
21
|
+
Endpoint: str | None = None,
|
|
22
|
+
):
|
|
23
|
+
self.UseDualStack = UseDualStack if UseDualStack is not None else False
|
|
24
|
+
self.UseFIPS = UseFIPS if UseFIPS is not None else False
|
|
25
|
+
self.Region = Region if Region is not None else None
|
|
26
|
+
self.Endpoint = Endpoint if Endpoint is not None else None
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def resolve(p: EndpointParams) -> Endpoint: # type: ignore
|
|
30
|
+
"""Resolve endpoint from parameters using generated ruleset."""
|
|
31
|
+
_locals: dict[str, Any] = {}
|
|
32
|
+
if p.Endpoint is not None:
|
|
33
|
+
if p.UseFIPS is True:
|
|
34
|
+
raise EndpointError(
|
|
35
|
+
interpolate(
|
|
36
|
+
"Invalid Configuration: FIPS and custom endpoint are not supported",
|
|
37
|
+
p,
|
|
38
|
+
_locals,
|
|
39
|
+
)
|
|
40
|
+
)
|
|
41
|
+
if p.UseDualStack is True:
|
|
42
|
+
raise EndpointError(
|
|
43
|
+
interpolate(
|
|
44
|
+
"Invalid Configuration: Dualstack and custom endpoint are not supported",
|
|
45
|
+
p,
|
|
46
|
+
_locals,
|
|
47
|
+
)
|
|
48
|
+
)
|
|
49
|
+
return Endpoint(url=p.Endpoint, properties={}, headers={})
|
|
50
|
+
_locals: dict[str, Any] = {}
|
|
51
|
+
if p.Region is not None:
|
|
52
|
+
_locals["PartitionResult"] = aws_partition(p.Region)
|
|
53
|
+
if _locals["PartitionResult"] is not None:
|
|
54
|
+
if p.UseFIPS is True:
|
|
55
|
+
if p.UseDualStack is True:
|
|
56
|
+
if True is get_attr(
|
|
57
|
+
_locals["PartitionResult"],
|
|
58
|
+
interpolate("supportsFIPS", p, _locals),
|
|
59
|
+
):
|
|
60
|
+
if True is get_attr(
|
|
61
|
+
_locals["PartitionResult"],
|
|
62
|
+
interpolate("supportsDualStack", p, _locals),
|
|
63
|
+
):
|
|
64
|
+
return Endpoint(
|
|
65
|
+
url=interpolate(
|
|
66
|
+
"https://codeartifact-fips.{Region}.{PartitionResult#dualStackDnsSuffix}",
|
|
67
|
+
p,
|
|
68
|
+
_locals,
|
|
69
|
+
),
|
|
70
|
+
properties={},
|
|
71
|
+
headers={},
|
|
72
|
+
)
|
|
73
|
+
raise EndpointError(
|
|
74
|
+
interpolate(
|
|
75
|
+
"FIPS and DualStack are enabled, but this partition does not support one or both",
|
|
76
|
+
p,
|
|
77
|
+
_locals,
|
|
78
|
+
)
|
|
79
|
+
)
|
|
80
|
+
if p.UseFIPS is True:
|
|
81
|
+
if (
|
|
82
|
+
get_attr(
|
|
83
|
+
_locals["PartitionResult"],
|
|
84
|
+
interpolate("supportsFIPS", p, _locals),
|
|
85
|
+
)
|
|
86
|
+
is True
|
|
87
|
+
):
|
|
88
|
+
return Endpoint(
|
|
89
|
+
url=interpolate(
|
|
90
|
+
"https://codeartifact-fips.{Region}.{PartitionResult#dnsSuffix}",
|
|
91
|
+
p,
|
|
92
|
+
_locals,
|
|
93
|
+
),
|
|
94
|
+
properties={},
|
|
95
|
+
headers={},
|
|
96
|
+
)
|
|
97
|
+
raise EndpointError(
|
|
98
|
+
interpolate(
|
|
99
|
+
"FIPS is enabled but this partition does not support FIPS",
|
|
100
|
+
p,
|
|
101
|
+
_locals,
|
|
102
|
+
)
|
|
103
|
+
)
|
|
104
|
+
if p.UseDualStack is True:
|
|
105
|
+
if True is get_attr(
|
|
106
|
+
_locals["PartitionResult"],
|
|
107
|
+
interpolate("supportsDualStack", p, _locals),
|
|
108
|
+
):
|
|
109
|
+
return Endpoint(
|
|
110
|
+
url=interpolate(
|
|
111
|
+
"https://codeartifact.{Region}.{PartitionResult#dualStackDnsSuffix}",
|
|
112
|
+
p,
|
|
113
|
+
_locals,
|
|
114
|
+
),
|
|
115
|
+
properties={},
|
|
116
|
+
headers={},
|
|
117
|
+
)
|
|
118
|
+
raise EndpointError(
|
|
119
|
+
interpolate(
|
|
120
|
+
"DualStack is enabled but this partition does not support DualStack",
|
|
121
|
+
p,
|
|
122
|
+
_locals,
|
|
123
|
+
)
|
|
124
|
+
)
|
|
125
|
+
return Endpoint(
|
|
126
|
+
url=interpolate(
|
|
127
|
+
"https://codeartifact.{Region}.{PartitionResult#dnsSuffix}",
|
|
128
|
+
p,
|
|
129
|
+
_locals,
|
|
130
|
+
),
|
|
131
|
+
properties={},
|
|
132
|
+
headers={},
|
|
133
|
+
)
|
|
134
|
+
_locals: dict[str, Any] = {}
|
|
135
|
+
raise EndpointError(
|
|
136
|
+
interpolate("Invalid Configuration: Missing Region", p, _locals)
|
|
137
|
+
)
|
|
138
|
+
raise EndpointError("No endpoint rules matched")
|