コード例 #1
0
    def update_docker_image_in_script(script_obj: dict, from_version: Optional[str] = None):
        """Update the docker image for the passed script object. Will ignore if this is a javascript
        object or using default image (not set).

        Args:
            script_obj (dict): script object
        """
        if script_obj.get('type') == TYPE_JS:
            print_color('Skipping docker image update as this is a Javascript automation.', LOG_COLORS.YELLOW)
            return
        dockerimage = script_obj.get('dockerimage')
        if not dockerimage:  # default image -> nothing to do
            print_color('Skipping docker image update as default docker image is being used.', LOG_COLORS.YELLOW)
            return
        image_name = dockerimage.split(':')[0]
        latest_tag = DockerImageValidator.get_docker_image_latest_tag_request(image_name)
        full_name = f'{image_name}:{latest_tag}'
        if full_name != dockerimage:
            print(f'Updating docker image to: {full_name}')
            script_obj['dockerimage'] = full_name
            if (not from_version) or server_version_compare('5.0.0', from_version):
                # if this is a script that supports 4.5 and earlier. Make sure dockerimage45 is set
                if not script_obj.get('dockerimage45'):
                    print(f'Setting dockerimage45 to previous image value: {dockerimage} for 4.5 and earlier support')
                    script_obj['dockerimage45'] = dockerimage
        else:
            print(f'Already using latest docker image: {dockerimage}. Nothing to update.')
コード例 #2
0
def get_docker_image():
    try:
        latest_tag = DockerImageValidator.get_docker_image_latest_tag_request(
            'demisto/python3')
        docker_image = f'demisto/python3:{latest_tag}'
        logger.debug(f'docker image set to: {docker_image}')
    except Exception as e:
        # set default docker image
        docker_image = 'demisto/python3:3.9.1.14969'
        logger.warning(
            f'Failed getting latest docker image for demisto/python3: {e}')
    return docker_image
コード例 #3
0
    def generate_configuration(self):
        """
        Generates an integration configuration file according to parsed functions from a swagger file.
        """

        security_types: list = []
        if self.security_definitions:
            all_security_types = [
                s.get('type') for s in self.security_definitions.values()
            ]
            security_types = [
                t for t in all_security_types
                if t in [BEARER_AUTH_TYPE, BASIC_AUTH_TYPE]
            ]
        if not security_types:
            security_types = [BEARER_AUTH_TYPE]

        configuration = {
            'name': self.name or 'GeneratedIntegration',
            'description': self.description
            or 'This integration was auto generated by the Cortex XSOAR SDK.',
            'category': 'Utilities',
            'url': self.host or DEFAULT_HOST,
            'auth': security_types,
            'context_path': self.context_path,
            'commands': []
        }
        for function in self.functions:
            command = {
                'name': function['name'].replace('_', '-'),
                'path': function['path'],
                'method': function['method'],
                'description': function['description'],
                'arguments': [],
                'outputs': [],
                'context_path': function.get('context_path', ''),
                'root_object': function.get('root_object', '')
            }

            headers = []
            if function['consumes'] and JSON_TYPE_HEADER not in function['consumes'] \
                    and ALL_TYPE_HEADER not in function['consumes']:
                headers.append({'Content-Type': function['consumes'][0]})

            if function['produces'] and JSON_TYPE_HEADER not in function['produces'] \
                    and ALL_TYPE_HEADER not in function['produces']:
                headers.append({'Accept': function['produces'][0]})
            command['headers'] = headers

            for arg in function['arguments']:
                command['arguments'].append({
                    'name':
                    str(arg.get('name', '')),
                    'description':
                    arg.get('description', ''),
                    'required':
                    arg.get('required'),
                    'default':
                    arg.get('default', ''),
                    'in':
                    arg.get('in', ''),
                    'ref':
                    arg.get('ref', ''),
                    'type':
                    arg.get('type', 'string'),
                    'options':
                    arg.get('enums'),
                    'properties':
                    arg.get('properties', {})
                })

            for output in function['outputs']:
                command['outputs'].append({
                    'name': output['name'],
                    'description': output['description'],
                    'type': output['type']
                })

                if output['name'] in self.unique_keys:
                    command['unique_key'] = output['name']

            if 'unique_key' not in command:
                command['unique_key'] = ''

            configuration['commands'].append(command)  # type: ignore

        configuration['code_type'] = 'python'
        configuration['code_subtype'] = 'python3'

        try:
            latest_tag = DockerImageValidator.get_docker_image_latest_tag_request(
                'demisto/python3')
            configuration['docker_image'] = f'demisto/python3:{latest_tag}'
        except Exception as e:
            self.print_with_verbose(
                f'Failed getting latest docker image for demisto/python3: {e}')

        self.configuration = configuration