Ejemplo n.º 1
0
    def _validate_config(self):
        provider_name = self.config.resolve("lexicon:provider_name")
        if not self.config.resolve("lexicon:provider_name"):
            raise AttributeError("provider_name")

        try:
            available = discovery.find_providers()[
                self.config.resolve("lexicon:provider_name")
            ]
        except KeyError:
            raise ProviderNotAvailableError(
                f"This provider ({provider_name}) is not supported by Lexicon."
            )
        else:
            if not available:
                raise ProviderNotAvailableError(
                    f"This provider ({provider_name}) has required dependencies that are missing. "
                    f"Please install lexicon[{provider_name}] first."
                )

        if not self.config.resolve("lexicon:action"):
            raise AttributeError("action")
        if not self.config.resolve("lexicon:domain"):
            raise AttributeError("domain")
        if not self.config.resolve("lexicon:type"):
            raise AttributeError("type")
Ejemplo n.º 2
0
def generate_cli_main_parser() -> argparse.ArgumentParser:
    """Using all providers available, generate a parser that will be used by Lexicon CLI"""
    parser = argparse.ArgumentParser(
        description="Create, Update, Delete, List DNS entries")

    parser.add_argument(
        "--version",
        help="show the current version of lexicon",
        action="version",
        version=f"%(prog)s {discovery.lexicon_version()}",
    )
    parser.add_argument("--delegated", help="specify the delegated domain")
    parser.add_argument(
        '--log_level',
        help='specify the log level',
        default='ERROR',
        choices=['CRITICAL', 'ERROR', 'WARNING', 'INFO', 'DEBUG', 'NOTSET'])
    parser.add_argument(
        '--output',
        help=(
            'specify the type of output: by default a formatted table (TABLE), '
            'a formatted table without header (TABLE-NO-HEADER), '
            'a JSON string (JSON) or no output (QUIET)'),
        default='TABLE',
        choices=['TABLE', 'TABLE-NO-HEADER', 'JSON', 'QUIET'])
    parser.add_argument(
        "--config-dir",
        default=os.getcwd(),
        help="specify the directory where to search lexicon.yml and "
        "lexicon_[provider].yml configuration files "
        "(default: current directory).",
    )
    subparsers = parser.add_subparsers(dest="provider_name",
                                       help="specify the DNS provider to use")
    subparsers.required = True

    for provider, available in discovery.find_providers().items():
        provider_module = importlib.import_module("lexicon.providers." +
                                                  provider)
        provider_parser = getattr(provider_module, "provider_parser")

        subparser = subparsers.add_parser(
            provider,
            help=f"{provider} provider",
            parents=[generate_base_provider_parser()],
        )
        provider_parser(subparser)

        if not available:
            subparser.epilog = (
                "WARNING: some required dependencies for this provider are not "
                f"installed. Please install lexicon[{provider}] first before using it."
            )

    return parser
Ejemplo n.º 3
0
def main():
    providers = [
        provider for provider in discovery.find_providers().keys()
        if provider != "auto"
    ]

    output = """\
=========================
Lexicon providers options
=========================

Supported providers
===================

The following Lexicon providers are supported by DNSroboCert.

{0}

Providers options
=================

""".format(_generate_table(["{0}_".format(provider)
                            for provider in providers]))

    for provider in providers:
        provider_module = importlib.import_module("lexicon.providers." +
                                                  provider)
        parser = argparse.ArgumentParser()
        provider_module.provider_parser(parser)

        output = (output + """\
.. _{0}:

{0}
""".format(provider))

        for action in parser._actions:
            if action.dest == "help":
                continue

            output = (output + """\
    * ``{0}`` {1}
""".format(action.dest,
            action.help.capitalize().replace("`", "'")))

        output = output + "\n"

    with open(os.path.join("docs", "providers_options.rst"), "w") as f:
        f.write(output)
Ejemplo n.º 4
0
def pytest_runtest_setup(item):
    """Standard pytest hook invoked before each test execution"""
    try:
        skip_providers_with_optdeps = getattr(
            item.config.option, "xfail_providers_with_missing_deps")
    except AttributeError:
        pass
    else:
        if skip_providers_with_optdeps:
            providers = discovery.find_providers()
            skip = [
                available for provider, available in providers.items()
                if provider in item.parent.name.lower()
            ]
            if skip and not skip[0]:
                pytest.xfail(
                    "Test expected to fail because --skip-providers-with-missing-deps "
                    "is set and provider has missing required dependencies.")
