<commit_before>"""
Reads input from OpenShift v3
"""
import json
import os

from dock.plugin import InputPlugin


class OSv3InputPlugin(InputPlugin):
    key = "osv3"

    def __init__(self):
        """
        constructor
        """
        # call parent constructor
        super(OSv3InputPlugin, self).__init__()

    def run(self):
        """
        each plugin has to implement this method -- it is used to run the plugin actually

        response from plugin is kept and used in json result response
        """
        build_json_str = os.environ['BUILD']
        build_json = json.loads(build_json_str)
        git_url = os.environ['SOURCE_URI']
        git_ref = os.environ.get('SOURCE_REF', None)
        image = os.environ['OUTPUT_IMAGE']
        target_registry = os.environ.get('OUTPUT_REGISTRY', None)
        plugins_json = os.environ.get('DOCK_PLUGINS', {})

        return {
            'git_url': git_url,
            'image': image,
            'git_commit': git_ref,
            'target_registries': [target_registry] if target_registry is not None else None,
            'prebuild_plugins': plugins_json.get('prebuild_plugins', None),
            'postbuild_plugins': plugins_json.get('postbuild_plugins', None),
        }<commit_msg>osv3 plugin: load the json string actually<commit_after>"""
Reads input from OpenShift v3
"""
import json
import os

from dock.plugin import InputPlugin


class OSv3InputPlugin(InputPlugin):
    key = "osv3"

    def __init__(self):
        """
        constructor
        """
        # call parent constructor
        super(OSv3InputPlugin, self).__init__()

    def run(self):
        """
        each plugin has to implement this method -- it is used to run the plugin actually

        response from plugin is kept and used in json result response
        """
        build_json_str = os.environ['BUILD']
        build_json = json.loads(build_json_str)
        git_url = os.environ['SOURCE_URI']
        git_ref = os.environ.get('SOURCE_REF', None)
        image = os.environ['OUTPUT_IMAGE']
        target_registry = os.environ.get('OUTPUT_REGISTRY', None)
        plugins_json = os.environ.get('DOCK_PLUGINS', '{}')
        plugins_json = json.loads(plugins_json)

        input_json = {
            'git_url': git_url,
            'image': image,
            'git_commit': git_ref,
            'target_registries': [target_registry] if target_registry is not None else None,
            'prebuild_plugins': plugins_json.get('prebuild_plugins', None),
            'postbuild_plugins': plugins_json.get('postbuild_plugins', None),
        }

        self.log.debug("build json: %s", input_json)

        return input_json
{'fraction_non_alphanumeric': 0.10387192851824274, 'fraction_numerical': 0.0033507073715562173, 'mean_word_length': 2.5078328981723237, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4196461', 'n_tokens_mistral': 777, 'n_tokens_neox': 777, 'n_words': 198}