lint: reformat python code with black
This commit is contained in:
parent
331beb01b4
commit
a406a7974b
88 changed files with 2579 additions and 1608 deletions
|
@ -11,14 +11,12 @@ from app.terraform.eotk import eotk_configuration
|
|||
from app.terraform.terraform import TerraformAutomation
|
||||
|
||||
|
||||
def update_eotk_instance(group_id: int,
|
||||
region: str,
|
||||
instance_id: str) -> None:
|
||||
def update_eotk_instance(group_id: int, region: str, instance_id: str) -> None:
|
||||
instance = Eotk.query.filter(
|
||||
Eotk.group_id == group_id,
|
||||
Eotk.region == region,
|
||||
Eotk.provider == "aws",
|
||||
Eotk.destroyed.is_(None)
|
||||
Eotk.destroyed.is_(None),
|
||||
).first()
|
||||
if instance is None:
|
||||
instance = Eotk()
|
||||
|
@ -35,10 +33,7 @@ class EotkAWSAutomation(TerraformAutomation):
|
|||
short_name = "eotk_aws"
|
||||
description = "Deploy EOTK instances to AWS"
|
||||
|
||||
template_parameters = [
|
||||
"aws_access_key",
|
||||
"aws_secret_key"
|
||||
]
|
||||
template_parameters = ["aws_access_key", "aws_secret_key"]
|
||||
|
||||
template = """
|
||||
terraform {
|
||||
|
@ -81,32 +76,41 @@ class EotkAWSAutomation(TerraformAutomation):
|
|||
self.tf_write(
|
||||
self.template,
|
||||
groups=Group.query.filter(
|
||||
Group.eotk.is_(True),
|
||||
Group.destroyed.is_(None)
|
||||
Group.eotk.is_(True), Group.destroyed.is_(None)
|
||||
).all(),
|
||||
global_namespace=app.config['GLOBAL_NAMESPACE'],
|
||||
terraform_modules_path=os.path.join(*list(os.path.split(app.root_path))[:-1], 'terraform-modules'),
|
||||
global_namespace=app.config["GLOBAL_NAMESPACE"],
|
||||
terraform_modules_path=os.path.join(
|
||||
*list(os.path.split(app.root_path))[:-1], "terraform-modules"
|
||||
),
|
||||
backend_config=f"""backend "http" {{
|
||||
lock_address = "{app.config['TFSTATE_BACKEND']}/{self.short_name}"
|
||||
unlock_address = "{app.config['TFSTATE_BACKEND']}/{self.short_name}"
|
||||
address = "{app.config['TFSTATE_BACKEND']}/{self.short_name}"
|
||||
}}""",
|
||||
**{
|
||||
k: app.config[k.upper()]
|
||||
for k in self.template_parameters
|
||||
}
|
||||
**{k: app.config[k.upper()] for k in self.template_parameters},
|
||||
)
|
||||
for group in Group.query.filter(
|
||||
Group.eotk.is_(True),
|
||||
Group.destroyed.is_(None)
|
||||
).order_by(Group.id).all():
|
||||
with DeterministicZip(os.path.join(self.working_dir, f"{group.id}.zip")) as dzip:
|
||||
dzip.add_file("sites.conf", eotk_configuration(group).encode('utf-8'))
|
||||
for group in (
|
||||
Group.query.filter(Group.eotk.is_(True), Group.destroyed.is_(None))
|
||||
.order_by(Group.id)
|
||||
.all()
|
||||
):
|
||||
with DeterministicZip(
|
||||
os.path.join(self.working_dir, f"{group.id}.zip")
|
||||
) as dzip:
|
||||
dzip.add_file("sites.conf", eotk_configuration(group).encode("utf-8"))
|
||||
for onion in sorted(group.onions, key=lambda o: o.onion_name):
|
||||
dzip.add_file(f"{onion.onion_name}.v3pub.key", onion.onion_public_key)
|
||||
dzip.add_file(f"{onion.onion_name}.v3sec.key", onion.onion_private_key)
|
||||
dzip.add_file(f"{onion.onion_name[:20]}-v3.cert", onion.tls_public_key)
|
||||
dzip.add_file(f"{onion.onion_name[:20]}-v3.pem", onion.tls_private_key)
|
||||
dzip.add_file(
|
||||
f"{onion.onion_name}.v3pub.key", onion.onion_public_key
|
||||
)
|
||||
dzip.add_file(
|
||||
f"{onion.onion_name}.v3sec.key", onion.onion_private_key
|
||||
)
|
||||
dzip.add_file(
|
||||
f"{onion.onion_name[:20]}-v3.cert", onion.tls_public_key
|
||||
)
|
||||
dzip.add_file(
|
||||
f"{onion.onion_name[:20]}-v3.pem", onion.tls_private_key
|
||||
)
|
||||
|
||||
def tf_posthook(self, *, prehook_result: Any = None) -> None:
|
||||
for e in Eotk.query.all():
|
||||
|
@ -115,9 +119,9 @@ class EotkAWSAutomation(TerraformAutomation):
|
|||
for output in outputs:
|
||||
if output.startswith("eotk_instances_"):
|
||||
try:
|
||||
group_id = int(output[len("eotk_instance_") + 1:])
|
||||
for az in outputs[output]['value']:
|
||||
update_eotk_instance(group_id, az, outputs[output]['value'][az])
|
||||
group_id = int(output[len("eotk_instance_") + 1 :])
|
||||
for az in outputs[output]["value"]:
|
||||
update_eotk_instance(group_id, az, outputs[output]["value"][az])
|
||||
except ValueError:
|
||||
pass
|
||||
db.session.commit()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue