fix linting

This commit is contained in:
Michael Jerger 2023-05-22 13:37:14 +02:00
parent 0e28cbd52d
commit c2fee0f52e
5 changed files with 72 additions and 62 deletions

View file

@ -1,33 +1,33 @@
from dda_python_terraform import Terraform from dda_python_terraform import Terraform
from .devops_terraform_build import DevopsTerraformBuild from .devops_terraform_build import DevopsTerraformBuild
def add_aws_backend_properties_mixin_config(config, account_name): def add_aws_backend_properties_mixin_config(config, account_name):
config.update({'AwsBackendPropertiesMixin': config.update({"AwsBackendPropertiesMixin": {"account_name": account_name}})
{'account_name': account_name}})
return config return config
class AwsBackendPropertiesMixin(DevopsTerraformBuild):
class AwsBackendPropertiesMixin(DevopsTerraformBuild):
def __init__(self, project, config): def __init__(self, project, config):
super().__init__(project, config) super().__init__(project, config)
aws_mixin_config = config['AwsBackendPropertiesMixin'] aws_mixin_config = config["AwsBackendPropertiesMixin"]
self.account_name = aws_mixin_config['account_name'] self.account_name = aws_mixin_config["account_name"]
self.backend_config = "backend." + self.account_name + "." + self.stage + ".properties" self.backend_config = (
"backend." + self.account_name + "." + self.stage + ".properties"
)
self.additional_tfvar_files.append(self.backend_config) self.additional_tfvar_files.append(self.backend_config)
def project_vars(self): def project_vars(self):
ret = super().project_vars() ret = super().project_vars()
ret.update({'account_name': self.account_name}) ret.update({"account_name": self.account_name})
return ret return ret
def copy_build_resources_from_package(self): def copy_build_resources_from_package(self):
super().copy_build_resources_from_package() super().copy_build_resources_from_package()
self.copy_build_resource_file_from_package('provider_registry.tf') self.copy_build_resource_file_from_package("provider_registry.tf")
self.copy_build_resource_file_from_package('aws_provider.tf') self.copy_build_resource_file_from_package("aws_provider.tf")
self.copy_build_resource_file_from_package( self.copy_build_resource_file_from_package("aws_backend_properties_vars.tf")
'aws_backend_properties_vars.tf') self.copy_build_resource_file_from_package("aws_backend_with_properties.tf")
self.copy_build_resource_file_from_package(
'aws_backend_with_properties.tf')
def copy_local_state(self): def copy_local_state(self):
pass pass
@ -36,14 +36,17 @@ class AwsBackendPropertiesMixin(DevopsTerraformBuild):
pass pass
def init_client(self): def init_client(self):
terraform = Terraform(working_dir=self.build_path(), terraform_semantic_version=self.terraform_semantic_version) terraform = Terraform(
working_dir=self.build_path(),
terraform_semantic_version=self.terraform_semantic_version,
)
terraform.init(backend_config=self.backend_config) terraform.init(backend_config=self.backend_config)
self.print_terraform_command(terraform) self.print_terraform_command(terraform)
if self.use_workspace: if self.use_workspace:
try: try:
terraform.workspace('select', self.stage) terraform.workspace("select", self.stage)
self.print_terraform_command(terraform) self.print_terraform_command(terraform)
except: except:
terraform.workspace('new', self.stage) terraform.workspace("new", self.stage)
self.print_terraform_command(terraform) self.print_terraform_command(terraform)
return terraform return terraform

View file

@ -43,6 +43,7 @@ def add_c4k_mixin_config(
) )
return config return config
class C4kBuild(DevopsBuild): class C4kBuild(DevopsBuild):
def __init__(self, project, config): def __init__(self, project, config):
super().__init__(project, config) super().__init__(project, config)

View file

