Skip to content

Commit

Permalink
fix: Flag should be enum for pritning
Browse files Browse the repository at this point in the history
  • Loading branch information
texastony committed Nov 4, 2024
1 parent e842846 commit c6fdedb
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 194 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
SystemKey_kmsAes,
SystemKey_trustStorage,
)
import aws_cryptographic_material_providers.internaldafny.generated.module_
import aws_cryptographic_material_providers.smithygenerated.aws_cryptography_keystore.dafny_to_smithy
import aws_cryptographic_material_providers.smithygenerated.aws_cryptography_keystoreadmin.dafny_to_smithy
import aws_cryptographic_material_providers.smithygenerated.aws_cryptography_keystoreadmin.models
Expand Down Expand Up @@ -279,29 +280,17 @@ def aws_cryptography_keystoreadmin_MutatedBranchKeyItem(dafny_input):


def aws_cryptography_keystoreadmin_InitializeMutationFlag(dafny_input):
# Convert InitializeMutationFlag
if isinstance(dafny_input, InitializeMutationFlag_Created):
InitializeMutationFlag_union_value = aws_cryptographic_material_providers.smithygenerated.aws_cryptography_keystoreadmin.models.InitializeMutationFlagCreated(
b"".join(ord(c).to_bytes(2, "big") for c in dafny_input.Created).decode(
"utf-16-be"
)
)
return "Created"

elif isinstance(dafny_input, InitializeMutationFlag_Resumed):
InitializeMutationFlag_union_value = aws_cryptographic_material_providers.smithygenerated.aws_cryptography_keystoreadmin.models.InitializeMutationFlagResumed(
b"".join(ord(c).to_bytes(2, "big") for c in dafny_input.Resumed).decode(
"utf-16-be"
)
)
return "Resumed"

elif isinstance(dafny_input, InitializeMutationFlag_ResumedWithoutIndex):
InitializeMutationFlag_union_value = aws_cryptographic_material_providers.smithygenerated.aws_cryptography_keystoreadmin.models.InitializeMutationFlagResumedWithoutIndex(
b"".join(
ord(c).to_bytes(2, "big") for c in dafny_input.ResumedWithoutIndex
).decode("utf-16-be")
)
else:
raise ValueError("No recognized union value in union type: " + str(dafny_input))
return "ResumedWithoutIndex"

return InitializeMutationFlag_union_value
else:
raise ValueError(f"No recognized enum value in enum type: {dafny_input=}")


def aws_cryptography_keystoreadmin_InitializeMutationOutput(dafny_input):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1221,138 +1221,29 @@ def __eq__(self, other: Any) -> bool:
return all(getattr(self, a) == getattr(other, a) for a in attributes)


class InitializeMutationFlagCreated:
"""This is a new mutation."""
class InitializeMutationFlag:
CREATED = "Created"

def __init__(self, value: str):
self.value = value

def as_dict(self) -> Dict[str, Any]:
return {"Created": self.value}

@staticmethod
def from_dict(d: Dict[str, Any]) -> "InitializeMutationFlagCreated":
if len(d) != 1:
raise TypeError(f"Unions may have exactly 1 value, but found {len(d)}")

return InitializeMutationFlagCreated(d["Created"])

def __repr__(self) -> str:
return f"InitializeMutationFlagCreated(value=repr(self.value))"

def __eq__(self, other: Any) -> bool:
if not isinstance(other, InitializeMutationFlagCreated):
return False
return self.value == other.value


class InitializeMutationFlagResumed:
"""A matching mutation already existed."""

def __init__(self, value: str):
self.value = value

def as_dict(self) -> Dict[str, Any]:
return {"Resumed": self.value}

@staticmethod
def from_dict(d: Dict[str, Any]) -> "InitializeMutationFlagResumed":
if len(d) != 1:
raise TypeError(f"Unions may have exactly 1 value, but found {len(d)}")

return InitializeMutationFlagResumed(d["Resumed"])

def __repr__(self) -> str:
return f"InitializeMutationFlagResumed(value=repr(self.value))"

def __eq__(self, other: Any) -> bool:
if not isinstance(other, InitializeMutationFlagResumed):
return False
return self.value == other.value


class InitializeMutationFlagResumedWithoutIndex:
"""A matching mutation already existed, but no Page Index was found."""

def __init__(self, value: str):
self.value = value

def as_dict(self) -> Dict[str, Any]:
return {"ResumedWithoutIndex": self.value}

@staticmethod
def from_dict(d: Dict[str, Any]) -> "InitializeMutationFlagResumedWithoutIndex":
if len(d) != 1:
raise TypeError(f"Unions may have exactly 1 value, but found {len(d)}")

return InitializeMutationFlagResumedWithoutIndex(d["ResumedWithoutIndex"])

def __repr__(self) -> str:
return f"InitializeMutationFlagResumedWithoutIndex(value=repr(self.value))"

def __eq__(self, other: Any) -> bool:
if not isinstance(other, InitializeMutationFlagResumedWithoutIndex):
return False
return self.value == other.value


class InitializeMutationFlagUnknown:
"""Represents an unknown variant.
If you receive this value, you will need to update your library to
receive the parsed value.
This value may not be deliberately sent.
"""

