Esempio n. 1
0
 def create_default_script(self):
     default_script_dir = 'assets/default_script'
     code = open(suite_join_path(default_script_dir, 'sample_script.py'))
     yml = open(suite_join_path(default_script_dir, 'sample_script.yml'))
     image = open(
         suite_join_path(default_script_dir, 'sample_script_image.png'),
         'rb')
     changelog = open(suite_join_path(default_script_dir, 'CHANGELOG.md'))
     description = open(
         suite_join_path(default_script_dir,
                         'sample_script_description.md'))
     self.build(code=str(code.read()),
                yml=yaml.load(yml, Loader=yaml.FullLoader),
                image=image.read(),
                changelog=str(changelog.read()),
                description=str(description.read()))
     yml.close()
     image.close()
     changelog.close()
     description.close()
     code.close()
     if self.create_unified:
         unifier = Unifier(input=self.path,
                           output=os.path.dirname(
                               self._tmpdir_integration_path))
         unifier.merge_script_package_to_yml()
         shutil.rmtree(self._tmpdir_integration_path)
Esempio n. 2
0
    def create_default_script(self, name: str = 'sample_script'):
        """Creates a new script with basic data.

        Args:
            name: The name and ID of the new script, default is "sample_script".

        """

        default_script_dir = 'assets/default_script'

        with open(suite_join_path(default_script_dir,
                                  'sample_script.py')) as code_file:
            code = str(code_file.read())
        with open(suite_join_path(default_script_dir,
                                  'sample_script.yml')) as yml_file:
            yml = yaml.load(yml_file)
            yml['name'] = yml['commonfields']['id'] = name
        with open(
                suite_join_path(default_script_dir, 'sample_script_image.png'),
                'rb') as image_file:
            image = image_file.read()
        with open(suite_join_path(default_script_dir,
                                  'CHANGELOG.md')) as changelog_file:
            changelog = str(changelog_file.read())
        with open(
                suite_join_path(
                    default_script_dir,
                    'sample_script_description.md')) as description_file:
            description = str(description_file.read())

        self.build(code=code,
                   yml=yml,
                   image=image,
                   changelog=changelog,
                   description=description)
Esempio n. 3
0
    def create_default_integration(self):
        default_integration_dir = 'assets/default_integration'

        with open(suite_join_path(default_integration_dir,
                                  'sample.py')) as code_file:
            code = str(code_file.read())
        with open(suite_join_path(default_integration_dir,
                                  'sample.yml')) as yml_file:
            yml = yaml.safe_load(yml_file)
        with open(suite_join_path(default_integration_dir, 'sample_image.png'),
                  'rb') as image_file:
            image = image_file.read()
        with open(suite_join_path(default_integration_dir,
                                  'CHANGELOG.md')) as changelog_file:
            changelog = str(changelog_file.read())
        with open(
                suite_join_path(default_integration_dir,
                                'sample_description.md')) as description_file:
            description = str(description_file.read())

        self.build(code=code,
                   yml=yml,
                   image=image,
                   changelog=changelog,
                   description=description)

        if self.create_unified:
            unifier = Unifier(input=self.path,
                              output=os.path.dirname(
                                  self._tmpdir_integration_path))
            unifier.merge_script_package_to_yml()
            shutil.rmtree(self._tmpdir_integration_path)
Esempio n. 4
0
    def create_default_integration(self, name: str = 'Sample', commands: List[str] = None):
        """Creates a new integration with basic data

        Args:
            name: The name and ID of the new integration, default is "Sample".
            commands: List of additional commands to add to the integration.

        """
        default_integration_dir = 'assets/default_integration'

        with open(suite_join_path(default_integration_dir, 'sample.py')) as code_file:
            code = str(code_file.read())
        with open(suite_join_path(default_integration_dir, 'sample.yml')) as yml_file:
            yml = yaml.load(yml_file)
            yml['name'] = yml['commonfields']['id'] = name
            if commands:
                for command in commands:
                    yml['script']['commands'].append({'name': command})
        with open(suite_join_path(default_integration_dir, 'sample_image.png'), 'rb') as image_file:
            image = image_file.read()
        with open(suite_join_path(default_integration_dir, 'CHANGELOG.md')) as changelog_file:
            changelog = str(changelog_file.read())
        with open(suite_join_path(default_integration_dir, 'sample_description.md')) as description_file:
            description = str(description_file.read())

        self.build(
            code=code,
            yml=yml,
            image=image,
            changelog=changelog,
            description=description
        )
