Pass env credentials to start command

This commit is contained in:
patdyn 2024-06-26 16:52:04 +02:00
parent 4eadad3940
commit ce9d3fdee6
3 changed files with 21 additions and 4 deletions

View file

@ -37,8 +37,10 @@ class TerraformService:
self.file_api.cp("*.tfvars", devops.build_path(), check=False) self.file_api.cp("*.tfvars", devops.build_path(), check=False)
self.file_api.cp_recursive("scripts", devops.build_path(), check=False) self.file_api.cp_recursive("scripts", devops.build_path(), check=False)
def start_tf_backend_git_daemon(self): def start_tf_backend_git_daemon(self, devops: Devops):
self.tf_backend_git_api.start() terraform = devops.specialized_builds[BuildType.TERRAFORM]
credentials = terraform.env_credentials()
self.tf_backend_git_api.start(credentials)
def uses_backend_git(self, devops: Devops) -> bool: def uses_backend_git(self, devops: Devops) -> bool:
terraform = devops.specialized_builds[BuildType.TERRAFORM] terraform = devops.specialized_builds[BuildType.TERRAFORM]

View file

@ -92,6 +92,17 @@ class TerraformDomain(Validateable):
def uses_backend_git(self) -> bool: def uses_backend_git(self) -> bool:
return ProviderType.TERRAFORM_BACKEND_GIT in self.providers.keys() return ProviderType.TERRAFORM_BACKEND_GIT in self.providers.keys()
# ToDo: Add ssh method case and make this default
# ToDo: How do we get to the credentials?
def env_credentials(self) -> Dict[str, str]:
tf_backend_git = self.providers[ProviderType.TERRAFORM_BACKEND_GIT]
if tf_backend_git.git_backend_token != "":
return {
"GITHUB_TOKEN" : tf_backend_git.git_backend_token,
"GIT_USERNAME" : tf_backend_git.git_backend_username,
}
return {"" : ""}
def backend_config(self) -> Dict[str, Any]: def backend_config(self) -> Dict[str, Any]:
result = {} result = {}
for provider in self.providers.values(): for provider in self.providers.values():

View file

@ -1,4 +1,5 @@
from subprocess import Popen, PIPE, run, CalledProcessError from subprocess import Popen, PIPE, run, CalledProcessError
from typing import Dict
from pathlib import Path from pathlib import Path
from sys import stdout from sys import stdout
from os import chmod, environ from os import chmod, environ
@ -218,8 +219,11 @@ class TerraformApi:
class TerraformBackendGitApi: class TerraformBackendGitApi:
def __init__(self): def __init__(self):
self.execution_api = ExecutionApi() self.execution_api = ExecutionApi()
def start(self): def start(self, credentials: Dict[str, str]):
self.execution_api.execute("terraform-backend-git &") env = ""
for key in credentials:
env = env + f'{key}' + "=" + f'{credentials[key]}' + " "
self.execution_api.execute(f'{env}' + " " + "terraform-backend-git &")
def stop(self): def stop(self):
self.execution_api.execute("terraform-backend-git stop") self.execution_api.execute("terraform-backend-git stop")