def __init__(self, tag: str):
self.tag = tag

def as_dict(self) -> Dict[str, Any]:
return {"SDK_UNKNOWN_MEMBER": {"name": self.tag}}

@staticmethod
def from_dict(d: Dict[str, Any]) -> "InitializeMutationFlagUnknown":
if len(d) != 1:
raise TypeError(f"Unions may have exactly 1 value, but found {len(d)}")
return InitializeMutationFlagUnknown(d["SDK_UNKNOWN_MEMBER"]["name"])

def __repr__(self) -> str:
return f"InitializeMutationFlagUnknown(tag={self.tag})"


InitializeMutationFlag = Union[
InitializeMutationFlagCreated,
InitializeMutationFlagResumed,
InitializeMutationFlagResumedWithoutIndex,
InitializeMutationFlagUnknown,
]
RESUMED = "Resumed"

RESUMED_WITHOUT_INDEX = "ResumedWithoutIndex"

def _initialize_mutation_flag_from_dict(d: Dict[str, Any]) -> InitializeMutationFlag:
if "Created" in d:
return InitializeMutationFlagCreated.from_dict(d)

if "Resumed" in d:
return InitializeMutationFlagResumed.from_dict(d)

if "ResumedWithoutIndex" in d:
return InitializeMutationFlagResumedWithoutIndex.from_dict(d)

raise TypeError(f"Unions may have exactly 1 value, but found {len(d)}")
# This set contains every possible value known at the time this was generated. New
# values may be added in the future.
values = frozenset({"Created", "Resumed", "ResumedWithoutIndex"})


class InitializeMutationOutput:
mutation_token: MutationToken
mutated_branch_key_items: list[MutatedBranchKeyItem]
initialize_mutation_flag: InitializeMutationFlag
initialize_mutation_flag: str

def __init__(
self,
*,
mutation_token: MutationToken,
mutated_branch_key_items: list[MutatedBranchKeyItem],
initialize_mutation_flag: InitializeMutationFlag,
initialize_mutation_flag: str,
):
"""
:param mutation_token: Pass the Mutation Token to the Apply Mutation operation
Expand All @@ -1371,7 +1262,7 @@ def as_dict(self) -> Dict[str, Any]:
"mutated_branch_key_items": _mutated_branch_key_items_as_dict(
self.mutated_branch_key_items
),
"initialize_mutation_flag": self.initialize_mutation_flag.as_dict(),
"initialize_mutation_flag": self.initialize_mutation_flag,
}

@staticmethod
Expand All @@ -1382,9 +1273,7 @@ def from_dict(d: Dict[str, Any]) -> "InitializeMutationOutput":
"mutated_branch_key_items": _mutated_branch_key_items_from_dict(
d["mutated_branch_key_items"]
),
"initialize_mutation_flag": _initialize_mutation_flag_from_dict(
d["initialize_mutation_flag"]
),
"initialize_mutation_flag": d["initialize_mutation_flag"],
}

return InitializeMutationOutput(**kwargs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,60 +471,17 @@ def aws_cryptography_keystoreadmin_MutatedBranchKeyItem(native_input):


def aws_cryptography_keystoreadmin_InitializeMutationFlag(native_input):
if isinstance(
native_input,
aws_cryptographic_material_providers.smithygenerated.aws_cryptography_keystoreadmin.models.InitializeMutationFlagCreated,
):
InitializeMutationFlag_union_value = InitializeMutationFlag_Created(
Seq(
"".join(
[
chr(int.from_bytes(pair, "big"))
for pair in zip(
*[iter(native_input.value.encode("utf-16-be"))] * 2
)
]
)
)
)
elif isinstance(
native_input,
aws_cryptographic_material_providers.smithygenerated.aws_cryptography_keystoreadmin.models.InitializeMutationFlagResumed,
):
InitializeMutationFlag_union_value = InitializeMutationFlag_Resumed(
Seq(
"".join(
[
chr(int.from_bytes(pair, "big"))
for pair in zip(
*[iter(native_input.value.encode("utf-16-be"))] * 2
)
]
)
)
)
elif isinstance(
native_input,
aws_cryptographic_material_providers.smithygenerated.aws_cryptography_keystoreadmin.models.InitializeMutationFlagResumedWithoutIndex,
):
InitializeMutationFlag_union_value = InitializeMutationFlag_ResumedWithoutIndex(
Seq(
"".join(
[
chr(int.from_bytes(pair, "big"))
for pair in zip(
*[iter(native_input.value.encode("utf-16-be"))] * 2
)
]
)
)
)
else:
raise ValueError(
"No recognized union value in union type: " + str(native_input)
)
if native_input == "Created":
return InitializeMutationFlag_Created()

return InitializeMutationFlag_union_value
elif native_input == "Resumed":
return InitializeMutationFlag_Resumed()

elif native_input == "ResumedWithoutIndex":
return InitializeMutationFlag_ResumedWithoutIndex()

else:
raise ValueError(f"No recognized enum value in enum type: {native_input=}")


def aws_cryptography_keystoreadmin_ApplyMutationOutput(native_input):
Expand Down

0 comments on commit c6fdedb

Please sign in to comment.