go.temporal.io/server@v1.23.0/common/persistence/visibility/store/elasticsearch/client/config.go (about) 1 // The MIT License 2 // 3 // Copyright (c) 2020 Temporal Technologies Inc. All rights reserved. 4 // 5 // Copyright (c) 2020 Uber Technologies, Inc. 6 // 7 // Permission is hereby granted, free of charge, to any person obtaining a copy 8 // of this software and associated documentation files (the "Software"), to deal 9 // in the Software without restriction, including without limitation the rights 10 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 // copies of the Software, and to permit persons to whom the Software is 12 // furnished to do so, subject to the following conditions: 13 // 14 // The above copyright notice and this permission notice shall be included in 15 // all copies or substantial portions of the Software. 16 // 17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 // THE SOFTWARE. 24 25 package client 26 27 import ( 28 "errors" 29 "fmt" 30 "net/url" 31 "time" 32 33 "go.temporal.io/server/common/auth" 34 ) 35 36 const ( 37 // VisibilityAppName is used to find ES indexName for visibility 38 VisibilityAppName = "visibility" 39 SecondaryVisibilityAppName = "secondary_visibility" 40 ) 41 42 // Config for connecting to Elasticsearch 43 type ( 44 Config struct { 45 Version string `yaml:"version"` 46 URL url.URL `yaml:"url"` 47 URLs []url.URL `yaml:"urls"` 48 Username string `yaml:"username"` 49 Password string `yaml:"password"` 50 Indices map[string]string `yaml:"indices"` 51 LogLevel string `yaml:"logLevel"` 52 AWSRequestSigning ESAWSRequestSigningConfig `yaml:"aws-request-signing"` 53 CloseIdleConnectionsInterval time.Duration `yaml:"closeIdleConnectionsInterval"` 54 EnableSniff bool `yaml:"enableSniff"` 55 EnableHealthcheck bool `yaml:"enableHealthcheck"` 56 TLS *auth.TLS `yaml:"tls"` 57 } 58 59 // ESAWSRequestSigningConfig represents configuration for signing ES requests to AWS 60 ESAWSRequestSigningConfig struct { 61 Enabled bool `yaml:"enabled"` 62 Region string `yaml:"region"` 63 64 // Possible options for CredentialProvider include: 65 // 1) static (fill out static Credential Provider) 66 // 2) environment 67 // a) AccessKeyID from either AWS_ACCESS_KEY_ID or AWS_ACCESS_KEY environment variable 68 // b) SecretAccessKey from either AWS_SECRET_ACCESS_KEY or AWS_SECRET_KEY environment variable 69 // 3) aws-sdk-default 70 // a) Follows aws-go-sdk default credential resolution for session.NewSession 71 CredentialProvider string `yaml:"credentialProvider"` 72 73 Static ESAWSStaticCredentialProvider `yaml:"static"` 74 } 75 76 // ESAWSStaticCredentialProvider represents static AWS credentials 77 ESAWSStaticCredentialProvider struct { 78 AccessKeyID string `yaml:"accessKeyID"` 79 SecretAccessKey string `yaml:"secretAccessKey"` 80 81 // Token only required for temporary security credentials retrieved via STS. Otherwise, this is optional. 82 Token string `yaml:"token"` 83 } 84 ) 85 86 // GetVisibilityIndex return visibility index name from Elasticsearch config or empty string if it is not defined. 87 func (cfg *Config) GetVisibilityIndex() string { 88 if cfg == nil { 89 // Empty string is be used as default index name when Elasticsearch is not configured. 90 return "" 91 } 92 return cfg.Indices[VisibilityAppName] 93 } 94 95 func (cfg *Config) GetSecondaryVisibilityIndex() string { 96 if cfg == nil { 97 return "" 98 } 99 return cfg.Indices[SecondaryVisibilityAppName] 100 } 101 102 func (cfg *Config) Validate() error { 103 if cfg == nil { 104 return errors.New("elasticsearch config: config not found") 105 } 106 if len(cfg.Indices) < 1 { 107 return errors.New("elasticsearch config: missing indices") 108 } 109 if cfg.Indices[VisibilityAppName] == "" { 110 return fmt.Errorf("elasticsearch config: indices configuration: missing %q key", VisibilityAppName) 111 } 112 return nil 113 }