Skip to content

Commit

Permalink
Merge pull request #2142 from traPtitech/es-authentication
Browse files Browse the repository at this point in the history
Elasticsearchに認証を導入
  • Loading branch information
logica0419 authored Dec 7, 2023
2 parents 9fc76ae + 5ec954d commit 0af382c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
11 changes: 10 additions & 1 deletion cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,12 @@ type Config struct {

// ES Elasticsearch設定
ES struct {
// URL URL (default: "")
URL string `mapstructure:"url" yaml:"url"`
// Username ユーザー名 (default: "elastic")
Username string `mapstructure:"username" yaml:"username"`
// Password パスワード (default: "password")
Password string `mapstructure:"password" yaml:"password"`
} `mapstructure:"es" yaml:"es"`

// Storage ファイルストレージ設定
Expand Down Expand Up @@ -270,6 +275,8 @@ func init() {
viper.SetDefault("mariadb.connection.maxIdle", 2)
viper.SetDefault("mariadb.connection.lifetime", 0)
viper.SetDefault("es.url", "")
viper.SetDefault("es.username", "elastic")
viper.SetDefault("es.password", "password")
viper.SetDefault("storage.type", "local")
viper.SetDefault("storage.local.dir", "./storage")
viper.SetDefault("storage.swift.username", "")
Expand Down Expand Up @@ -452,7 +459,9 @@ func provideFirebaseCredentialsFilePathString(c *Config) variable.FirebaseCreden

func provideESEngineConfig(c *Config) search.ESEngineConfig {
return search.ESEngineConfig{
URL: c.ES.URL,
URL: c.ES.URL,
Username: c.ES.Username,
Password: c.ES.Password,
}
}

Expand Down
3 changes: 1 addition & 2 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ services:
environment:
discovery.type: single-node
cluster.name: docker-cluster
# デフォルトではオンになっているので、セキュリティをオフにする
xpack.security.enabled: false
ELASTIC_PASSWORD: password
ports:
- "9200:9200"
- "9300:9300"
Expand Down
2 changes: 0 additions & 2 deletions dev/elasticsearch.yml

This file was deleted.

6 changes: 6 additions & 0 deletions service/search/es.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ func getIndexName(index string) string {
type ESEngineConfig struct {
// URL ESのURL
URL string
// Username ESのユーザー名
Username string
// Password ESのパスワード
Password string
}

// esEngine search.Engine 実装
Expand Down Expand Up @@ -173,6 +177,8 @@ func NewESEngine(mm message.Manager, cm channel.Manager, repo repository.Reposit
// esクライアント作成
client, err := elasticsearch.NewClient(elasticsearch.Config{
Addresses: []string{config.URL},
Username: config.Username,
Password: config.Password,
})
if err != nil {
return nil, fmt.Errorf("failed to init Elasticsearch: %w", err)
Expand Down

0 comments on commit 0af382c

Please sign in to comment.