Example #1
0
def test_add_plugin_corrupted_spec(tmpdir_factory, description, plugin_spec):
    """Tests that it's not possible to add a plugin with invalid spec file

    :param tmpdir_factory: pytest builtin fixture for creating temp dirs
    :param description: test description (adds a description in pytest run)
    :param plugin_spec: dictionary with data for spec file
    :return:
    """

    lp_dir = tmpdir_factory.mktemp('test_tmp_dir')
    lp_file = lp_dir.join('plugin.spec')

    with open(lp_file.strpath, 'w') as fp:
        yaml.dump(plugin_spec, fp, default_flow_style=True)

    try:
        with pytest.raises(IRValidatorException):
            SpecValidator.validate_from_file(lp_file.strpath)
    finally:
        lp_dir.remove()
Example #2
0
def test_add_plugin_corrupted_spec(tmpdir_factory, description, plugin_spec):
    """Tests that it's not possible to add a plugin with invalid spec file

    :param tmpdir_factory: pytest builtin fixture for creating temp dirs
    :param description: test description (adds a description in pytest run)
    :param plugin_spec: dictionary with data for spec file
    :return:
    """

    lp_dir = tmpdir_factory.mktemp('test_tmp_dir')
    lp_file = lp_dir.join('plugin.spec')

    with open(lp_file.strpath, 'w') as fp:
        yaml.dump(plugin_spec, fp, default_flow_style=True)

    try:
        with pytest.raises(IRValidatorException):
            SpecValidator.validate_from_file(lp_file.strpath)
    finally:
        lp_dir.remove()
Example #3
0
    def get_github_organization_plugins(organization, no_forks=False):
        """Returns a dict with all plugins from a GitHub organization.

        Inspired from: https://gist.github.com/ralphbean/5733076

        :param organization: GitHub organization name
        :param no_forks: include / not include forks
        """
        plugins_dict = OrderedDict()

        try:
            gh = github.Github()
            all_repos = gh.get_organization(organization).get_repos()
        except github.RateLimitExceededException:
            raise IRException("Github API rate limit exceeded")

        for repo in all_repos:

            try:
                # Don't print the urls for repos that are forks.
                if no_forks and repo.fork:
                    continue

                spec_file = repo.get_contents('plugin.spec').decoded_content

                plugin = SpecValidator.validate_from_content(spec_file)
                plugin_name = plugin["subparsers"].keys()[0]
                plugin_src = repo.clone_url
                plugin_type = plugin["config"]["plugin_type"] \
                    if "config" in plugin \
                    else plugin["plugin_type"]
                plugin_desc = plugin["description"] \
                    if "description" in plugin \
                       and plugin["description"] is not None \
                    else "-"

                if plugin_type not in plugins_dict:
                    plugins_dict[plugin_type] = {}

                plugins_dict[plugin_type][plugin_name] = {
                    "src": plugin_src,
                    "desc": plugin_desc,
                }

            except github.RateLimitExceededException:
                raise IRException("Github API rate limit exceeded")
            except Exception:
                # skip repo failures
                continue

        return plugins_dict
Example #4
0
    def get_github_organization_plugins(organization, no_forks=False):
        """
        Returns a dict with all plugins from a GitHub organization
        inspired from: https://gist.github.com/ralphbean/5733076
        :param organization: GitHub organization name
        :param no_forks: include / not include forks
        """
        plugins_dict = OrderedDict()

        try:
            gh = github.Github()
            all_repos = gh.get_organization(organization).get_repos()
        except github.RateLimitExceededException:
            raise IRException("Github API rate limit exceeded")

        for repo in all_repos:

            try:
                # Don't print the urls for repos that are forks.
                if no_forks and repo.fork:
                    continue

                spec_file = repo.get_contents('plugin.spec').decoded_content

                plugin = SpecValidator.validate_from_content(spec_file)
                plugin_name = plugin["subparsers"].keys()[0]
                plugin_src = repo.clone_url
                plugin_type = plugin["config"]["plugin_type"] \
                    if "config" in plugin \
                    else plugin["plugin_type"]
                plugin_desc = plugin["description"] \
                    if "description" in plugin \
                       and plugin["description"] is not None \
                    else "-"

                if plugin_type not in plugins_dict:
                    plugins_dict[plugin_type] = {}

                plugins_dict[plugin_type][plugin_name] = {
                    "src": plugin_src,
                    "desc": plugin_desc,
                }

            except github.RateLimitExceededException:
                raise IRException("Github API rate limit exceeded")
            except Exception:
                # skip repo failures
                continue

        return plugins_dict
Example #5
0
 def config(self, plugin_spec):
     self._config = SpecValidator.validate_from_file(plugin_spec)
Example #6
0
 def config(self, plugin_spec):
     self._config = SpecValidator.validate_from_file(plugin_spec)