Ejemplo n.º 1
0
    def __init__(self,
                 config,
                 vault_config,
                 vault_creds,
                 config_format=None,
                 load_certs=False):
        """
        Args:
            config{str} -- [File path to configuration or a string containing the configuration] (default: {'config.yaml'})
            vault_config {str} -- [File path to configuration or a string containing the configuration] (default: {'vault.yaml'})
            vault_creds {str} -- [File path to configuration or a string containing the configuration](default: {'vault.yaml'})
            load_certs {bool} -- Automatically load certificate and key files during configuration (default: {False})
            config_format {str} -- Specifies the parser to use when reading the configuration, only needed if reading a string. See the ac_parser option
            in python-anyconfig for available formats. Common ones are `json` and `yaml`.
        """
        config_client = VaultAnyConfig(vault_config, ac_parser=config_format)
        config_client.auto_auth(vault_creds, ac_parser=config_format)
        if os.path.isfile(config):
            self.config = config_client.load(config,
                                             process_secret_files=load_certs)
        else:
            self.config = config_client.loads(config,
                                              process_secret_files=load_certs,
                                              ac_parser=config_format)

        # Elastic Search
        elastic_config = self.config["elastic"]
        self.connect_elastic(elastic_config)
        self.ES_INDEX = elastic_config["index"]
Ejemplo n.º 2
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
Ejemplo n.º 3
0
def main():
    """
    Main entrypoint
    """
    args = parse_args(sys.argv[1:])

    client = VaultAnyConfig(vault_config_in=args.vault_config)
    client.auto_auth(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)
def test_load_no_vault_with_secrets(mock_load, gen_input_config):
    """
    Basic test of the load function
    """
    mock_load.return_value = gen_input_config()

    input_config_edited = gen_input_config()
    del input_config_edited["vault_secrets"]

    client = VaultAnyConfig()

    with pytest.warns(UserWarning):
        assert client.load("in.json") == input_config_edited

    mock_load.assert_called_with("in.json")