Skip to content

Commit

Permalink
feat: ES support password config (#87)
Browse files Browse the repository at this point in the history
* feat: ES provide password config

* feat: add username

---------

Co-authored-by: Muhammad Luthfi Fahlevi <muhammad.fahlevi@gojek.com>
  • Loading branch information
luthfifahlevi and Muhammad Luthfi Fahlevi authored Dec 2, 2024
1 parent 6119ad8 commit 7acbcda
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,27 +166,27 @@ 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://<broker-host-name>" -db-host "<postgres-host-name>" -db-port 5432 -db-name "<postgres-db-name>" -db-user "<postgres-db-user>" -db-password "<postgres-db-password> server migrate"
./compass -elasticsearch-brokers "http://<broker-host-name>" -elasticsearch-username "" -elasticsearch-password "" -db-host "<postgres-host-name>" -db-port 5432 -db-name "<postgres-db-name>" -db-user "<postgres-db-user>" -db-password "<postgres-db-password> server migrate"
```

## Serving locally

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://<broker-host-name>" -db-host "<postgres-host-name>" -db-port 5432 -db-name "<postgres-db-name>" -db-user "<postgres-db-user>" -db-password "<postgres-db-password> server start"
./compass -elasticsearch-brokers "http://<broker-host-name>" -elasticsearch-username "" -elasticsearch-password "" -db-host "<postgres-host-name>" -db-port 5432 -db-name "<postgres-db-name>" -db-user "<postgres-db-user>" -db-password "<postgres-db-password> server start"
```

## Running tests
Expand Down
2 changes: 2 additions & 0 deletions compass.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ newrelic:

elasticsearch:
brokers: http://localhost:9200
username:
password:
request_timeout: 10s

db:
Expand Down
6 changes: 6 additions & 0 deletions docs/docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ log_level: info # debug|info|warning|error|fatal

elasticsearch:
brokers: http://localhost:9200 #required
username:
password:

db:
host: localhost #required
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions internal/store/elasticsearch/es.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 7acbcda

Please sign in to comment.