Skip to content

Commit 748bb1c

Browse files
TaggingService: Allow key value field names to be overridden
1 parent f5b247b commit 748bb1c

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

localstack-core/localstack/utils/tagging.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,23 @@
22

33

44
class TaggingService:
5-
def __init__(self):
5+
def __init__(self, key_field: str = None, value_field: str = None):
6+
"""
7+
:param key_field: the field name representing the tag key as used by botocore specs
8+
:param value_field: the field name representing the tag value as used by botocore specs
9+
"""
10+
self.key_field = key_field or "Key"
11+
self.value_field = value_field or "Value"
12+
613
self.tags = {}
714

815
def list_tags_for_resource(self, arn: str, root_name: Optional[str] = None):
916
root_name = root_name or "Tags"
17+
1018
result = []
1119
if arn in self.tags:
1220
for k, v in self.tags[arn].items():
13-
result.append({"Key": k, "Value": v})
21+
result.append({self.key_field: k, self.value_field: v})
1422
return {root_name: result}
1523

1624
def tag_resource(self, arn: str, tags: List[Dict[str, str]]):
@@ -19,7 +27,7 @@ def tag_resource(self, arn: str, tags: List[Dict[str, str]]):
1927
if arn not in self.tags:
2028
self.tags[arn] = {}
2129
for t in tags:
22-
self.tags[arn][t["Key"]] = t["Value"]
30+
self.tags[arn][t[self.key_field]] = t[self.value_field]
2331

2432
def untag_resource(self, arn: str, tag_names: List[str]):
2533
tags = self.tags.get(arn, {})

0 commit comments

Comments
 (0)