Skip to content

Commit

Permalink
running black
Browse files Browse the repository at this point in the history
  • Loading branch information
eamonnfaherty committed Oct 15, 2024
1 parent 36d6221 commit 5f45fe4
Show file tree
Hide file tree
Showing 85 changed files with 1,411 additions and 689 deletions.
115 changes: 84 additions & 31 deletions servicecatalog_puppet/aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ def get_provisioned_product_from_scan(
):
logger.info(f"{logging_prefix}: running get_provisioned_product_from_scan")
paginator = service_catalog.get_paginator("scan_provisioned_products")
pages = paginator.paginate(AccessLevelFilter={"Key": "Account", "Value": "self"},)
pages = paginator.paginate(
AccessLevelFilter={"Key": "Account", "Value": "self"},
)

for page in pages:
logger.info(
Expand Down Expand Up @@ -136,7 +138,9 @@ def get_stack_output_for(cloudformation, stack_name):
def get_default_parameters_for_stack(cloudformation, stack_name):
logger.info(f"Getting default parameters for for {stack_name}")
existing_stack_params_dict = {}
summary_response = cloudformation.get_template_summary(StackName=stack_name,)
summary_response = cloudformation.get_template_summary(
StackName=stack_name,
)
for parameter in summary_response.get("Parameters"):
existing_stack_params_dict[parameter.get("ParameterKey")] = parameter.get(
"DefaultValue"
Expand Down Expand Up @@ -175,14 +179,16 @@ def provision_product_with_plan(
stack_name = "-".join([constants.PREFIX, account_id, region, launch_name])
logger.info(f"{uid} :: Checking for an existing plan")
if puppet_account_id == account_id:
provisioned_product_plans = service_catalog.list_provisioned_product_plans_single_page().get(
"ProvisionedProductPlans", []
provisioned_product_plans = (
service_catalog.list_provisioned_product_plans_single_page().get(
"ProvisionedProductPlans", []
)
)
else:
provisioned_product_plans = service_catalog.list_provisioned_product_plans_single_page(
AccessLevelFilter={"Key": "Account", "Value": "self"}
).get(
"ProvisionedProductPlans", []
provisioned_product_plans = (
service_catalog.list_provisioned_product_plans_single_page(
AccessLevelFilter={"Key": "Account", "Value": "self"}
).get("ProvisionedProductPlans", [])
)
for provisioned_product_plan in provisioned_product_plans:
logger.info(
Expand All @@ -191,7 +197,8 @@ def provision_product_with_plan(
if provisioned_product_plan.get("ProvisionProductName") == launch_name:
logger.info(f"{uid} :: Found existing plan, going to terminate it")
service_catalog.delete_provisioned_product_plan(
PlanId=provisioned_product_plan.get("PlanId"), IgnoreErrors=True,
PlanId=provisioned_product_plan.get("PlanId"),
IgnoreErrors=True,
)

logger.info(f"{uid} :: Creating a plan")
Expand All @@ -200,7 +207,10 @@ def provision_product_with_plan(
provisioning_parameters = []
for p in params.keys():
provisioning_parameters.append(
{"Key": p, "Value": params.get(p),}
{
"Key": p,
"Value": params.get(p),
}
)
args = dict(
PlanName=stack_name,
Expand All @@ -211,11 +221,26 @@ def provision_product_with_plan(
ProvisioningArtifactId=provisioning_artifact_id,
ProvisioningParameters=provisioning_parameters,
Tags=[
{"Key": "ServiceCatalogPuppet:Actor", "Value": "Generated",},
{"Key": "launch_name", "Value": launch_name,},
{"Key": "version", "Value": version,},
{
"Key": "ServiceCatalogPuppet:Actor",
"Value": "Generated",
},
{
"Key": "launch_name",
"Value": launch_name,
},
{
"Key": "version",
"Value": version,
},
],
NotificationArns=[regional_sns_topic,] if should_use_sns else [],
NotificationArns=(
[
regional_sns_topic,
]
if should_use_sns
else []
),
)
if tags:
args["Tags"].extend(
Expand All @@ -228,8 +253,8 @@ def provision_product_with_plan(
plan_status = "CREATE_IN_PROGRESS"

while plan_status == "CREATE_IN_PROGRESS":
describe_provisioned_product_plan_response = service_catalog.describe_provisioned_product_plan(
PlanId=plan_id
describe_provisioned_product_plan_response = (
service_catalog.describe_provisioned_product_plan(PlanId=plan_id)
)
plan_status = describe_provisioned_product_plan_response.get(
"ProvisionedProductPlanDetails"
Expand Down Expand Up @@ -278,7 +303,8 @@ def provision_product_with_plan(
break
elif execute_status == "TAINTED":
service_catalog.delete_provisioned_product_plan(
PlanId=plan_id, IgnoreErrors=True,
PlanId=plan_id,
IgnoreErrors=True,
)
raise Exception(
f"{uid} :: Execute failed: {execute_status}: {provisioned_product_detail.get('StatusMessage')}"
Expand All @@ -291,7 +317,8 @@ def provision_product_with_plan(
time.sleep(5)

service_catalog.delete_provisioned_product_plan(
PlanId=plan_id, IgnoreErrors=True,
PlanId=plan_id,
IgnoreErrors=True,
)
return provisioned_product_id

Expand Down Expand Up @@ -352,7 +379,10 @@ def provision_product(
f"Could not provision {launch_name} in {region} of {account_id}, parameter {p} was None"
)
provisioning_parameters.append(
{"Key": p, "Value": params.get(p),}
{
"Key": p,
"Value": params.get(p),
}
)
args = dict(
ProductId=product_id,
Expand All @@ -361,15 +391,26 @@ def provision_product(
ProvisionedProductName=launch_name,
ProvisioningParameters=provisioning_parameters,
Tags=[
{"Key": "ServiceCatalogPuppet:Actor", "Value": "Generated",},
{"Key": "launch_name", "Value": launch_name,},
{"Key": "version", "Value": version,},
{
"Key": "ServiceCatalogPuppet:Actor",
"Value": "Generated",
},
{
"Key": "launch_name",
"Value": launch_name,
},
{
"Key": "version",
"Value": version,
},
],
NotificationArns=[
f"arn:{partition}:sns:{region}:{puppet_account_id}:servicecatalog-puppet-cloudformation-regional-events",
]
if should_use_sns
else [],
NotificationArns=(
[
f"arn:{partition}:sns:{region}:{puppet_account_id}:servicecatalog-puppet-cloudformation-regional-events",
]
if should_use_sns
else []
),
)
if tags:
args["Tags"].extend(
Expand Down Expand Up @@ -424,7 +465,10 @@ def update_provisioned_product(
provisioning_parameters = []
for p in params.keys():
provisioning_parameters.append(
{"Key": p, "Value": params.get(p),}
{
"Key": p,
"Value": params.get(p),
}
)

args = dict(
Expand All @@ -434,9 +478,18 @@ def update_provisioned_product(
ProvisionedProductName=launch_name,
ProvisioningParameters=provisioning_parameters,
Tags=[
{"Key": "ServiceCatalogPuppet:Actor", "Value": "Generated",},
{"Key": "launch_name", "Value": launch_name,},
{"Key": "version", "Value": version,},
{
"Key": "ServiceCatalogPuppet:Actor",
"Value": "Generated",
},
{
"Key": "launch_name",
"Value": launch_name,
},
{
"Key": "version",
"Value": version,
},
],
)
if tags:
Expand Down
Loading

0 comments on commit 5f45fe4

Please sign in to comment.