コード例 #1
0
def configure(config_file, vault_config, vault_creds):
    """
    Loads the configuration of the Slackbot
    Args:
        config_file: filename for the bot configuration file
        vault_config: filename for the vault client configuration file
        vault_creds: filename for the vault credentials file
    """
    global config  # pylint: disable=invalid-name
    config_client = VaultAnyConfig(vault_config)
    config_client.auth_from_file(vault_creds)
    config = config_client.load(config_file)["ebr-trackerbot"]

    log_level = logging.getLevelName(config.get("log_level", "ERROR"))

    logging.basicConfig(level=log_level,
                        format="[%(asctime)s] [%(levelname)s] %(message)s",
                        datefmt="%Y-%m-%d %H:%M:%S")
    if "api_url" not in config:
        raise RuntimeError("Missing api url in configuration.")
    if "slack_token" not in config:
        raise RuntimeError("Missing Slack Token in configuration.")

    default_slack_message_template = "Test *{{test}}* failed *{{count}}* in the last {{period}}\n"
    config.setdefault("slack_message_template", default_slack_message_template)
    config.setdefault("init_channel", "#test-slackbot")

    config.setdefault("check_tests_delay", 86400)  # in seconds, 86400 = 1 day
コード例 #2
0
def test_auth_from_file(mock_auto_auth):
    """
    Tests that auth_from_file calls auto_auth
    """
    client = VaultAnyConfig()
    client.auth_from_file("test.json")
    mock_auto_auth.assert_called_once_with("test.json", ac_parser=None)
コード例 #3
0
def test_auth_with_already_authenticated_and_passthrough(
        mock_is_authenticated):
    """
    Tests that the auth_from_file will simply be bypassed when using an instance with passthrough set and the client is already authenticated
    """
    mock_is_authenticated.return_value = True
    client = VaultAnyConfig()
    assert client.auth_from_file("config.json")
コード例 #4
0
def main():
    """
    Main entrypoint
    """
    args = parse_args(sys.argv[1:])

    client = VaultAnyConfig(vault_config_file=args.vault_config)
    client.auth_from_file(args.vault_creds)

    config = client.load(
        args.in_file,
        process_secret_files=args.secret_files_write,
        ac_parser=args.file_type,
    )

    client.dump(
        config,
        args.out_file,
        process_secret_files=args.secret_files_write,
        ac_parser=args.file_type,
    )
コード例 #5
0
def test_auth_with_passthrough():
    """
    Tests that the auth_from_file will simply be bypassed when using an instance with passthrough
    """
    client = VaultAnyConfig()
    assert client.auth_from_file("config.json")