Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Python): Repolymorph to add orphaned shapes #831

Merged
merged 13 commits into from
Oct 11, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
import aws_cryptographic_materialproviders.smithygenerated.aws_cryptography_keystore.dafny_to_smithy
import aws_cryptographic_materialproviders.smithygenerated.aws_cryptography_keystore.smithy_to_dafny
from dataclasses import dataclass
from typing import Any, Callable, Optional, TypeAlias
from typing import Any, Callable, Dict, Optional, TypeAlias

from .dafnyImplInterface import DafnyImplInterface
from botocore.client import BaseClient
from smithy_python._private.retries import SimpleRetryStrategy
from smithy_python.interfaces.retries import RetryStrategy

from .models import KMSConfiguration
from .models import KMSConfiguration, _kms_configuration_from_dict


_ServiceInterceptor = Any
Expand Down Expand Up @@ -55,8 +55,6 @@ def __init__(


class KeyStoreConfig(Config):
"""Smithy-modelled localService Config shape for this localService."""

ddb_table_name: str
kms_configuration: KMSConfiguration
logical_key_store_name: str
Expand All @@ -67,6 +65,7 @@ class KeyStoreConfig(Config):

def __init__(
self,
*,
ddb_table_name: str,
kms_configuration: KMSConfiguration,
logical_key_store_name: str,
Expand All @@ -93,6 +92,16 @@ def __init__(
the default client.
"""
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"
)

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"
)

self.ddb_table_name = ddb_table_name
self.kms_configuration = kms_configuration
self.logical_key_store_name = logical_key_store_name
Expand All @@ -101,6 +110,90 @@ def __init__(
self.ddb_client = ddb_client
self.kms_client = kms_client

def as_dict(self) -> Dict[str, Any]:
"""Converts the KeyStoreConfig to a dictionary."""
d: Dict[str, Any] = {
"ddb_table_name": self.ddb_table_name,
"kms_configuration": self.kms_configuration.as_dict(),
"logical_key_store_name": self.logical_key_store_name,
}

if self.id is not None:
d["id"] = self.id

if self.grant_tokens is not None:
d["grant_tokens"] = self.grant_tokens

if self.ddb_client is not None:
d["ddb_client"] = self.ddb_client

if self.kms_client is not None:
d["kms_client"] = self.kms_client

return d

@staticmethod
def from_dict(d: Dict[str, Any]) -> "KeyStoreConfig":
"""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"]),
"logical_key_store_name": d["logical_key_store_name"],
}

if "id" in d:
kwargs["id"] = d["id"]

if "grant_tokens" in d:
kwargs["grant_tokens"] = d["grant_tokens"]

if "ddb_client" in d:
kwargs["ddb_client"] = d["ddb_client"]

if "kms_client" in d:
kwargs["kms_client"] = d["kms_client"]

return KeyStoreConfig(**kwargs)

def __repr__(self) -> str:
result = "KeyStoreConfig("
if self.ddb_table_name is not None:
result += f"ddb_table_name={repr(self.ddb_table_name)}, "

if self.kms_configuration is not None:
result += f"kms_configuration={repr(self.kms_configuration)}, "

if self.logical_key_store_name is not None:
result += f"logical_key_store_name={repr(self.logical_key_store_name)}, "

if self.id is not None:
result += f"id={repr(self.id)}, "

if self.grant_tokens is not None:
result += f"grant_tokens={repr(self.grant_tokens)}, "

if self.ddb_client is not None:
result += f"ddb_client={repr(self.ddb_client)}, "

if self.kms_client is not None:
result += f"kms_client={repr(self.kms_client)}"

return result + ")"

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)


def dafny_config_to_smithy_config(dafny_config) -> KeyStoreConfig:
"""Converts the provided Dafny shape for this localService's config into
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import aws_cryptographic_materialproviders.smithygenerated.aws_cryptography_materialproviders.dafny_to_smithy
import aws_cryptographic_materialproviders.smithygenerated.aws_cryptography_materialproviders.smithy_to_dafny
from dataclasses import dataclass
from typing import Any, Callable, TypeAlias
from typing import Any, Callable, Dict, TypeAlias

from .dafnyImplInterface import DafnyImplInterface
from smithy_python._private.retries import SimpleRetryStrategy
Expand Down Expand Up @@ -52,14 +52,29 @@ def __init__(


class MaterialProvidersConfig(Config):
"""Smithy-modelled localService Config shape for this localService."""

def __init__(
self,
):
"""Constructor for MaterialProvidersConfig."""
super().__init__()

def as_dict(self) -> Dict[str, Any]:
"""Converts the MaterialProvidersConfig to a dictionary."""
return {}

@staticmethod
def from_dict(d: Dict[str, Any]) -> "MaterialProvidersConfig":
"""Creates a MaterialProvidersConfig from a dictionary."""
return MaterialProvidersConfig()

def __repr__(self) -> str:
result = "MaterialProvidersConfig("

return result + ")"

def __eq__(self, other: Any) -> bool:
return isinstance(other, MaterialProvidersConfig)


def dafny_config_to_smithy_config(dafny_config) -> MaterialProvidersConfig:
"""Converts the provided Dafny shape for this localService's config into
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,94 @@ def __eq__(self, other: Any) -> bool:
return all(getattr(self, a) == getattr(other, a) for a in attributes)


class EntryAlreadyExists(ApiError[Literal["EntryAlreadyExists"]]):
code: Literal["EntryAlreadyExists"] = "EntryAlreadyExists"
message: str

def __init__(
self,
*,
message: str,
):
super().__init__(message)

def as_dict(self) -> Dict[str, Any]:
"""Converts the EntryAlreadyExists to a dictionary."""
return {
"message": self.message,
"code": self.code,
}

@staticmethod
def from_dict(d: Dict[str, Any]) -> "EntryAlreadyExists":
"""Creates a EntryAlreadyExists from a dictionary."""
kwargs: Dict[str, Any] = {
"message": d["message"],
}

return EntryAlreadyExists(**kwargs)

def __repr__(self) -> str:
result = "EntryAlreadyExists("
if self.message is not None:
result += f"message={repr(self.message)}"

return result + ")"

def __eq__(self, other: Any) -> bool:
if not isinstance(other, EntryAlreadyExists):
return False
attributes: list[str] = [
"message",
"message",
]
return all(getattr(self, a) == getattr(other, a) for a in attributes)


class EntryDoesNotExist(ApiError[Literal["EntryDoesNotExist"]]):
code: Literal["EntryDoesNotExist"] = "EntryDoesNotExist"
message: str

def __init__(
self,
*,
message: str,
):
super().__init__(message)

def as_dict(self) -> Dict[str, Any]:
"""Converts the EntryDoesNotExist to a dictionary."""
return {
"message": self.message,
"code": self.code,
}

@staticmethod
def from_dict(d: Dict[str, Any]) -> "EntryDoesNotExist":
"""Creates a EntryDoesNotExist from a dictionary."""
kwargs: Dict[str, Any] = {
"message": d["message"],
}

return EntryDoesNotExist(**kwargs)

def __repr__(self) -> str:
result = "EntryDoesNotExist("
if self.message is not None:
result += f"message={repr(self.message)}"

return result + ")"

def __eq__(self, other: Any) -> bool:
if not isinstance(other, EntryDoesNotExist):
return False
attributes: list[str] = [
"message",
"message",
]
return all(getattr(self, a) == getattr(other, a) for a in attributes)


class AwsCryptographicMaterialProvidersException(
ApiError[Literal["AwsCryptographicMaterialProvidersException"]]
):
Expand Down
Loading
Loading