Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
tf_bin = TFEnvManager(self.path).install()
elif os.path.isfile(os.path.join(self.context.env_root,
'.terraform-version')):
tf_bin = TFEnvManager(self.context.env_root).install()
else:
if not which('terraform'):
LOGGER.error('Terraform not available (a '
'".terraform-version" file is not present '
'and "terraform" not found in path). Fix '
'this by writing a desired Terraform version '
'to your module\'s .terraform-version file '
'or installing Terraform.')
sys.exit(1)
tf_bin = 'terraform'
tf_cmd.insert(0, tf_bin)
with change_dir(self.path):
if os.path.isfile(os.path.join(self.path, '.terraform', FAILED_INIT_FILENAME)):
LOGGER.info('Previous init failed; trashing '
'.terraform directory...')
send2trash(os.path.join(self.path, '.terraform'))
LOGGER.info('Running "terraform init"...')
run_terraform_init(
tf_bin=tf_bin,
module_path=self.path,
module_options=options,
env_name=self.context.env_name,
env_region=self.context.env_region,
env_vars=env_vars,
no_color=self.context.no_color
)
if self.context.no_color:
cdk_opts.append('--no-color')
if not which('npm'):
LOGGER.error('"npm" not found in path or is not executable; '
'please ensure it is installed correctly.')
sys.exit(1)
if 'DEBUG' in self.context.env_vars:
cdk_opts.append('-v') # Increase logging if requested
warn_on_boto_env_vars(self.context.env_vars)
if self.options['environment']:
if os.path.isfile(os.path.join(self.path, 'package.json')):
with change_dir(self.path):
run_npm_install(self.path, self.options, self.context)
if self.options.get('options', {}).get('build_steps',
[]):
LOGGER.info("Running build steps for %s...",
os.path.basename(self.path))
run_commands(
commands=self.options.get('options',
{}).get('build_steps',
[]),
directory=self.path,
env=self.context.env_vars
)
cdk_context_opts = []
for (key, val) in self.options['parameters'].items():
cdk_context_opts.extend(['-c', "%s=%s" % (key, val)])
cdk_opts.extend(cdk_context_opts)
os.path.dirname(os.path.dirname(os.path.abspath(__file__))), # noqa
'templates',
'.flake8'
))
]
if os.path.isfile(os.path.join(base_dir, '.yamllint')):
yamllint_config = os.path.join(base_dir, '.yamllint')
elif os.path.isfile(os.path.join(base_dir, '.yamllint.yml')):
yamllint_config = os.path.join(base_dir, '.yamllint.yml')
else:
yamllint_config = os.path.join(
os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
'templates',
'.yamllint.yml'
)
with change_dir(base_dir):
with ignore_exit_code_0():
LOGGER.info('Starting Flake8 linting...')
flake8_run = flake8_app.Application()
flake8_run.run(
flake8_config + dirs_to_scan + self.get_python_files_at_env_root() # noqa pylint: disable=line-too-long
)
flake8_run.exit()
with ignore_exit_code_0():
LOGGER.info('Flake8 linting complete.')
LOGGER.info('Starting yamllint...')
yamllint_run(
["--config-file=%s" % yamllint_config] + dirs_to_scan + self.get_yaml_files_at_env_root() # noqa pylint: disable=line-too-long
)
LOGGER.info('yamllint complete.')
def get_hash_of_files(root_path, directories=None):
"""Generate md5 hash of files."""
if not directories:
directories = [{'path': './'}]
files_to_hash = []
for i in directories:
ignorer = get_ignorer(os.path.join(root_path, i['path']),
i.get('exclusions'))
with change_dir(root_path):
for root, dirs, files in os.walk(i['path'], topdown=True):
if (root != './') and ignorer.is_ignored(root, True):
dirs[:] = []
files[:] = []
else:
for filename in files:
filepath = os.path.join(root, filename)
if not ignorer.is_ignored(filepath):
files_to_hash.append(
filepath[2:] if filepath.startswith('./') else filepath # noqa
)
return calculate_hash_of_files(files_to_hash, root_path)
context.env_name,
context.env_region)
LOGGER.info("Module options: %s", module_opts)
if module_opts.get('env_vars'):
module_env_vars = merge_nested_environment_dicts(
module_opts.get('env_vars'), env_name=context.env_name,
env_root=self.env_root
)
if module_env_vars:
context = copy.deepcopy(context) # changes for this mod only
LOGGER.info("OS environment variable overrides being "
"applied to this module: %s",
str(module_env_vars))
context.env_vars = merge_dicts(context.env_vars, module_env_vars)
with change_dir(path.module_root):
runway_module_type = RunwayModuleType(path.module_root,
module_opts.get('class_path'),
module_opts.get('type'))
# dynamically load the particular module's class, 'get' the method
# associated with the command, and call the method
module_instance = runway_module_type.module_class(
context=context,
path=path.module_root,
options=module_opts
)
if hasattr(module_instance, context.command):
module_instance[context.command]()
else:
LOGGER.error("'%s' is missing method '%s'",