How to use the colin.core.result.CheckResult function in colin

To help you get started, we’ve selected a few colin examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github user-cont / colin / colin / core / checks / cmd.py View on Github external
passed = False

        if self.expected_regex is not None:
            pattern = re.compile(self.expected_regex)
            if pattern.match(output):
                logs.append("ok: Output of the command '{}' match the regex '{}'." \
                            .format(self.cmd, self.expected_regex))
            else:
                logs.append(
                    "nok: Output of the command '{}' does not match"
                    " the expected regex: '{}'.".format(self.cmd, self.expected_regex))

                passed = False

        return CheckResult(ok=passed,
                           description=self.description,
                           message=self.message,
                           reference_url=self.reference_url,
                           check_name=self.name,
                           logs=logs)
github user-cont / colin / colin / core / result.py View on Github external
self.description = description
        self.message = message
        self.reference_url = reference_url
        self.check_name = check_name
        self.logs = logs

    @property
    def status(self):
        return PASSED if self.ok else FAILED

    def __str__(self):
        return "{}:{}".format(self.status,
                              self.message)


class DockerfileCheckResult(CheckResult):

    def __init__(self, ok, description, message, reference_url, check_name, lines=None,
                 correction_diff=None):
        super(DockerfileCheckResult, self) \
            .__init__(ok, description, message, reference_url, check_name)
        self.lines = lines
        self.correction_diff = correction_diff


class CheckResults(object):

    def __init__(self, results):
        self.results = CachingIterable(results)

    @property
    def results_per_check(self):
github user-cont / colin / colin / core / checks / labels.py View on Github external
def check(self, target):
        passed = True
        logs = []

        if target.parent_target:
            labels_to_check = (set(self.labels_list) & set(target.labels)
                               & set(target.parent_target.labels))
            for label in labels_to_check:
                if target.labels[label] == target.parent_target.labels[label]:
                    passed = False
                    log = "optional label inherited: {}".format(label)
                    logs.append(log)
                    logger.debug(log)

        return CheckResult(ok=passed,
                           description=self.description,
                           message=self.message,
                           reference_url=self.reference_url,
                           check_name=self.name,
                           logs=logs)
github user-cont / colin / colin / core / checks / filesystem.py View on Github external
for f in self.files:
            cmd = ["/bin/ls", "-1", f]
            try:
                f_present = cont.execute(cmd)
                logs.append("File '{}' is {}present."
                            .format(f, "" if f_present else "not "))
            except ConuException as ex:
                logger.info("File %s is not present, ex: %s", f, ex)
                f_present = False
                logs.append("File {} is not present.".format(f))
            if self.all_must_be_present:
                passed = f_present and passed
            else:
                passed = f_present or passed

        return CheckResult(ok=passed,
                           description=self.description,
                           message=self.message,
                           reference_url=self.reference_url,
                           check_name=self.name,
                           logs=logs)
github user-cont / colin / colin / checks / best_practices.py View on Github external
def check(self, target):
        metadata = target.config_metadata
        root_present = "User" in metadata and metadata["User"] in ["", "0", "root"]

        return CheckResult(ok=not root_present,
                           description=self.description,
                           message=self.message,
                           reference_url=self.reference_url,
                           check_name=self.name,
                           logs=[])
github user-cont / colin / colin / core / checks / dockerfile.py View on Github external
def check(self, target):
        instructions = get_instructions_from_dockerfile_parse(target.instance, self.instruction)
        pattern = re.compile(self.value_regex)
        logs = []
        passed = True
        for inst in instructions:
            match = bool(pattern.match(inst["value"]))
            passed = match == self.required
            log = "Value for instruction {} " \
                  "{}mach regex: '{}'.".format(inst["content"],
                                               "" if match else "does not ",
                                               self.value_regex)
            logs.append(log)
            logger.debug(log)

        return CheckResult(ok=passed,
                           description=self.description,
                           message=self.message,
                           reference_url=self.reference_url,
                           check_name=self.name,
                           logs=logs)
github user-cont / colin / colin / core / checks / filesystem.py View on Github external
f_present = target.file_is_present(f)
                logs.append("File '{}' is {}present."
                            .format(f, "" if f_present else "not "))
            except IOError as ex:
                logger.info("File %s is not present, ex: %s", f, ex)
                f_present = False
                logs.append("File {} is not present.".format(f))
            if self.all_must_be_present:
                passed = f_present and passed
            else:
                passed = f_present or passed

        for log in logs:
            logger.debug(log)

        return CheckResult(ok=passed,
                           description=self.description,
                           message=self.message,
                           reference_url=self.reference_url,
                           check_name=self.name,
                           logs=logs)
github user-cont / colin / colin / checks / dockerfile.py View on Github external
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=[])
github user-cont / colin / colin / core / result.py View on Github external
def get_pretty_string(self, stat, verbose):
        """
        Pretty string representation of the results

        :param stat: bool
        :param verbose: bool
        :return: str
        """
        pretty_output = _PrettyOutputToStr()
        self.generate_pretty_output(stat=stat,
                                    verbose=verbose,
                                    output_function=pretty_output.save_output)
        return pretty_output.result


class FailedCheckResult(CheckResult):

    def __init__(self, check, logs=None):
        super(FailedCheckResult, self) \
            .__init__(ok=False,
                      message=check.message,
                      description=check.description,
                      reference_url=check.reference_url,
                      check_name=check.name,
                      logs=logs or []
                      )

    @property
    def status(self):
        return ERROR