Skip to content

Commit b5f8149

Browse files
committed
Updates for v5 baselines
1 parent 5a2335d commit b5f8149

2 files changed

Lines changed: 17 additions & 12 deletions

File tree

python/example_code/controltower/controltower_wrapper.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,21 @@ def enable_baseline(
8585
:raises ClientError: If enabling the baseline fails for reasons other than it being already enabled.
8686
"""
8787
try:
88-
response = self.controltower_client.enable_baseline(
89-
baselineIdentifier=baseline_identifier,
90-
baselineVersion=baseline_version,
91-
targetIdentifier=target_identifier,
92-
parameters=[
88+
# Only include parameters if identity_center_baseline is not empty
89+
parameters = []
90+
if identity_center_baseline:
91+
parameters = [
9392
{
9493
"key": "IdentityCenterEnabledBaselineArn",
9594
"value": identity_center_baseline,
9695
}
97-
],
96+
]
97+
98+
response = self.controltower_client.enable_baseline(
99+
baselineIdentifier=baseline_identifier,
100+
baselineVersion=baseline_version,
101+
targetIdentifier=target_identifier,
102+
parameters=parameters,
98103
)
99104

100105
operation_id = response["operationIdentifier"]
@@ -110,7 +115,6 @@ def enable_baseline(
110115
if err.response["Error"]["Code"] == "ValidationException":
111116
if "already enabled" in err.response["Error"]["Message"]:
112117
print("Baseline is already enabled for this target")
113-
return None
114118
else:
115119
print(
116120
"Unable to enable baseline due to validation exception: %s: %s",
@@ -122,7 +126,7 @@ def enable_baseline(
122126
err.response["Error"]["Code"],
123127
err.response["Error"]["Message"],
124128
)
125-
raise
129+
return None
126130

127131
# snippet-end:[python.example_code.controltower.EnableBaseline]
128132

python/example_code/controltower/scenario_controltower.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def run_scenario(self) -> None:
121121
else None
122122
)
123123
baseline_arn = self.controltower_wrapper.enable_baseline(
124-
self.ou_arn, ic_baseline_arn, control_tower_baseline["arn"], "4.0"
124+
self.ou_arn, ic_baseline_arn, control_tower_baseline["arn"], "5.0"
125125
)
126126
if baseline_arn:
127127
print(f"Enabled baseline ARN: {baseline_arn}")
@@ -133,9 +133,10 @@ def run_scenario(self) -> None:
133133
== control_tower_baseline["arn"]
134134
):
135135
baseline_arn = enabled_baseline["arn"]
136-
print("No change, the selected baseline was already enabled.")
136+
if baseline_arn:
137+
print("No change, the selected baseline was already enabled.")
137138

138-
if q.ask(
139+
if baseline_arn and q.ask(
139140
f"Do you want to reset the Control Tower Baseline? (y/n) ",
140141
q.is_yesno,
141142
):
@@ -161,7 +162,7 @@ def run_scenario(self) -> None:
161162
self.ou_arn,
162163
ic_baseline_arn,
163164
control_tower_baseline["arn"],
164-
"4.0",
165+
"5.0",
165166
)
166167

167168
# List and Enable Controls.

0 commit comments

Comments
 (0)