Ejemplo n.º 5
0
def generate_cli_main_parser() -> argparse.ArgumentParser:
    """Using all providers available, generate a parser that will be used by Lexicon CLI"""
    parser = argparse.ArgumentParser(
        description="Create, Update, Delete, List DNS entries"
    )

    parser.add_argument(
        "--version",
        help="show the current version of lexicon",
        action="version",
        version=f"%(prog)s {discovery.lexicon_version()}",
    )
    parser.add_argument("--delegated", help="specify the delegated domain")
    parser.add_argument(
        "--config-dir",
        default=os.getcwd(),
        help="specify the directory where to search lexicon.yml and "
        "lexicon_[provider].yml configuration files "
        "(default: current directory).",
    )
    subparsers = parser.add_subparsers(
        dest="provider_name", help="specify the DNS provider to use"
    )
    subparsers.required = True

    for provider, available in discovery.find_providers().items():
        provider_module = importlib.import_module("lexicon.providers." + provider)
        provider_parser = getattr(provider_module, "provider_parser")

        subparser = subparsers.add_parser(
            provider,
            help=f"{provider} provider",
            parents=[generate_base_provider_parser()],
        )
        provider_parser(subparser)

        if not available:
            subparser.epilog = (
                "WARNING: some required dependencies for this provider are not "
                f"installed. Please install lexicon[{provider}] first before using it."
            )

    return parser
Ejemplo n.º 6
0
    def guessProvider(self, hostname):
        domain = self.guessDomain(hostname)
        resolve = "{}.{}".format(domain.domain, domain.suffix)
        nameservers = dns.resolver.query(resolve, "NS")

        # 1 Get Lexicon Providers
        lexicon_providers = discovery.find_providers()

        valid_guesses = set([])

        # Loop over nameservers to find a Lexicon provider
        for nameserver in nameservers:
            # Remove trailing .
            nameserver = str(nameserver.target).strip()
            domain = self.guessDomain(str(nameserver).strip())
            extracted_provider = domain.domain
            lexicon_provider = lexicon_providers[extracted_provider]
            if lexicon_provider:
                valid_guesses.add(extracted_provider)
        return list(valid_guesses)
Ejemplo n.º 7
0
def main():
    providers = [
        provider for provider in discovery.find_providers().keys()
        if provider != "auto"
    ]

    output = f"""\
Providers available
-------------------

The following Lexicon providers are available:

{_generate_table(["{0}_".format(provider) for provider in providers])}

List of options
---------------

"""

    for provider in providers:
        provider_module = importlib.import_module("lexicon.providers." +
                                                  provider)
        parser = argparse.ArgumentParser()
        provider_module.provider_parser(parser)

        provider_content = [f"""\
.. _{provider}:

{provider}
"""]
        for action in parser._actions:
            if action.dest == "help":
                continue

            provider_content.append(f"""\
    * ``{action.dest}`` {action.help.capitalize().replace("`", "'")}
""")
        output = output + "".join(provider_content) + "\n"

    with open(os.path.join("docs", "providers_options.rst"), "w") as f:
        f.write(output)
Ejemplo n.º 8
0
    def _validate_config(self):
        provider_name = self.config.resolve('lexicon:provider_name')
        if not self.config.resolve('lexicon:provider_name'):
            raise AttributeError('provider_name')

        try:
            available = discovery.find_providers()[self.config.resolve('lexicon:provider_name')]
        except KeyError:
            raise ProviderNotAvailableError('This provider ({0}) is not supported by Lexicon.'
                                            .format(provider_name))
        else:
            if not available:
                raise ProviderNotAvailableError(
                    'This provider ({0}) has required dependencies that are missing. '
                    'Please install lexicon[{0}] first.'.format(provider_name))

        if not self.config.resolve('lexicon:action'):
            raise AttributeError('action')
        if not self.config.resolve('lexicon:domain'):
            raise AttributeError('domain')
        if not self.config.resolve('lexicon:type'):
            raise AttributeError('type')
Ejemplo n.º 9
0
def generate_cli_main_parser():
    """Using all providers available, generate a parser that will be used by Lexicon CLI"""
    parser = argparse.ArgumentParser(
        description='Create, Update, Delete, List DNS entries')

    parser.add_argument('--version',
                        help='show the current version of lexicon',
                        action='version',
                        version='%(prog)s {0}'.format(
                            discovery.lexicon_version()))
    parser.add_argument('--delegated', help='specify the delegated domain')
    parser.add_argument(
        '--config-dir',
        default=os.getcwd(),
        help='specify the directory where to search lexicon.yml and '
        'lexicon_[provider].yml configuration files '
        '(default: current directory).')
    subparsers = parser.add_subparsers(dest='provider_name',
                                       help='specify the DNS provider to use')
    subparsers.required = True

    for provider, available in discovery.find_providers().items():
        provider_module = importlib.import_module('lexicon.providers.' +
                                                  provider)
        provider_parser = getattr(provider_module, 'provider_parser')

        subparser = subparsers.add_parser(
            provider,
            help='{0} provider'.format(provider),
            parents=[generate_base_provider_parser()])
        provider_parser(subparser)

        if not available:
            subparser.epilog = (
                'WARNING: some required dependencies for this provider are not '
                'installed. Please install lexicon[{0}] first before using it.'
                .format(provider))

    return parser