Beispiel #1
0
def main() -> None:
    """Main function of Lexicon."""
    # Dynamically determine all the providers available and gather command line arguments.
    parsed_args = generate_cli_main_parser().parse_args()

    log_level = logging.getLevelName(parsed_args.log_level)
    logging.basicConfig(stream=sys.stdout, level=log_level, format="%(message)s")
    logger.debug("Arguments: %s", parsed_args)

    # In the CLI context, will get configuration interactively:
    #   * from the command line
    #   * from the environment variables
    #   * from lexicon configuration files found in given --config-dir (default is current dir)
    config = ConfigResolver()
    config.with_args(parsed_args).with_env().with_config_dir(parsed_args.config_dir)

    client = Client(config)

    results = client.execute()

    action = config.resolve("lexicon:action")
    if not action:
        raise ValueError("Parameter action is not set.")

    handle_output(results, parsed_args.output, action)
Beispiel #2
0
def test_cli_main_parser():
    baseparser = generate_cli_main_parser()
    parsed = baseparser.parse_args(
        ['cloudflare', 'list', 'capsulecd.com', 'TXT'])
    assert parsed.provider_name == 'cloudflare'
    assert parsed.action == 'list'
    assert parsed.domain == 'capsulecd.com'
    assert parsed.type == 'TXT'
    assert parsed.output == 'TABLE'
Beispiel #3
0
def test_cli_main_parser():
    baseparser = parser.generate_cli_main_parser()
    parsed = baseparser.parse_args(
        ["cloudflare", "list", "capsulecd.com", "TXT"])
    assert parsed.provider_name == "cloudflare"
    assert parsed.action == "list"
    assert parsed.domain == "capsulecd.com"
    assert parsed.type == "TXT"
    assert parsed.output == "TABLE"
Beispiel #4
0
def test_argparse_resolution():
    parser = generate_cli_main_parser()
    data = parser.parse_args([
        '--delegated', 'TEST1', 'cloudflare', 'create', 'example.com', 'TXT',
        '--auth-token', 'TEST2'
    ])

    config = ConfigResolver().with_args(data)

    assert config.resolve('lexicon:delegated') == 'TEST1'
    assert config.resolve('lexicon:cloudflare:auth_token') == 'TEST2'
    assert config.resolve('lexicon:nonexistent') is None
Beispiel #5
0
def test_argparse_resolution():
    parser = generate_cli_main_parser()
    data = parser.parse_args([
        "--delegated",
        "TEST1",
        "cloudflare",
        "create",
        "example.com",
        "TXT",
        "--auth-token",
        "TEST2",
    ])

    config = ConfigResolver().with_args(data)

    assert config.resolve("lexicon:delegated") == "TEST1"
    assert config.resolve("lexicon:cloudflare:auth_token") == "TEST2"
    assert config.resolve("lexicon:nonexistent") is None
Beispiel #6
0
def main():
    """Main function of Lexicon."""
    # Dynamically determine all the providers available and gather command line arguments.
    parsed_args = generate_cli_main_parser().parse_args()

    log_level = logging.getLevelName(parsed_args.log_level)
    logging.basicConfig(stream=sys.stdout,
                        level=log_level,
                        format='%(message)s')
    logger.debug('Arguments: %s', parsed_args)

    # In the CLI context, will get configuration interactively:
    #   * from the command line
    #   * from the environment variables
    #   * from lexicon configuration files in working directory
    config = ConfigResolver()
    config.with_args(parsed_args).with_env().with_config_dir(os.getcwd())

    client = Client(config)

    results = client.execute()

    handle_output(results, parsed_args.output)
Beispiel #7
0
import shlex
from copy import deepcopy
from functools import reduce
from typing import Any, Dict, List

import coloredlogs
import yaml
from lexicon import config, parser

from dnsrobocert.core import utils

LEGACY_CONFIGURATION_PATH = "/etc/letsencrypt/domains.conf"
LOGGER = logging.getLogger(__name__)
coloredlogs.install(logger=LOGGER)

LEXICON_ARGPARSER = parser.generate_cli_main_parser()


def migrate(config_path):
    if os.path.exists(config_path):  # pragma: nocover
        return

    if not os.path.exists(LEGACY_CONFIGURATION_PATH):  # pragma: nocover
        return

    provider = os.environ.get("LEXICON_PROVIDER")
    if not provider:  # pragma: nocover
        LOGGER.error(
            "Error, LEXICON_PROVIDER environment variable is not set!")
        return
Beispiel #8
0
def test_cli_main_parser_without_args():
    baseparser = generate_cli_main_parser()
    with pytest.raises(SystemExit):
        baseparser.parse_args([])