Skip to content

Commit 6491f96

Browse files
committed
fix logic for object Tags
1 parent 2c7c856 commit 6491f96

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/rpdk/guard_rail/utils/schema_utils.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -181,23 +181,27 @@ def _add_tagging_key(schema: Dict):
181181

182182
if tags_schema.get("type") == "object":
183183

184-
def _get_first_pattern_key(schema: Dict) -> str:
184+
def _get_all_pattern_key(schema: Dict) -> str:
185185
pattern_properties = schema.get("patternProperties", {})
186186
if pattern_properties:
187-
return next(iter(pattern_properties))
188-
return None
187+
return list(pattern_properties.keys())
188+
return []
189189

190190
if "patternProperties" in tags_schema:
191-
tag_key = {"pattern": _get_first_pattern_key(tags_schema)}
191+
tag_key = {"pattern": _get_all_pattern_key(tags_schema)}
192192
schema["TaggingKeyPattern"] = _is_tag_key_pattern_match(tag_key)
193193
return
194194

195195

196-
def _is_tag_key_pattern_match(tag_key: str):
196+
def _is_tag_key_pattern_match(tag_key: Dict) -> bool:
197197
_AWS_PREFIX_TAG = "aws:"
198+
198199
if "pattern" in tag_key:
199200
tag_key_pattern = tag_key["pattern"]
200201
if isinstance(tag_key_pattern, str):
201-
is_blocked = not re.match(tag_key_pattern, _AWS_PREFIX_TAG)
202-
return is_blocked
202+
return not re.match(tag_key_pattern, _AWS_PREFIX_TAG)
203+
if isinstance(tag_key_pattern, list):
204+
return all(
205+
not re.match(pattern, _AWS_PREFIX_TAG) for pattern in tag_key_pattern
206+
)
203207
return False

0 commit comments

Comments
 (0)