lint: reformat python code with black
This commit is contained in:
parent
331beb01b4
commit
a406a7974b
88 changed files with 2579 additions and 1608 deletions
|
@ -15,21 +15,26 @@ from app.terraform.terraform import TerraformAutomation
|
|||
def import_state(state: Any) -> None:
|
||||
if not isinstance(state, dict):
|
||||
raise RuntimeError("The Terraform state object returned was not a dict.")
|
||||
if "values" not in state or "child_modules" not in state['values']['root_module']:
|
||||
if "values" not in state or "child_modules" not in state["values"]["root_module"]:
|
||||
# There are no CloudFront origins deployed to import state for
|
||||
return
|
||||
# CloudFront distributions (origins)
|
||||
for mod in state['values']['root_module']['child_modules']:
|
||||
if mod['address'].startswith('module.static_'):
|
||||
static_id = mod['address'][len('module.static_'):]
|
||||
for mod in state["values"]["root_module"]["child_modules"]:
|
||||
if mod["address"].startswith("module.static_"):
|
||||
static_id = mod["address"][len("module.static_") :]
|
||||
logging.debug("Found static module in state: %s", static_id)
|
||||
for res in mod['resources']:
|
||||
if res['address'].endswith('aws_cloudfront_distribution.this'):
|
||||
for res in mod["resources"]:
|
||||
if res["address"].endswith("aws_cloudfront_distribution.this"):
|
||||
logging.debug("and found related cloudfront distribution")
|
||||
static = StaticOrigin.query.filter(StaticOrigin.id == static_id).first()
|
||||
static.origin_domain_name = res['values']['domain_name']
|
||||
logging.debug("and found static origin: %s to update with domain name: %s", static.id,
|
||||
static.origin_domain_name)
|
||||
static = StaticOrigin.query.filter(
|
||||
StaticOrigin.id == static_id
|
||||
).first()
|
||||
static.origin_domain_name = res["values"]["domain_name"]
|
||||
logging.debug(
|
||||
"and found static origin: %s to update with domain name: %s",
|
||||
static.id,
|
||||
static.origin_domain_name,
|
||||
)
|
||||
static.terraform_updated = datetime.now(tz=timezone.utc)
|
||||
break
|
||||
db.session.commit()
|
||||
|
@ -128,14 +133,18 @@ class StaticAWSAutomation(TerraformAutomation):
|
|||
groups=groups,
|
||||
storage_cloud_accounts=storage_cloud_accounts,
|
||||
source_cloud_accounts=source_cloud_accounts,
|
||||
global_namespace=current_app.config['GLOBAL_NAMESPACE'], bypass_token=current_app.config['BYPASS_TOKEN'],
|
||||
terraform_modules_path=os.path.join(*list(os.path.split(current_app.root_path))[:-1], 'terraform-modules'),
|
||||
global_namespace=current_app.config["GLOBAL_NAMESPACE"],
|
||||
bypass_token=current_app.config["BYPASS_TOKEN"],
|
||||
terraform_modules_path=os.path.join(
|
||||
*list(os.path.split(current_app.root_path))[:-1], "terraform-modules"
|
||||
),
|
||||
backend_config=f"""backend "http" {{
|
||||
lock_address = "{current_app.config['TFSTATE_BACKEND']}/{self.short_name}"
|
||||
unlock_address = "{current_app.config['TFSTATE_BACKEND']}/{self.short_name}"
|
||||
address = "{current_app.config['TFSTATE_BACKEND']}/{self.short_name}"
|
||||
}}""",
|
||||
**{k: current_app.config[k.upper()] for k in self.template_parameters})
|
||||
**{k: current_app.config[k.upper()] for k in self.template_parameters},
|
||||
)
|
||||
|
||||
def tf_posthook(self, *, prehook_result: Any = None) -> None:
|
||||
import_state(self.tf_show())
|
||||
|
|
|
@ -27,7 +27,9 @@ class StaticMetaAutomation(BaseAutomation):
|
|||
if static_origin.origin_domain_name is not None:
|
||||
try:
|
||||
# Check if an Origin with the same domain name already exists
|
||||
origin = Origin.query.filter_by(domain_name=static_origin.origin_domain_name).one()
|
||||
origin = Origin.query.filter_by(
|
||||
domain_name=static_origin.origin_domain_name
|
||||
).one()
|
||||
# Keep auto rotation value in sync
|
||||
origin.auto_rotation = static_origin.auto_rotate
|
||||
except NoResultFound:
|
||||
|
@ -35,17 +37,21 @@ class StaticMetaAutomation(BaseAutomation):
|
|||
origin = Origin(
|
||||
group_id=static_origin.group_id,
|
||||
description=f"PORTAL !! DO NOT DELETE !! Automatically created web origin for static origin "
|
||||
f"#{static_origin.id}",
|
||||
f"#{static_origin.id}",
|
||||
domain_name=static_origin.origin_domain_name,
|
||||
auto_rotation=static_origin.auto_rotate,
|
||||
smart=False,
|
||||
assets=False,
|
||||
)
|
||||
db.session.add(origin)
|
||||
logging.debug(f"Created Origin with domain name {origin.domain_name}")
|
||||
logging.debug(
|
||||
f"Created Origin with domain name {origin.domain_name}"
|
||||
)
|
||||
|
||||
# Step 2: Remove Origins for StaticOrigins with non-null destroy value
|
||||
static_origins_with_destroyed = StaticOrigin.query.filter(StaticOrigin.destroyed.isnot(None)).all()
|
||||
static_origins_with_destroyed = StaticOrigin.query.filter(
|
||||
StaticOrigin.destroyed.isnot(None)
|
||||
).all()
|
||||
for static_origin in static_origins_with_destroyed:
|
||||
try:
|
||||
origin = Origin.query.filter_by(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue