diff --git a/README.md b/README.md index 4ae8e75d..af444e91 100644 --- a/README.md +++ b/README.md @@ -166,13 +166,13 @@ docker build . -t compass Before serving Compass app, we need to run the migration first. Run this docker command to migrate Compass. ```text -$ docker run --rm --net compass_storage -p 8080:8080 -e ELASTICSEARCH_BROKERS=http://es:9200 -e DB_HOST=postgres -e DB_PORT=5432 -e DB_NAME=compass -e DB_USER=compass -e DB_PASSWORD=compass_password gotocompany/compass compass server migrate +$ docker run --rm --net compass_storage -p 8080:8080 -e ELASTICSEARCH_BROKERS=http://es:9200 -e ELASTICSEARCH_USERNAME= -e ELASTICSEARCH_PASSWORD= -e DB_HOST=postgres -e DB_PORT=5432 -e DB_NAME=compass -e DB_USER=compass -e DB_PASSWORD=compass_password gotocompany/compass compass server migrate ``` If you are using Compass binary, you can run this command. ```text -./compass -elasticsearch-brokers "http://" -db-host "" -db-port 5432 -db-name "" -db-user "" -db-password " server migrate" +./compass -elasticsearch-brokers "http://" -elasticsearch-username "" -elasticsearch-password "" -db-host "" -db-port 5432 -db-name "" -db-user "" -db-password " server migrate" ``` ## Serving locally @@ -180,13 +180,13 @@ If you are using Compass binary, you can run this command. Once the migration has been done, Compass server can be started with this command. ```text -docker run --net compass_storage -p 8080:8080 -e ELASTICSEARCH_BROKERS=http://es:9200 -e DB_HOST=postgres -e DB_PORT=5432 -e DB_NAME=compass -e DB_USER=compass -e DB_PASSWORD=compass_password gotocompany/compass compass server start +docker run --net compass_storage -p 8080:8080 -e ELASTICSEARCH_BROKERS=http://es:9200 -e ELASTICSEARCH_USERNAME= -e ELASTICSEARCH_PASSWORD= -e DB_HOST=postgres -e DB_PORT=5432 -e DB_NAME=compass -e DB_USER=compass -e DB_PASSWORD=compass_password gotocompany/compass compass server start ``` If you are using Compass binary, you can run this command. ```text -./compass -elasticsearch-brokers "http://" -db-host "" -db-port 5432 -db-name "" -db-user "" -db-password " server start" +./compass -elasticsearch-brokers "http://" -elasticsearch-username "" -elasticsearch-password "" -db-host "" -db-port 5432 -db-name "" -db-user "" -db-password " server start" ``` ## Running tests diff --git a/compass.yaml.example b/compass.yaml.example index d12c1e2d..b3f83058 100644 --- a/compass.yaml.example +++ b/compass.yaml.example @@ -29,6 +29,8 @@ newrelic: elasticsearch: brokers: http://localhost:9200 + username: + password: request_timeout: 10s db: diff --git a/docs/docs/configuration.md b/docs/docs/configuration.md index e550aad4..68773025 100644 --- a/docs/docs/configuration.md +++ b/docs/docs/configuration.md @@ -38,6 +38,8 @@ log_level: info # debug|info|warning|error|fatal elasticsearch: brokers: http://localhost:9200 #required + username: + password: db: host: localhost #required @@ -67,6 +69,8 @@ See [configuration reference](./reference/configuration.md) for the list of all ```sh title=".env" LOG_LEVEL=info ELASTICSEARCH_BROKERS=http://localhost:9200 +ELASTICSEARCH_USERNAME= +ELASTICSEARCH_PASSWORD= DB_HOST=localhost DB_PORT=5432 DB_NAME=compass @@ -238,6 +242,8 @@ app: secretConfig: {} # COMPASS_ELASTICSEARCH_BROKERS: ~ + # COMPASS_ELASTICSEARCH_USERNAME: ~ + # COMPASS_ELASTICSEARCH_PASSWORD: ~ # COMPASS_NEWRELIC_LICENSEKEY: ~ # COMPASS_DB_HOST: ~ # COMPASS_DB_PORT: 5432 diff --git a/internal/store/elasticsearch/es.go b/internal/store/elasticsearch/es.go index 5014d905..71ce2d66 100644 --- a/internal/store/elasticsearch/es.go +++ b/internal/store/elasticsearch/es.go @@ -28,6 +28,8 @@ const ( type Config struct { Brokers string `mapstructure:"brokers" default:"http://localhost:9200"` + Username string `mapstructure:"username" default:""` + Password string `mapstructure:"password" default:""` RequestTimeout time.Duration `mapstructure:"request_timeout" default:"10s"` } @@ -131,6 +133,8 @@ func NewClient(logger log.Logger, config Config, opts ...ClientOption) (*Client, esClient, err := elasticsearch.NewClient(elasticsearch.Config{ Addresses: brokers, Transport: nrelasticsearch.NewRoundTripper(nil), + Username: config.Username, + Password: config.Password, // uncomment below code to debug request and response to elasticsearch // Logger: &estransport.ColorLogger{ // Output: os.Stdout,