コード例 #1
0
ファイル: image.py プロジェクト: wjsetzer/content
    def __init__(self, file_path):
        self._is_valid = True

        if re.match(INTEGRATION_REGEX, file_path, re.IGNORECASE):
            self.file_path = file_path
        else:
            if re.match(INTEGRATION_YML_REGEX, file_path, re.IGNORECASE):
                try:
                    self.file_path = glob.glob(os.path.join(os.path.dirname(file_path), '*.png'))[0]
                except IndexError:
                    self._is_valid = False
                    print_error("You've created/modified a package but failed to provide an image as a .png file, "
                                "please add an image in order to proceed.")
コード例 #2
0
ファイル: description.py プロジェクト: whtnw/content
    def is_duplicate_description(self):
        """Check if the integration has a non-duplicate description ."""
        is_description_in_yml = False
        is_description_in_package = False
        package_path = None
        md_file_path = None
        if not re.match(INTEGRATION_REGEX, self.file_path, re.IGNORECASE):
            package_path = os.path.dirname(self.file_path)
            try:
                md_file_path = glob.glob(os.path.join(os.path.dirname(self.file_path), '*.md'))[0]
            except IndexError:
                print_error("No description file was found in the package {}."
                            " Consider adding one.".format(package_path))
            if md_file_path:
                is_description_in_package = True

        data_dictionary = get_yaml(self.file_path)

        if not data_dictionary:
            return is_description_in_package

        if data_dictionary.get('detaileddescription'):
            is_description_in_yml = True

        if is_description_in_package and is_description_in_yml:
            self._is_valid = False
            print_error("A description was found both in the package and in the yml, "
                        "please update the package {}.".format(package_path))
            return False

        return True
コード例 #3
0
    def is_existing_image(self):
        """Check if the integration has an image."""
        is_image_in_yml = False
        is_image_in_package = False

        data_dictionary = get_yaml(self.file_path)

        if not data_dictionary:
            return False

        if data_dictionary.get('image'):
            is_image_in_yml = True

        if not re.match(INTEGRATION_REGEX, self.file_path, re.IGNORECASE):
            package_path = os.path.dirname(self.file_path)
            if is_image_in_yml:
                print_error(
                    "You have added an image in the yml "
                    "file, please update the package {}".format(package_path))
                return False
            image_path = glob.glob(package_path + '/*.png')
            if image_path:
                is_image_in_package = True

        if not (is_image_in_package or is_image_in_yml):
            print_error(
                "You have failed to add an image in the yml/package for {}".
                format(self.file_path))
            self._is_valid = False
            return False

        return True
コード例 #4
0
    def oversize_image(self):
        """Check if the image if over sized, bigger than IMAGE_MAX_SIZE"""
        if re.match(IMAGE_REGEX, self.file_path, re.IGNORECASE):
            if os.path.getsize(
                    self.file_path
            ) > self.IMAGE_MAX_SIZE:  # disable-secrets-detection
                print_error(
                    "{} has too large logo, please update the logo to be under 10kB"
                    .format(self.file_path))
                self._is_valid = False

        else:
            data_dictionary = get_yaml(self.file_path)

            if not data_dictionary:
                return

            image = data_dictionary.get('image', '')

            if ((len(image) - 22) / 4.0
                ) * 3 > self.IMAGE_MAX_SIZE:  # disable-secrets-detection
                print_error(
                    "{} has too large logo, please update the logo to be under 10kB"
                    .format(self.file_path))
                self._is_valid = False
コード例 #5
0
    def load_image(self):
        if re.match(IMAGE_REGEX, self.file_path, re.IGNORECASE):
            with open(self.file_path, "rb") as image:
                image_data = image.read()
                image = base64.b64encode(image_data)
                if isinstance(image, bytes):
                    image = image.decode("utf-8")

        else:
            image = self.load_image_from_yml()

        return image
コード例 #6
0
ファイル: description.py プロジェクト: yhager/demisto-content
    def is_valid_beta_description(self):
        """Check if beta disclaimer exists in detailed description"""
        data_dictionary = get_yaml(self.file_path)
        description_in_yml = data_dictionary.get('detaileddescription',
                                                 '') if data_dictionary else ''

        if not re.match(BETA_INTEGRATION_REGEX, self.file_path, re.IGNORECASE):
            package_path = os.path.dirname(self.file_path)
            try:
                md_file_path = glob.glob(
                    os.path.join(os.path.dirname(self.file_path),
                                 '*_description.md'))[0]
            except IndexError:
                self._is_valid = False
                print_error(
                    "No detailed description file was found in the package {}. Please add one,"
                    " and make sure it includes the beta disclaimer note."
                    "It should contain the string in constant"
                    "\"BETA_INTEGRATION_DISCLAIMER\"".format(package_path))
                return False

            with open(md_file_path) as description_file:
                description = description_file.read()
            if BETA_INTEGRATION_DISCLAIMER not in description:
                self._is_valid = False
                print_error(
                    "Detailed description in beta integration package {} "
                    "dose not contain the beta disclaimer note. "
                    "It should contain the string in constant"
                    " \"BETA_INTEGRATION_DISCLAIMER\".".format(package_path))
                return False
            else:
                return True
        elif BETA_INTEGRATION_DISCLAIMER not in description_in_yml:
            self._is_valid = False
            print_error("Detailed description field in beta integration {} "
                        "dose not contain the beta disclaimer note."
                        "It should contain the string in constant"
                        " \"BETA_INTEGRATION_DISCLAIMER\".".format(
                            self.file_path))
            return False
        return True