Skip to content

Commit

Permalink
Add basic auth for Elastic
Browse files Browse the repository at this point in the history
  • Loading branch information
mzealey committed Oct 28, 2022
1 parent 4ba0425 commit 76ee2da
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ For use with RapidPro, you will need to configure these settings:
- `MAILROOM_DB`: URL describing how to connect to the RapidPro database (default "postgres://temba:temba@localhost/temba?sslmode=disable")
- `MAILROOM_READONLY_DB`: URL for an additional database connection for read-only operations (optional)
- `MAILROOM_REDIS`: URL describing how to connect to Redis (default "redis://localhost:6379/15")
- `MAILROOM_ELASTIC`: URL describing how to connect to ElasticSearch (default "http://localhost:9200")
- `MAILROOM_SMTP_SERVER`: the smtp configuration for sending emails ex: smtp://user%40password@server:port/?from=foo%40gmail.com
- `MAILROOM_FCM_KEY`: the key for Firebase Cloud Messaging used to sync Android channels
- `MAILROOM_ELASTIC`: URL describing how to connect to ElasticSearch (default "http://localhost:9200")
- `MAILROOM_ELASTIC_USERNAME`: ElasticSearch username for Basic Auth
- `MAILROOM_ELASTIC_PASSWORD`: ElasticSearch password for Basic Auth

For writing of message attachments, you need an S3 compatible service which you configure with:

Expand Down
5 changes: 3 additions & 2 deletions mailroom.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func (mr *Mailroom) Start() error {
}

// initialize our elastic client
mr.rt.ES, err = newElasticClient(c.Elastic)
mr.rt.ES, err = newElasticClient(c.Elastic, c.ElasticUsername, c.ElasticPassword)
if err != nil {
log.WithError(err).Error("elastic search not available")
} else {
Expand Down Expand Up @@ -271,7 +271,7 @@ func openAndCheckRedisPool(redisUrl string) (*redis.Pool, error) {
return rp, err
}

func newElasticClient(url string) (*elastic.Client, error) {
func newElasticClient(url string, username string, password string) (*elastic.Client, error) {
// enable retrying
backoff := elastic.NewSimpleBackoff(500, 1000, 2000)
backoff.Jitter(true)
Expand All @@ -281,5 +281,6 @@ func newElasticClient(url string) (*elastic.Client, error) {
elastic.SetURL(url),
elastic.SetSniff(false),
elastic.SetRetrier(retrier),
elastic.SetBasicAuth(username, password),
)
}
10 changes: 8 additions & 2 deletions runtime/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ type Config struct {
ReadonlyDB string `validate:"omitempty,url,startswith=postgres:" help:"URL of optional connection to readonly database instance"`
DBPoolSize int ` help:"the size of our db pool"`
Redis string `validate:"url,startswith=redis:" help:"URL for your Redis instance"`
Elastic string `validate:"url" help:"URL for your ElasticSearch service"`
SentryDSN string ` help:"the DSN used for logging errors to Sentry"`

Elastic string `validate:"url" help:"URL for your ElasticSearch service"`
ElasticUsername string `help:"Username for ElasticSearch service"`
ElasticPassword string `help:"Password for ElasticSearch service"`

Address string `help:"the address to bind our web server to"`
Port int `help:"the port to bind our web server to"`
AuthToken string `help:"the token clients will need to authenticate web requests"`
Expand Down Expand Up @@ -82,7 +85,10 @@ func NewDefaultConfig() *Config {
ReadonlyDB: "",
DBPoolSize: 36,
Redis: "redis://localhost:6379/15",
Elastic: "http://localhost:9200",

Elastic: "http://localhost:9200",
ElasticUsername: "",
ElasticPassword: "",

Address: "localhost",
Port: 8090,
Expand Down

0 comments on commit 76ee2da

Please sign in to comment.