Skip to content

Commit cd32e6a

Browse files
author
Pavan Kumar Vooturi
committed
Fix remaining flake8 plugin errors: docstrings, string concat, raise chaining, else-after-return
1 parent d463e5b commit cd32e6a

4 files changed

Lines changed: 43 additions & 16 deletions

File tree

aws_sra_examples/solutions/common/common_prerequisites/lambda/src/app.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ def get_customer_control_tower_regions() -> list: # noqa: CCR001
122122
123123
Supports both legacy Control Tower (pre-4.0) using StackSets and Control Tower 4.0+.
124124
125+
Raises:
126+
ClientError: If an unexpected AWS API error occurs.
127+
125128
Returns:
126129
Customer regions chosen in Control Tower
127130
"""
@@ -260,6 +263,9 @@ def _get_ct4_cloudformation_ssm_parameter_info(path: str) -> dict:
260263
Args:
261264
path: SSM parameter hierarchy path
262265
266+
Raises:
267+
ValueError: If Audit or Log Archive account cannot be found.
268+
263269
Returns:
264270
Info needed to create SSM parameters and helper data for custom resource
265271
"""
@@ -291,7 +297,7 @@ def _get_ct4_cloudformation_ssm_parameter_info(path: str) -> dict:
291297
LOGGER.warning("Could not find Audit account in Organizations. Ensure account is named 'Audit' or 'Security'.")
292298
raise ValueError(
293299
"Audit account not found. For CT 4.0, ensure your security account is named 'Audit' or 'Security', "
294-
"or use pControlTower=false with manual account IDs."
300+
+ "or use pControlTower=false with manual account IDs."
295301
)
296302

297303
if ct_accounts["LogArchiveAccountId"]:
@@ -301,7 +307,7 @@ def _get_ct4_cloudformation_ssm_parameter_info(path: str) -> dict:
301307
LOGGER.warning("Could not find Log Archive account in Organizations. Ensure account is named 'Log Archive'.")
302308
raise ValueError(
303309
"Log Archive account not found. For CT 4.0, ensure your log archive account is named 'Log Archive', "
304-
"or use pControlTower=false with manual account IDs."
310+
+ "or use pControlTower=false with manual account IDs."
305311
)
306312

307313
LOGGER.info(ssm_data["helper"])
@@ -317,6 +323,10 @@ def get_cloudformation_ssm_parameter_info(path: str) -> dict: # noqa: CCR001
317323
Args:
318324
path: SSM parameter hierarchy path
319325
326+
Raises:
327+
ClientError: If an unexpected AWS API error occurs.
328+
ValueError: If Log Archive account cannot be found.
329+
320330
Returns:
321331
Info needed to create SSM parameters and helper data for custom resource
322332
"""
@@ -337,8 +347,7 @@ def get_cloudformation_ssm_parameter_info(path: str) -> dict: # noqa: CCR001
337347
if error.response["Error"]["Code"] == "StackSetNotFoundException":
338348
LOGGER.info("Control Tower 4.0+ detected - AWSControlTowerBP-BASELINE-CONFIG StackSet not found")
339349
return _get_ct4_cloudformation_ssm_parameter_info(path)
340-
else:
341-
raise
350+
raise
342351

343352
# Legacy CT (< 4.0): Get Log Archive account from AWSControlTowerLoggingResources StackSet.
344353
try:
@@ -359,7 +368,7 @@ def get_cloudformation_ssm_parameter_info(path: str) -> dict: # noqa: CCR001
359368
)
360369
ssm_data["helper"]["LogArchiveAccountId"] = ct_accounts["LogArchiveAccountId"]
361370
else:
362-
raise ValueError("Log Archive account not found in Organizations.")
371+
raise ValueError("Log Archive account not found in Organizations.") from None
363372
else:
364373
raise
365374

aws_sra_examples/solutions/config/config_management_account/lambda/src/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def process_event(event: CloudFormationCustomResourceEvent, context: Context) ->
187187
if existing_aggregation_sources is None:
188188
LOGGER.info(
189189
f"Config Aggregator '{params['AGGREGATOR_NAME']}' does not exist in account {params['AUDIT_ACCOUNT_ID']}. "
190-
"Skipping aggregator update. This is expected for Control Tower 4.0+ environments."
190+
+ "Skipping aggregator update. This is expected for Control Tower 4.0+ environments."
191191
)
192192
return f"{params['AUDIT_ACCOUNT_ID']}-{params['AGGREGATOR_NAME']}-skipped"
193193
updated_aggregation_sources = get_updated_account_aggregation_sources(existing_aggregation_sources, management_account, params["action"])

aws_sra_examples/solutions/genai/bedrock_guardrails/lambda/src/sra_ssm_params.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ def get_customer_control_tower_regions(self) -> list: # noqa: CCR001
133133
134134
Supports both legacy Control Tower (pre-4.0) using StackSets and Control Tower 4.0+.
135135
136+
Raises:
137+
ClientError: If an unexpected AWS API error occurs.
138+
136139
Returns:
137140
Customer regions chosen in Control Tower
138141
"""
@@ -294,6 +297,9 @@ def _get_ct4_cloudformation_ssm_parameter_info(self, path: str) -> dict:
294297
Args:
295298
path: SSM parameter hierarchy path
296299
300+
Raises:
301+
ValueError: If Audit or Log Archive account cannot be found.
302+
297303
Returns:
298304
Info needed to create SSM parameters and helper data for custom resource
299305
"""
@@ -349,7 +355,7 @@ def _get_ct4_cloudformation_ssm_parameter_info(self, path: str) -> dict:
349355
else:
350356
raise ValueError(
351357
"Audit account not found. For CT 4.0, ensure your security account is named 'Audit' or 'Security', "
352-
"or use pControlTower=false with manual account IDs."
358+
+ "or use pControlTower=false with manual account IDs."
353359
)
354360

355361
if ct_accounts["LogArchiveAccountId"]:
@@ -365,7 +371,7 @@ def _get_ct4_cloudformation_ssm_parameter_info(self, path: str) -> dict:
365371
else:
366372
raise ValueError(
367373
"Log Archive account not found. For CT 4.0, ensure your log archive account is named 'Log Archive', "
368-
"or use pControlTower=false with manual account IDs."
374+
+ "or use pControlTower=false with manual account IDs."
369375
)
370376

371377
self.LOGGER.info(ssm_data["helper"])
@@ -379,6 +385,10 @@ def get_cloudformation_ssm_parameter_info(self, path: str) -> dict: # noqa: CCR
379385
Args:
380386
path: SSM parameter hierarchy path
381387
388+
Raises:
389+
ClientError: If an unexpected AWS API error occurs.
390+
ValueError: If Log Archive account cannot be found.
391+
382392
Returns:
383393
Info needed to create SSM parameters and helper data for custom resource
384394
"""
@@ -414,8 +424,7 @@ def get_cloudformation_ssm_parameter_info(self, path: str) -> dict: # noqa: CCR
414424
if error.response["Error"]["Code"] == "StackSetNotFoundException":
415425
self.LOGGER.info("Control Tower 4.0+ detected - AWSControlTowerBP-BASELINE-CONFIG StackSet not found")
416426
return self._get_ct4_cloudformation_ssm_parameter_info(path)
417-
else:
418-
raise
427+
raise
419428

