Helpers

Utils

es_client.helpers.utils.check_config(config)

Ensure that the top-level key elasticsearch and its sub-keys, other_settings and client as contained in config before passing it (or empty defaults) to SchemaCheck for value validation.

Parameters:config (dict) – The configuration
es_client.helpers.utils.ensure_list(data)

Return a list, even if data is a single value

Parameters:data – A list or scalar variable to act upon
Return type:list
es_client.helpers.utils.file_exists(file)

Verify the file exists

Parameters:file (str) – The file to test
Returns:Whether the file exists
Return type:bool
es_client.helpers.utils.get_version(client)

Get the Elasticsearch version of the connected node

Parameters:client (Elasticsearch) – An Elasticsearch client object
Returns:The Elasticsearch version as a 3-part tuple, (major, minor, patch)
Return type:tuple
es_client.helpers.utils.get_yaml(path)

Read the file identified by path and import its YAML contents.

Parameters:path (str) – The path to a YAML configuration file.
Returns:The contents of path translated from YAML to dict
Return type:dict
es_client.helpers.utils.parse_apikey_token(token)

Split a base64 encoded API Key Token into id and api_key

Parameters:token (str) – The base64 encoded API Key
Returns:A tuple of (id, api_key)
Return type:tuple
es_client.helpers.utils.prune_nones(mydict)

Remove keys from mydict whose values are None

Parameters:mydict – The dictionary to act on
Return type:dict
es_client.helpers.utils.read_file(myfile)

Read a file and return the resulting data.

Parameters:myfile – A file to read.
Return type:str
es_client.helpers.utils.verify_ssl_paths(args)

Verify that the various certificate/key paths are readable. The read_file() function will raise a ConfigurationError if a file fails to be read.

Parameters:args (dict) – The client block of the config dictionary.
es_client.helpers.utils.verify_url_schema(url)

Ensure that a valid URL schema (HTTP[S]://URL:PORT) is used

Parameters:url (str) – The url to verify
Returns:Verified URL
Return type:str

SchemaCheck

es_client.helpers.schemacheck.password_filter(data)

Return a deepcopy of the dictionary with any password fields hidden

class es_client.helpers.schemacheck.SchemaCheck(config, schema, test_what, location)

Validate config with the provided Schema. test_what and location are for reporting the results, in case of failure. If validation is successful, the method returns config as valid through the result() method.

Parameters:
  • config (dict) – A configuration dictionary.
  • schema (Schema) – A voluptuous schema definition
  • test_what (str) – which configuration block is being validated
  • location (str) – An string to report which configuration sub-block is being tested.
result()

Return the result of the Schema test, if successful. Otherwise, raise a ConfigurationError