Skip to content

Commit

Permalink
fix: Polymorph Python
Browse files Browse the repository at this point in the history
  • Loading branch information
Shubham Chaturvedi committed Oct 28, 2024
1 parent 831aeea commit 18f0d48
Show file tree
Hide file tree
Showing 55 changed files with 5,351 additions and 17,123 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
# Do not modify this file. This file is machine generated, and any changes to it will be overwritten.

Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,15 @@
Input = TypeVar("Input")
Output = TypeVar("Output")


class KeyStore:
"""Client for KeyStore.
"""Client for KeyStore
:param config: Configuration for the client.
"""

def __init__(
self,
config: KeyStoreConfig | None = None,
dafny_client: IKeyStoreClient | None = None,
dafny_client: IKeyStoreClient | None = None
):
if config is None:
self._config = Config()
Expand Down Expand Up @@ -97,9 +95,7 @@ def get_key_store_info(self, input: Unit) -> GetKeyStoreInfoOutput:
)

def create_key_store(self, input: CreateKeyStoreInput) -> CreateKeyStoreOutput:
"""Create the DynamoDB table that backs this Key Store based on the Key
Store configuration. If a table already exists, validate it is
configured as expected.
"""Create the DynamoDB table that backs this Key Store based on the Key Store configuration. If a table already exists, validate it is configured as expected.
:param input: The operation's input.
"""
Expand All @@ -113,8 +109,7 @@ def create_key_store(self, input: CreateKeyStoreInput) -> CreateKeyStoreOutput:
)

def create_key(self, input: CreateKeyInput) -> CreateKeyOutput:
"""Create a new Branch Key in the Key Store. Additionally create a
Beacon Key that is tied to this Branch Key.
"""Create a new Branch Key in the Key Store. Additionally create a Beacon Key that is tied to this Branch Key.
:param input: The operation's input.
"""
Expand All @@ -128,8 +123,7 @@ def create_key(self, input: CreateKeyInput) -> CreateKeyOutput:
)

def version_key(self, input: VersionKeyInput) -> VersionKeyOutput:
"""Create a new ACTIVE version of an existing Branch Key in the Key
Store, and set the previously ACTIVE version to DECRYPT_ONLY.
"""Create a new ACTIVE version of an existing Branch Key in the Key Store, and set the previously ACTIVE version to DECRYPT_ONLY.
:param input: Inputs for versioning a Branch Key.
"""
Expand All @@ -142,11 +136,8 @@ def version_key(self, input: VersionKeyInput) -> VersionKeyOutput:
operation_name="VersionKey",
)

def get_active_branch_key(
self, input: GetActiveBranchKeyInput
) -> GetActiveBranchKeyOutput:
"""Get the ACTIVE version for a particular Branch Key from the Key
Store.
def get_active_branch_key(self, input: GetActiveBranchKeyInput) -> GetActiveBranchKeyOutput:
"""Get the ACTIVE version for a particular Branch Key from the Key Store.
:param input: Inputs for getting a Branch Key's ACTIVE version.
"""
Expand All @@ -159,9 +150,7 @@ def get_active_branch_key(
operation_name="GetActiveBranchKey",
)

def get_branch_key_version(
self, input: GetBranchKeyVersionInput
) -> GetBranchKeyVersionOutput:
def get_branch_key_version(self, input: GetBranchKeyVersionInput) -> GetBranchKeyVersionOutput:
"""Get a particular version of a Branch Key from the Key Store.
:param input: Inputs for getting a version of a Branch Key.
Expand Down Expand Up @@ -226,8 +215,7 @@ def _handle_execution(
)
_client_interceptors = config.interceptors
client_interceptors = cast(
list[Interceptor[Input, Output, DafnyRequest, DafnyResponse]],
_client_interceptors,
list[Interceptor[Input, Output, DafnyRequest, DafnyResponse]], _client_interceptors
)
interceptors = client_interceptors

