lint: reformat python code with black
This commit is contained in:
parent
331beb01b4
commit
a406a7974b
88 changed files with 2579 additions and 1608 deletions
|
@ -51,14 +51,20 @@ class TerraformAutomation(BaseAutomation):
|
|||
prehook_result = self.tf_prehook() # pylint: disable=assignment-from-no-return
|
||||
self.tf_generate()
|
||||
self.tf_init()
|
||||
returncode, logs = self.tf_apply(self.working_dir, refresh=self.always_refresh or full)
|
||||
returncode, logs = self.tf_apply(
|
||||
self.working_dir, refresh=self.always_refresh or full
|
||||
)
|
||||
self.tf_posthook(prehook_result=prehook_result)
|
||||
return returncode == 0, logs
|
||||
|
||||
def tf_apply(self, working_dir: str, *,
|
||||
refresh: bool = True,
|
||||
parallelism: Optional[int] = None,
|
||||
lock_timeout: int = 15) -> Tuple[int, str]:
|
||||
def tf_apply(
|
||||
self,
|
||||
working_dir: str,
|
||||
*,
|
||||
refresh: bool = True,
|
||||
parallelism: Optional[int] = None,
|
||||
lock_timeout: int = 15,
|
||||
) -> Tuple[int, str]:
|
||||
if not parallelism:
|
||||
parallelism = self.parallelism
|
||||
if not self.working_dir:
|
||||
|
@ -67,17 +73,19 @@ class TerraformAutomation(BaseAutomation):
|
|||
# the argument list as an array such that argument injection would be
|
||||
# ineffective.
|
||||
tfcmd = subprocess.run( # nosec
|
||||
['terraform',
|
||||
'apply',
|
||||
'-auto-approve',
|
||||
'-json',
|
||||
f'-refresh={str(refresh).lower()}',
|
||||
f'-parallelism={str(parallelism)}',
|
||||
f'-lock-timeout={str(lock_timeout)}m',
|
||||
],
|
||||
[
|
||||
"terraform",
|
||||
"apply",
|
||||
"-auto-approve",
|
||||
"-json",
|
||||
f"-refresh={str(refresh).lower()}",
|
||||
f"-parallelism={str(parallelism)}",
|
||||
f"-lock-timeout={str(lock_timeout)}m",
|
||||
],
|
||||
cwd=working_dir,
|
||||
stdout=subprocess.PIPE)
|
||||
return tfcmd.returncode, tfcmd.stdout.decode('utf-8')
|
||||
stdout=subprocess.PIPE,
|
||||
)
|
||||
return tfcmd.returncode, tfcmd.stdout.decode("utf-8")
|
||||
|
||||
@abstractmethod
|
||||
def tf_generate(self) -> None:
|
||||
|
@ -91,41 +99,49 @@ class TerraformAutomation(BaseAutomation):
|
|||
# the argument list as an array such that argument injection would be
|
||||
# ineffective.
|
||||
subprocess.run( # nosec
|
||||
['terraform',
|
||||
'init',
|
||||
f'-lock-timeout={str(lock_timeout)}m',
|
||||
],
|
||||
cwd=self.working_dir)
|
||||
[
|
||||
"terraform",
|
||||
"init",
|
||||
f"-lock-timeout={str(lock_timeout)}m",
|
||||
],
|
||||
cwd=self.working_dir,
|
||||
)
|
||||
|
||||
def tf_output(self) -> Any:
|
||||
if not self.working_dir:
|
||||
raise RuntimeError("No working directory specified.")
|
||||
# The following subprocess call does not take any user input.
|
||||
tfcmd = subprocess.run( # nosec
|
||||
['terraform', 'output', '-json'],
|
||||
["terraform", "output", "-json"],
|
||||
cwd=self.working_dir,
|
||||
stdout=subprocess.PIPE)
|
||||
stdout=subprocess.PIPE,
|
||||
)
|
||||
return json.loads(tfcmd.stdout)
|
||||
|
||||
def tf_plan(self, *,
|
||||
refresh: bool = True,
|
||||
parallelism: Optional[int] = None,
|
||||
lock_timeout: int = 15) -> Tuple[int, str]:
|
||||
def tf_plan(
|
||||
self,
|
||||
*,
|
||||
refresh: bool = True,
|
||||
parallelism: Optional[int] = None,
|
||||
lock_timeout: int = 15,
|
||||
) -> Tuple[int, str]:
|
||||
if not self.working_dir:
|
||||
raise RuntimeError("No working directory specified.")
|
||||
# The following subprocess call takes external input, but is providing
|
||||
# the argument list as an array such that argument injection would be
|
||||
# ineffective.
|
||||
tfcmd = subprocess.run( # nosec
|
||||
['terraform',
|
||||
'plan',
|
||||
'-json',
|
||||
f'-refresh={str(refresh).lower()}',
|
||||
f'-parallelism={str(parallelism)}',
|
||||
f'-lock-timeout={str(lock_timeout)}m',
|
||||
],
|
||||
cwd=self.working_dir)
|
||||
return tfcmd.returncode, tfcmd.stdout.decode('utf-8')
|
||||
[
|
||||
"terraform",
|
||||
"plan",
|
||||
"-json",
|
||||
f"-refresh={str(refresh).lower()}",
|
||||
f"-parallelism={str(parallelism)}",
|
||||
f"-lock-timeout={str(lock_timeout)}m",
|
||||
],
|
||||
cwd=self.working_dir,
|
||||
)
|
||||
return tfcmd.returncode, tfcmd.stdout.decode("utf-8")
|
||||
|
||||
def tf_posthook(self, *, prehook_result: Any = None) -> None:
|
||||
"""
|
||||
|
@ -154,9 +170,8 @@ class TerraformAutomation(BaseAutomation):
|
|||
raise RuntimeError("No working directory specified.")
|
||||
# This subprocess call doesn't take any user input.
|
||||
terraform = subprocess.run( # nosec
|
||||
['terraform', 'show', '-json'],
|
||||
cwd=self.working_dir,
|
||||
stdout=subprocess.PIPE)
|
||||
["terraform", "show", "-json"], cwd=self.working_dir, stdout=subprocess.PIPE
|
||||
)
|
||||
return json.loads(terraform.stdout)
|
||||
|
||||
def tf_write(self, template: str, **kwargs: Any) -> None:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue