Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds configuration for customizing SSL connections #36

Merged
merged 1 commit into from
Oct 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ All variables are optional unless marked required.
- **url** (*Required*): The URL of your Elasticsearch cluster
- **username**: If your cluster is protected with Basic Authentication via [X-Pack Security](https://www.elastic.co/products/x-pack/security), then provide a username here
- **password**: If your cluster is protected with Basic Authentication via [X-Pack Security](https://www.elastic.co/products/x-pack/security), then provide a password here
- **verify_ssl** (*default:* `true`): Set to `false` to disable SSL certificate verification.
- **ssl_ca_path** (*default:* `None`): Optional path to PEM encoded certificate authority bundle.
- **exclude**:
- **domains**: Specify an optional array of domains to exclude from publishing
- **entities**: Specify an optional array of entity ids to exclude from publishing
Expand Down
22 changes: 19 additions & 3 deletions custom_components/elastic.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import voluptuous as vol
from homeassistant.const import (
CONF_URL, CONF_USERNAME, CONF_PASSWORD, CONF_ALIAS, EVENT_STATE_CHANGED,
CONF_EXCLUDE, CONF_DOMAINS, CONF_ENTITIES
CONF_EXCLUDE, CONF_DOMAINS, CONF_ENTITIES, CONF_VERIFY_SSL
)
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers import (
Expand All @@ -28,6 +28,7 @@
CONF_ROLLOVER_AGE = 'rollover_max_age'
CONF_ROLLOVER_DOCS = 'rollover_max_docs'
CONF_ROLLOVER_SIZE = 'rollover_max_size'
CONF_SSL_CA_PATH = 'ssl_ca_path'

ELASTIC_COMPONENTS = [
'sensor'
Expand All @@ -51,6 +52,8 @@
vol.Optional(CONF_ROLLOVER_AGE, default='60d'): cv.string,
vol.Optional(CONF_ROLLOVER_DOCS, default=1000000): cv.positive_int,
vol.Optional(CONF_ROLLOVER_SIZE, default='5gb'): cv.string,
vol.Optional(CONF_VERIFY_SSL): cv.boolean,
vol.Optional(CONF_SSL_CA_PATH): cv.string,
vol.Optional(CONF_EXCLUDE, default={}): vol.Schema({
vol.Optional(CONF_DOMAINS, default=[]): vol.All(cv.ensure_list, [cv.string]),
vol.Optional(CONF_ENTITIES, default=[]): cv.entity_ids
Expand Down Expand Up @@ -117,6 +120,8 @@ def __init__(self, hass, config):
self._url = config.get(CONF_URL)
self._username = config.get(CONF_USERNAME)
self._password = config.get(CONF_PASSWORD)
self._verify_certs = config.get(CONF_VERIFY_SSL)
self._ca_certs = config.get(CONF_SSL_CA_PATH)

_LOGGER.debug("Creating Elasticsearch client")
self.client = self._create_es_client()
Expand All @@ -135,9 +140,20 @@ def _create_es_client(self):

if use_basic_auth:
auth = (self._username, self._password)
return elasticsearch.Elasticsearch([self._url], http_auth=auth, serializer=serializer)
return elasticsearch.Elasticsearch(
[self._url],
http_auth=auth,
serializer=serializer,
verify_certs=self._verify_certs,
ca_certs=self._ca_certs
)

return elasticsearch.Elasticsearch([self._url], serializer=serializer)
return elasticsearch.Elasticsearch(
[self._url],
serializer=serializer,
verify_certs=self._verify_certs,
ca_certs=self._ca_certs
)

def _get_serializer(self):
"""Gets the custom JSON serializer"""
Expand Down