420429
# Legacy CT (< 4.0): Get Log Archive account from AWSControlTowerLoggingResources StackSet.
421430
try:
@@ -449,7 +458,7 @@ def get_cloudformation_ssm_parameter_info(self, path: str) -> dict: # noqa: CCR
449458
)
450459
ssm_data["helper"]["LogArchiveAccountId"] = ct_accounts["LogArchiveAccountId"]
451460
else:
452-
raise ValueError("Log Archive account not found in Organizations.")
461+
raise ValueError("Log Archive account not found in Organizations.") from None
453462
else:
454463
raise
455464

aws_sra_examples/solutions/genai/bedrock_org/lambda/src/sra_ssm_params.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ def get_customer_control_tower_regions(self) -> list: # noqa: CCR001
134134
135135
Supports both legacy Control Tower (pre-4.0) using StackSets and Control Tower 4.0+.
136136
137+
Raises:
138+
ClientError: If an unexpected AWS API error occurs.
139+
137140
Returns:
138141
Customer regions chosen in Control Tower
139142
"""
@@ -295,6 +298,9 @@ def _get_ct4_cloudformation_ssm_parameter_info(self, path: str) -> dict:
295298
Args:
296299
path: SSM parameter hierarchy path
297300
301+
Raises:
302+
ValueError: If Audit or Log Archive account cannot be found.
303+
298304
Returns:
299305
Info needed to create SSM parameters and helper data for custom resource
300306
"""
@@ -350,7 +356,7 @@ def _get_ct4_cloudformation_ssm_parameter_info(self, path: str) -> dict:
350356
else:
351357
raise ValueError(
352358
"Audit account not found. For CT 4.0, ensure your security account is named 'Audit' or 'Security', "
353-
"or use pControlTower=false with manual account IDs."
359+
+ "or use pControlTower=false with manual account IDs."
354360
)
355361

356362
if ct_accounts["LogArchiveAccountId"]:
@@ -366,7 +372,7 @@ def _get_ct4_cloudformation_ssm_parameter_info(self, path: str) -> dict:
366372
else:
367373
raise ValueError(
368374
"Log Archive account not found. For CT 4.0, ensure your log archive account is named 'Log Archive', "
369-
"or use pControlTower=false with manual account IDs."
375+
+ "or use pControlTower=false with manual account IDs."
370376
)
371377

372378
self.LOGGER.info(ssm_data["helper"])
@@ -380,6 +386,10 @@ def get_cloudformation_ssm_parameter_info(self, path: str) -> dict: # noqa: CCR
380386
Args:
381387
path: SSM parameter hierarchy path
382388
389+
Raises:
390+
ClientError: If an unexpected AWS API error occurs.
391+
ValueError: If Log Archive account cannot be found.
392+
383393
Returns:
384394
Info needed to create SSM parameters and helper data for custom resource
385395
"""
@@ -415,8 +425,7 @@ def get_cloudformation_ssm_parameter_info(self, path: str) -> dict: # noqa: CCR
415425
if error.response["Error"]["Code"] == "StackSetNotFoundException":
416426
self.LOGGER.info("Control Tower 4.0+ detected - AWSControlTowerBP-BASELINE-CONFIG StackSet not found")
417427
return self._get_ct4_cloudformation_ssm_parameter_info(path)
418-
else:
419-
raise
428+
raise
420429

421430
# Legacy CT (< 4.0): Get Log Archive account from AWSControlTowerLoggingResources StackSet.
422431
try:
@@ -450,7 +459,7 @@ def get_cloudformation_ssm_parameter_info(self, path: str) -> dict: # noqa: CCR
450459
)
451460
ssm_data["helper"]["LogArchiveAccountId"] = ct_accounts["LogArchiveAccountId"]
452461
else:
453-
raise ValueError("Log Archive account not found in Organizations.")
462+
raise ValueError("Log Archive account not found in Organizations.") from None
454463
else:
455464
raise
456465

0 commit comments

Comments
 (0)