Esempio n. 5
0
 def create_default_test_playbook(self, name: str = 'SamplePlaybookTest'):
     default_test_playbook_dir = 'assets/default_playbook'
     with open(
             suite_join_path(default_test_playbook_dir,
                             'playbook-sample.yml')) as yml_file:
         yml = yaml.load(yml_file)
         yml['id'] = yml['name'] = name
         self.build(yml=yml)
Esempio n. 6
0
 def create_default_integration(self):
     default_integration_dir = 'assets/default_integration'
     code = open(suite_join_path(default_integration_dir, 'sample.py'))
     yml = open(suite_join_path(default_integration_dir, 'sample.yml'))
     image = open(suite_join_path(default_integration_dir, 'sample_image.png'), 'rb')
     changelog = open(suite_join_path(default_integration_dir, 'CHANGELOG.md'))
     description = open(suite_join_path(default_integration_dir, 'sample_description.md'))
     self.build(
         code=str(code.read()),
         yml=yaml.load(yml),
         image=image.read(),
         changelog=str(changelog.read()),
         description=str(description.read())
     )
     yml.close()
     image.close()
     changelog.close()
     description.close()
     code.close()
Esempio n. 7
0
    def create_default_playbook(self, name: str = 'sample playbook'):
        """Creates a new playbook with basic data.

        Args:
            name: The name and ID of the new playbook, default is "sample playbook".

        """
        default_playbook_dir = 'assets/default_playbook'
        with open(suite_join_path(default_playbook_dir,
                                  'playbook-sample.yml')) as yml_file:
            yml = yaml.load(yml_file)
            yml['id'] = yml['name'] = name
            self.build(yml=yml)
Esempio n. 8
0
 def create_integration(
     self,
     name: Optional[str] = None,
     code: Optional[str] = None,
     yml: Optional[dict] = None,
     readme: Optional[str] = None,
     description: Optional[str] = None,
     changelog: Optional[str] = None,
     image: Optional[bytes] = None,
     create_unified=False,
 ) -> Integration:
     if name is None:
         name = f'integration_{len(self.integrations)}'
     if yml is None:
         yml = {
             'commonfields': {
                 'id': name,
                 'version': -1
             },
             'name': name,
             'display': name,
             'description': f'this is an integration {name}',
             'script': {
                 'type': 'python',
                 'subtype': 'python3',
                 'script': '',
                 'commands': [],
             },
         }
     if image is None:
         with open(
                 suite_join_path('assets/default_integration',
                                 'sample_image.png'), 'rb') as image_file:
             image = image_file.read()
     integration = Integration(self._integrations_path,
                               name,
                               self._repo,
                               create_unified=create_unified)
     integration.build(code, yml, readme, description, changelog, image)
     self.integrations.append(integration)
     return integration
Esempio n. 9
0
 def create_default_test_playbook(self):
     default_test_playbook_dir = 'assets/default_playbook'
     with open(
             suite_join_path(default_test_playbook_dir,
                             'playbook-sample.yml')) as yml:
         self.build(yml=yaml.safe_load(yml))
Esempio n. 10
0
 def create_default_playbook(self):
     default_playbook_dir = 'assets/default_playbook'
     with open(suite_join_path(default_playbook_dir,
                               'playbook-sample.yml')) as yml:
         self.build(yml=yaml.load(yml, Loader=yaml.FullLoader))