Skip to content

Commit

Permalink
Add support for list and dict type tag
Browse files Browse the repository at this point in the history
  • Loading branch information
cloutierMat committed Oct 14, 2024
1 parent 29ba736 commit 7dc9040
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion moto/apigateway/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1658,7 +1658,7 @@ def create_rest_api(
) -> RestAPI:
api_id = ApigwRestApiIdentifier(
self.account_id, self.region_name, name
).generate()
).generate(tags=tags)
rest_api = RestAPI(
api_id,
self.account_id,
Expand Down
2 changes: 1 addition & 1 deletion moto/secretsmanager/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def __init__(
self.name = secret_id
self.arn = SecretsManagerSecretIdentifier(
account_id, region_name, secret_id
).generate()
).generate(tags=tags)
self.account_id = account_id
self.region = region_name
self.secret_string = secret_string
Expand Down
12 changes: 9 additions & 3 deletions moto/utilities/id_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
log = logging.getLogger(__name__)

ExistingIds = Union[List[str], None]
Tags = Union[Dict[str, str], None]
Tags = Union[Dict[str, str], List[Dict[str, str]], None]

# Custom resource tag to override the generated resource ID.
TAG_KEY_CUSTOM_ID = "_custom_id_"
Expand Down Expand Up @@ -95,10 +95,16 @@ def add_id_source(

@staticmethod
def get_id_from_tags(id_source_context: IdSourceContext) -> Union[str, None]:
if tags := id_source_context.get("tags"):

if not (tags := id_source_context.get("tags")):
return None

if isinstance(tags, dict):
return tags.get(TAG_KEY_CUSTOM_ID)

return None
if isinstance(tags, list):
return next((tag.get("Value") for tag in tags if tag.get("Key") == TAG_KEY_CUSTOM_ID), None)


def get_custom_id_from_context(
self, id_source_context: IdSourceContext
Expand Down

0 comments on commit 7dc9040

Please sign in to comment.