Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def bad_fce():
raise ColinException("Error")
def get_instance(target_type, **kwargs):
"""
:param target_type: string, either image, dockertar, ostree or dockerfile
"""
if target_type in TARGET_TYPES:
cls = TARGET_TYPES[target_type]
try:
return cls(**kwargs)
except Exception:
logger.error("Please make sure that you picked the correct target type: "
"--target-type CLI option.")
raise
raise ColinException(
"Unknown target type '{}'. Please make sure that you picked the correct target type: "
"--target-type CLI option.".format(target_type))
def read_file(self, file_path):
"""
read file specified via 'file_path' and return its content - raises an ConuException if
there is an issue accessing the file
:param file_path: str, path to the file to read
:return: str (not bytes), content of the file
"""
try:
with open(self.cont_path(file_path)) as fd:
return fd.read()
except IOError as ex:
logger.error("error while accessing file %s: %r", file_path, ex)
raise ColinException(
"There was an error while accessing file %s: %r" % (file_path, ex))
output = target.get_output(cmd=self.cmd)
"""
except ConuException as ex:
if str(ex).endswith("exit code 126") or str(ex).endswith("error: 127"):
return CheckResult(ok=False,
description=self.description,
message=self.message,
reference_url=self.reference_url,
check_name=self.name,
logs=["exec: '{}': executable file not found in $PATH".format(
self.cmd)])
return FailedCheckResult(check=self,
logs=[str(ex)])
"""
except ColinException as ex:
return FailedCheckResult(check=self,
logs=[str(ex)])
passed = True
logs = ["Output:\n{}".format(output)]
if self.substring is not None:
substring_present = self.substring in output
passed = passed and substring_present
logs.append("{}: Substring '{}' is {}present in the output of the command '{}'." \
.format("ok" if substring_present else "nok",
self.substring,
"" if substring_present else "not ",
self.cmd))
if self.expected_output is not None:
expected_output = self.expected_output == output
if expected_output:
def check(self, target):
raise ColinException(self.message)
logger.debug("Pulling an image.")
cmd_pull = ["podman", "pull", "--quiet", self.target_name]
result_pull = subprocess.run(cmd_pull,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
if result_pull.returncode == 0:
self.image_id = result_pull.stdout.decode().rstrip()
logger.debug("Image pulled with id: '{}'.".format(self.image_id))
else:
raise ColinException(
"Cannot pull an image: '{}'.".format(self.target_name))
else:
raise ColinException("Image '{}' not found.".format(self.target_name))
else:
raise ColinException("Podman error: {}".format(result.stderr))
def check(self, target):
if not target.instance.parent_images:
raise ColinException("Cannot find FROM instruction.")
im = ImageName.parse(target.instance.baseimage)
passed = im.tag and im.tag != "latest"
return CheckResult(ok=passed,
description=self.description,
message=self.message,
reference_url=self.reference_url,
check_name=self.name,
logs=[])
if not debug:
logging.basicConfig(stream=six.StringIO())
log_level = _get_log_level(debug=debug,
verbose=verbose)
checks = get_checks(ruleset_name=ruleset,
ruleset_file=ruleset_file,
logging_level=log_level,
tags=tag,
checks_paths=checks_paths,
skips=skip)
_print_checks(checks=checks)
if json:
AbstractCheck.save_checks_to_json(file=json, checks=checks)
except ColinException as ex:
logger.error("An error occurred: %r", ex)
if debug:
raise
else:
raise click.ClickException(str(ex))
except Exception as ex:
logger.error("An error occurred: %r", ex)
if debug:
raise
else:
raise click.ClickException(str(ex))