Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Elasticsearchに認証を導入 #2142

Merged
merged 3 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading