How to use the colin.core.checks.abstract_check.ImageAbstractCheck 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 / envs.py View on Github external
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see .
#

import re

from .abstract_check import ImageAbstractCheck
from ..result import CheckResult


class EnvCheck(ImageAbstractCheck):

    def __init__(self, message, description, reference_url, tags, env_var, required,
                 value_regex=None):
        super(EnvCheck, self) \
            .__init__(message, description, reference_url, tags)
        self.env_var = env_var
        self.required = required
        self.value_regex = value_regex

    def check(self, target):
        env_vars = target.config_metadata["Env"]

        env_vars_dict = {}
        if env_vars:
            for key_value in env_vars:
                key, value = key_value.split("=")
github user-cont / colin / colin / checks / best_practices.py View on Github external
logger.debug(msg_entrypoint_present)

        passed = cmd_present or entrypoint_present
        return CheckResult(ok=passed,
                           description=self.description,
                           message=self.message,
                           reference_url=self.reference_url,
                           check_name=self.name,
                           logs=[msg_cmd_present, msg_entrypoint_present])


class HelpFileOrReadmeCheck(FMFAbstractCheck, FileCheck):
    name = "help_file_or_readme"


class NoRootCheck(FMFAbstractCheck, ImageAbstractCheck):
    name = "no_root"

    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 / target.py View on Github external
def get_compatible_check_class(cls):
        return ImageAbstractCheck
github user-cont / colin / colin / core / checks / labels.py View on Github external
def check(self, target):
        labels = target.labels
        old_present = labels is not None and self.old_label in labels

        passed = (not old_present) or (self.new_label in labels)

        return CheckResult(ok=passed,
                           description=self.description,
                           message=self.message,
                           reference_url=self.reference_url,
                           check_name=self.name,
                           logs=[])


class InheritedOptionalLabelAbstractCheck(ImageAbstractCheck):

    def __init__(self, message, description, reference_url, tags):
        """
        Abstract check for Dockerfile/Image labels.

        :param message: str
        :param description: str
        :param reference_url: str
        :param tags: [str]
        """
        super(InheritedOptionalLabelAbstractCheck, self) \
            .__init__(message, description, reference_url, tags)
        self.labels_list = []

    def check(self, target):
        passed = True
github user-cont / colin / colin / checks / best_practices.py View on Github external
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see .
#

import logging

from colin.core.checks.filesystem import FileCheck
from colin.core.checks.fmf_check import FMFAbstractCheck
from colin.core.checks.abstract_check import ImageAbstractCheck
from colin.core.result import CheckResult

logger = logging.getLogger(__name__)


class CmdOrEntrypointCheck(FMFAbstractCheck, ImageAbstractCheck):
    name = "cmd_or_entrypoint"

    def check(self, target):
        metadata = target.config_metadata["ContainerConfig"]
        cmd_present = "Cmd" in metadata and metadata["Cmd"]
        msg_cmd_present = "Cmd {}specified.".format("" if cmd_present else "not ")
        logger.debug(msg_cmd_present)

        entrypoint_present = "Entrypoint" in metadata and metadata["Entrypoint"]
        msg_entrypoint_present = "Entrypoint {}specified.".format(
            "" if entrypoint_present else "not ")
        logger.debug(msg_entrypoint_present)

        passed = cmd_present or entrypoint_present
        return CheckResult(ok=passed,
                           description=self.description,
github user-cont / colin / colin / core / checks / filesystem.py View on Github external
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see .
#
import logging

from conu.exceptions import ConuException

from .abstract_check import ImageAbstractCheck
from ..result import CheckResult

logger = logging.getLogger(__name__)


class FileCheck(ImageAbstractCheck):
    """ Check presence of files; w/o mounting the whole FS """

    def __init__(self, message, description, reference_url, tags, files, all_must_be_present):
        super(FileCheck, self) \
            .__init__(message, description, reference_url, tags)
        self.files = files
        self.all_must_be_present = all_must_be_present

    def _handle_image(self, target):
        passed = self.all_must_be_present

        logs = []
        for f in self.files:
            try:
                f_present = target.file_is_present(f)
                logs.append("File '{}' is {}present."
github user-cont / colin / colin / core / checks / cmd.py View on Github external
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see .
#
import re

from .abstract_check import ImageAbstractCheck
from ..exceptions import ColinException
from ..result import CheckResult, FailedCheckResult


class CmdAbstractCheck(ImageAbstractCheck):

    def __init__(self, message, description, reference_url, tags, cmd, expected_output=None,
                 expected_regex=None,
                 substring=None):
        super(CmdAbstractCheck, self).__init__(message, description, reference_url, tags)
        self.cmd = cmd
        self.expected_output = expected_output
        self.expected_regex = expected_regex
        self.substring = substring

    def check(self, target):

        try:
            output = target.get_output(cmd=self.cmd)

            """