@ -1,55 +1,55 @@
from dda_python_terraform import Terraform from dda_python_terraform import Terraform
from .digitalocean_terraform_build import DigitaloceanTerraformBuild from .digitalocean_terraform_build import DigitaloceanTerraformBuild
def add_digitalocean_backend_properties_mixin_config(config,
account_name, def add_digitalocean_backend_properties_mixin_config(
endpoint, config, account_name, endpoint, bucket, key, region="eu-central-1"
bucket, ):
key, config.update(
region='eu-central-1'): {
config.update({'DigitaloceanBackendPropertiesMixin': "DigitaloceanBackendPropertiesMixin": {
{'account_name': account_name, "account_name": account_name,
'endpoint': endpoint, "endpoint": endpoint,
'bucket': bucket, "bucket": bucket,
'key': key, "key": key,
'region': region}}) "region": region,
}
}
)
return config return config
class DigitaloceanBackendPropertiesMixin(DigitaloceanTerraformBuild): class DigitaloceanBackendPropertiesMixin(DigitaloceanTerraformBuild):
def __init__(self, project, config): def __init__(self, project, config):
super().__init__(project, config) super().__init__(project, config)
do_mixin_config = config['DigitaloceanBackendPropertiesMixin'] do_mixin_config = config["DigitaloceanBackendPropertiesMixin"]
self.account_name = do_mixin_config['account_name'] self.account_name = do_mixin_config["account_name"]
self.endpoint = do_mixin_config['endpoint'] self.endpoint = do_mixin_config["endpoint"]
self.bucket = do_mixin_config['bucket'] self.bucket = do_mixin_config["bucket"]
self.key = do_mixin_config['account_name'] + \ self.key = do_mixin_config["account_name"] + "/" + do_mixin_config["key"]
'/' + do_mixin_config['key'] self.region = do_mixin_config["region"]
self.region = do_mixin_config['region']
self.backend_config = { self.backend_config = {
'access_key': self.do_spaces_access_id, "access_key": self.do_spaces_access_id,
'secret_key': self.do_spaces_secret_key, "secret_key": self.do_spaces_secret_key,
'endpoint': self.endpoint, "endpoint": self.endpoint,
'bucket': self.bucket, "bucket": self.bucket,
'key': self.key, "key": self.key,
'region': self.region} "region": self.region,
}
def project_vars(self): def project_vars(self):
ret = super().project_vars() ret = super().project_vars()
ret.update({'account_name': self.account_name}) ret.update({"account_name": self.account_name})
ret.update({'endpoint': self.endpoint}) ret.update({"endpoint": self.endpoint})
ret.update({'bucket': self.bucket}) ret.update({"bucket": self.bucket})
ret.update({'key': self.key}) ret.update({"key": self.key})
ret.update({'region': self.region}) ret.update({"region": self.region})
return ret return ret
def copy_build_resources_from_package(self): def copy_build_resources_from_package(self):
super().copy_build_resources_from_package() super().copy_build_resources_from_package()
self.copy_build_resource_file_from_package( self.copy_build_resource_file_from_package("do_backend_properties_vars.tf")
'do_backend_properties_vars.tf') self.copy_build_resource_file_from_package("do_backend_with_properties.tf")
self.copy_build_resource_file_from_package(
'do_backend_with_properties.tf')
def copy_local_state(self): def copy_local_state(self):
pass pass
@ -58,15 +58,17 @@ class DigitaloceanBackendPropertiesMixin(DigitaloceanTerraformBuild):
pass pass
def init_client(self): def init_client(self):
terraform = Terraform(working_dir=self.build_path(), terraform = Terraform(
terraform_semantic_version=self.terraform_semantic_version) working_dir=self.build_path(),
terraform_semantic_version=self.terraform_semantic_version,
)
terraform.init(backend_config=self.backend_config) terraform.init(backend_config=self.backend_config)
self.print_terraform_command(terraform) self.print_terraform_command(terraform)
if self.use_workspace: if self.use_workspace:
try: try:
terraform.workspace('select', self.stage) terraform.workspace("select", self.stage)
self.print_terraform_command(terraform) self.print_terraform_command(terraform)
except: except:
terraform.workspace('new', self.stage) terraform.workspace("new", self.stage)
self.print_terraform_command(terraform) self.print_terraform_command(terraform)
return terraform return terraform

View file

@ -98,7 +98,10 @@ class ExecutionApi:
output = output.rstrip() output = output.rstrip()
return output return output
def execute_live(self, command): def execute_live(self, command, dry_run=False):
if dry_run:
print(command)
else:
process = Popen(command, stdout=PIPE) process = Popen(command, stdout=PIPE)
for line in iter(process.stdout.readline, b""): for line in iter(process.stdout.readline, b""):
print(line.decode("utf-8"), end="") print(line.decode("utf-8"), end="")

View file

@ -1,7 +1,8 @@
from .domain import DnsRecord from .domain import DnsRecord, BuildType
from .infrastructure import ExecutionApi from .infrastructure import ExecutionApi
from .devops_build import DevopsBuild from .devops_build import DevopsBuild
class ProvsK3sBuild(DevopsBuild): class ProvsK3sBuild(DevopsBuild):
def __init__(self, project, config): def __init__(self, project, config):
inp = config.copy() inp = config.copy()