Expand Down Expand Up @@ -310,7 +298,7 @@ def _handle_execution(
error_info=RetryErrorInfo(
# TODO: Determine the error type.
error_type=RetryErrorType.CLIENT_ERROR,
),
)
)
except SmithyRetryException:
raise context_with_response.response
Expand All @@ -325,10 +313,7 @@ def _handle_execution(
# The response will be set either with the modeled output or an exception. The
# transport_request and transport_response may be set or None.
execution_context = cast(
InterceptorContext[
Input, Output, DafnyRequest | None, DafnyResponse | None
],
context,
InterceptorContext[Input, Output, DafnyRequest | None, DafnyResponse | None], context
)
return self._finalize_execution(interceptors, execution_context)

Expand All @@ -353,10 +338,8 @@ def _handle_attempt(
InterceptorContext[Input, None, DafnyRequest, DafnyResponse], context
)

context_with_response._transport_response = (
config.dafnyImplInterface.handle_request(
input=context_with_response.transport_request
)
context_with_response._transport_response = config.dafnyImplInterface.handle_request(
input=context_with_response.transport_request
)

# Step 7n: Invoke read_after_transmit
Expand Down Expand Up @@ -393,8 +376,7 @@ def _handle_attempt(
# None. This will also be true after _finalize_attempt because there is no opportunity
# there to set the transport_response.
attempt_context = cast(
InterceptorContext[Input, Output, DafnyRequest, DafnyResponse | None],
context,
InterceptorContext[Input, Output, DafnyRequest, DafnyResponse | None], context
)
return self._finalize_attempt(interceptors, attempt_context)

Expand Down Expand Up @@ -424,9 +406,7 @@ def _finalize_attempt(
def _finalize_execution(
self,
interceptors: list[Interceptor[Input, Output, DafnyRequest, DafnyResponse]],
context: InterceptorContext[
Input, Output, DafnyRequest | None, DafnyResponse | None
],
context: InterceptorContext[Input, Output, DafnyRequest | None, DafnyResponse | None],
) -> Output:
try:
# Step 9: Invoke modify_before_completion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@


_ServiceInterceptor = Any


@dataclass(init=False)
class Config:
"""Configuration for KeyStore."""
Expand All @@ -39,21 +37,21 @@ def __init__(
):
"""Constructor.
:param interceptors: The list of interceptors, which are hooks
that are called during the execution of a request.
:param retry_strategy: The retry strategy for issuing retry
tokens and computing retry delays.
:param interceptors: The list of interceptors, which are hooks that are called
during the execution of a request.
:param retry_strategy: The retry strategy for issuing retry tokens and computing
retry delays.
:param dafnyImplInterface:
"""
self.interceptors = interceptors or []
self.retry_strategy = retry_strategy or SimpleRetryStrategy()
self.dafnyImplInterface = dafnyImplInterface


# A callable that allows customizing the config object on each request.
Plugin: TypeAlias = Callable[[Config], None]


class KeyStoreConfig(Config):
ddb_table_name: str
kms_configuration: KMSConfiguration
Expand All @@ -62,7 +60,6 @@ class KeyStoreConfig(Config):
grant_tokens: Optional[list[str]]
ddb_client: Optional[BaseClient]
kms_client: Optional[BaseClient]

def __init__(
self,
*,
Expand All @@ -74,7 +71,7 @@ def __init__(
ddb_client: Optional[BaseClient] = None,
kms_client: Optional[BaseClient] = None,
):
"""Constructor for KeyStoreConfig.
"""Constructor for KeyStoreConfig
:param ddb_table_name: The DynamoDB table name that backs this Key Store.
:param kms_configuration: Configures Key Store's KMS Key ARN restrictions.
Expand All @@ -93,14 +90,10 @@ def __init__(
"""
super().__init__()
if (ddb_table_name is not None) and (len(ddb_table_name) < 3):
raise ValueError(
"The size of ddb_table_name must be greater than or equal to 3"
)
raise ValueError("The size of ddb_table_name must be greater than or equal to 3")

if (ddb_table_name is not None) and (len(ddb_table_name) > 255):
raise ValueError(
"The size of ddb_table_name must be less than or equal to 255"
)
raise ValueError("The size of ddb_table_name must be less than or equal to 255")

self.ddb_table_name = ddb_table_name
self.kms_configuration = kms_configuration
Expand All @@ -111,7 +104,9 @@ def __init__(
self.kms_client = kms_client

def as_dict(self) -> Dict[str, Any]:
"""Converts the KeyStoreConfig to a dictionary."""
"""Converts the KeyStoreConfig to a dictionary.
"""
d: Dict[str, Any] = {
"ddb_table_name": self.ddb_table_name,
"kms_configuration": self.kms_configuration.as_dict(),
Expand All @@ -134,7 +129,9 @@ def as_dict(self) -> Dict[str, Any]:

@staticmethod
def from_dict(d: Dict[str, Any]) -> "KeyStoreConfig":
"""Creates a KeyStoreConfig from a dictionary."""
"""Creates a KeyStoreConfig from a dictionary.
"""
kwargs: Dict[str, Any] = {
"ddb_table_name": d["ddb_table_name"],
"kms_configuration": _kms_configuration_from_dict(d["kms_configuration"]),
Expand Down Expand Up @@ -183,29 +180,22 @@ def __repr__(self) -> str:
def __eq__(self, other: Any) -> bool:
if not isinstance(other, KeyStoreConfig):
return False
attributes: list[str] = [
"ddb_table_name",
"kms_configuration",
"logical_key_store_name",
"id",
"grant_tokens",
"ddb_client",
"kms_client",
]
return all(getattr(self, a) == getattr(other, a) for a in attributes)

attributes: list[str] = ['ddb_table_name','kms_configuration','logical_key_store_name','id','grant_tokens','ddb_client','kms_client',]
return all(
getattr(self, a) == getattr(other, a)
for a in attributes
)

def dafny_config_to_smithy_config(dafny_config) -> KeyStoreConfig:
"""Converts the provided Dafny shape for this localService's config into
the corresponding Smithy-modelled shape."""
return aws_cryptographic_material_providers.smithygenerated.aws_cryptography_keystore.dafny_to_smithy.aws_cryptography_keystore_KeyStoreConfig(
dafny_config
)

"""
Converts the provided Dafny shape for this localService's config
into the corresponding Smithy-modelled shape.
"""
return aws_cryptographic_material_providers.smithygenerated.aws_cryptography_keystore.dafny_to_smithy.aws_cryptography_keystore_KeyStoreConfig(dafny_config)

def smithy_config_to_dafny_config(smithy_config) -> DafnyKeyStoreConfig:
"""Converts the provided Smithy-modelled shape for this localService's
config into the corresponding Dafny shape."""
return aws_cryptographic_material_providers.smithygenerated.aws_cryptography_keystore.smithy_to_dafny.aws_cryptography_keystore_KeyStoreConfig(
smithy_config
)
"""
Converts the provided Smithy-modelled shape for this localService's config
into the corresponding Dafny shape.
"""
return aws_cryptographic_material_providers.smithygenerated.aws_cryptography_keystore.smithy_to_dafny.aws_cryptography_keystore_KeyStoreConfig(smithy_config)
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@
# SPDX-License-Identifier: Apache-2.0
# Do not modify this file. This file is machine generated, and any changes to it will be overwritten.

from aws_cryptographic_material_providers.internaldafny.generated.KeyStore import (
KeyStoreClient,
)
from aws_cryptographic_material_providers.internaldafny.generated.KeyStore import KeyStoreClient
from .dafny_protocol import DafnyRequest


class DafnyImplInterface:
impl: KeyStoreClient | None = None

Expand All @@ -30,9 +27,9 @@ def handle_request(self, input: DafnyRequest):
"GetBeaconKey": self.impl.GetBeaconKey,
}

# This logic is where a typical Smithy client would expect the "server" to be.
# This code can be thought of as logic our Dafny "server" uses
# to route incoming client requests to the correct request handler code.
# This logic is where a typical Smithy client would expect the "server" to be.
# This code can be thought of as logic our Dafny "server" uses
# to route incoming client requests to the correct request handler code.
if input.dafny_operation_input is None:
return self.operation_map[input.operation_name]()
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import smithy_dafny_standard_library.internaldafny.generated.Wrappers as Wrappers
from typing import Union


class DafnyRequest:
operation_name: str

Expand All @@ -36,7 +35,6 @@ def __init__(self, operation_name, dafny_operation_input):
self.operation_name = operation_name
self.dafny_operation_input = dafny_operation_input


class DafnyResponse(Wrappers.Result):
def __init__(self):
super().__init__(self)
Loading

0 comments on commit 18f0d48

Please sign in to comment.