Skip to content

Commit 7acbcda

Browse files
luthfifahleviMuhammad Luthfi Fahlevi
and
Muhammad Luthfi Fahlevi
authored
feat: ES support password config (#87)
* feat: ES provide password config * feat: add username --------- Co-authored-by: Muhammad Luthfi Fahlevi <[email protected]>
1 parent 6119ad8 commit 7acbcda

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -166,27 +166,27 @@ docker build . -t compass
166166
Before serving Compass app, we need to run the migration first. Run this docker command to migrate Compass.
167167

168168
```text
169-
$ 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
169+
$ 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
170170
```
171171

172172
If you are using Compass binary, you can run this command.
173173

174174
```text
175-
./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"
175+
./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"
176176
```
177177

178178
## Serving locally
179179

180180
Once the migration has been done, Compass server can be started with this command.
181181

182182
```text
183-
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
183+
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
184184
```
185185

186186
If you are using Compass binary, you can run this command.
187187

188188
```text
189-
./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"
189+
./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"
190190
```
191191

192192
## Running tests

compass.yaml.example

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ newrelic:
2929

3030
elasticsearch:
3131
brokers: http://localhost:9200
32+
username:
33+
password:
3234
request_timeout: 10s
3335

3436
db:

docs/docs/configuration.md

+6
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ log_level: info # debug|info|warning|error|fatal
3838

3939
elasticsearch:
4040
brokers: http://localhost:9200 #required
41+
username:
42+
password:
4143

4244
db:
4345
host: localhost #required
@@ -67,6 +69,8 @@ See [configuration reference](./reference/configuration.md) for the list of all
6769
```sh title=".env"
6870
LOG_LEVEL=info
6971
ELASTICSEARCH_BROKERS=http://localhost:9200
72+
ELASTICSEARCH_USERNAME=
73+
ELASTICSEARCH_PASSWORD=
7074
DB_HOST=localhost
7175
DB_PORT=5432
7276
DB_NAME=compass
@@ -238,6 +242,8 @@ app:
238242

239243
secretConfig: {}
240244
# COMPASS_ELASTICSEARCH_BROKERS: ~
245+
# COMPASS_ELASTICSEARCH_USERNAME: ~
246+
# COMPASS_ELASTICSEARCH_PASSWORD: ~
241247
# COMPASS_NEWRELIC_LICENSEKEY: ~
242248
# COMPASS_DB_HOST: ~
243249
# COMPASS_DB_PORT: 5432

internal/store/elasticsearch/es.go

+4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ const (
2828

2929
type Config struct {
3030
Brokers string `mapstructure:"brokers" default:"http://localhost:9200"`
31+
Username string `mapstructure:"username" default:""`
32+
Password string `mapstructure:"password" default:""`
3133
RequestTimeout time.Duration `mapstructure:"request_timeout" default:"10s"`
3234
}
3335

@@ -131,6 +133,8 @@ func NewClient(logger log.Logger, config Config, opts ...ClientOption) (*Client,
131133
esClient, err := elasticsearch.NewClient(elasticsearch.Config{
132134
Addresses: brokers,
133135
Transport: nrelasticsearch.NewRoundTripper(nil),
136+
Username: config.Username,
137+
Password: config.Password,
134138
// uncomment below code to debug request and response to elasticsearch
135139
// Logger: &estransport.ColorLogger{
136140
// Output: os.Stdout,

0 commit comments

Comments
 (0)