@@ -6,10 +6,8 @@ import (
66 "fmt"
77 "github.com/hashicorp/go-multierror"
88 "github.com/knadh/koanf/parsers/yaml"
9- "github.com/knadh/koanf/providers/env"
109 "github.com/knadh/koanf/providers/file"
1110 "github.com/knadh/koanf/v2"
12- "github.com/rs/zerolog"
1311 "log"
1412 "os"
1513 "quesma/elasticsearch/elasticsearch_field_types"
@@ -29,58 +27,27 @@ var (
2927
3028type QuesmaConfiguration struct {
3129 // both clickhouse and hydrolix connections are going to be deprecated and everything is going to live under connector
32- Connectors map [string ]RelationalDbConfiguration `koanf:"connectors"`
33- TransparentProxy bool `koanf:"transparentProxy"`
34- InstallationId string `koanf:"installationId"`
35- LicenseKey string `koanf:"licenseKey"`
30+ Connectors map [string ]RelationalDbConfiguration
31+ TransparentProxy bool
32+ InstallationId string
33+ LicenseKey string
3634 //deprecated
37- ClickHouse RelationalDbConfiguration `koanf:"clickhouse"`
35+ ClickHouse RelationalDbConfiguration
3836 //deprecated
39- Hydrolix RelationalDbConfiguration `koanf:"hydrolix"`
40- Elasticsearch ElasticsearchConfiguration `koanf:"elasticsearch"`
41- IndexConfig map [string ]IndexConfiguration `koanf:"indexes"`
42- Logging LoggingConfiguration `koanf:"logging"`
43- PublicTcpPort network.Port `koanf:"port"`
44- IngestStatistics bool `koanf:"ingestStatistics"`
45- QuesmaInternalTelemetryUrl * Url `koanf:"internalTelemetryUrl"`
46- DisableAuth bool `koanf:"disableAuth"`
37+ Hydrolix RelationalDbConfiguration
38+ Elasticsearch ElasticsearchConfiguration
39+ IndexConfig map [string ]IndexConfiguration
40+ Logging LoggingConfiguration
41+ PublicTcpPort network.Port
42+ IngestStatistics bool
43+ QuesmaInternalTelemetryUrl * Url
44+ DisableAuth bool
4745 AutodiscoveryEnabled bool
4846
4947 EnableIngest bool // this is computed from the configuration 2.0
5048 CreateCommonTable bool
5149}
5250
53- type LoggingConfiguration struct {
54- Path string `koanf:"path"`
55- Level * zerolog.Level `koanf:"level"`
56- RemoteLogDrainUrl * Url `koanf:"remoteUrl"`
57- FileLogging bool `koanf:"fileLogging"`
58- }
59-
60- type RelationalDbConfiguration struct {
61- //ConnectorName string `koanf:"name"`
62- ConnectorType string `koanf:"type"`
63- Url * Url `koanf:"url"`
64- User string `koanf:"user"`
65- Password string `koanf:"password"`
66- Database string `koanf:"database"`
67- AdminUrl * Url `koanf:"adminUrl"`
68- DisableTLS bool `koanf:"disableTLS"`
69- }
70-
71- type OptimizerConfiguration struct {
72- Disabled bool `koanf:"disabled"`
73- Properties map [string ]string `koanf:"properties"`
74- }
75-
76- func (c * RelationalDbConfiguration ) IsEmpty () bool {
77- return c != nil && c .Url == nil && c .User == "" && c .Password == "" && c .Database == ""
78- }
79-
80- func (c * RelationalDbConfiguration ) IsNonEmpty () bool {
81- return ! c .IsEmpty ()
82- }
83-
8451func (c * QuesmaConfiguration ) AliasFields (indexName string ) map [string ]string {
8552 aliases := make (map [string ]string )
8653 if indexConfig , found := c .IndexConfig [indexName ]; found {
@@ -99,34 +66,6 @@ func MatchName(pattern, name string) bool {
9966
10067var k = koanf .New ("." )
10168
102- func Load () QuesmaConfiguration {
103- var config QuesmaConfiguration
104-
105- loadConfigFile ()
106- if err := k .Load (env .Provider ("QUESMA_" , "." , func (s string ) string {
107- // This enables overriding config values with environment variables. It's case-sensitive, just like the YAML.
108- // Examples:
109- // `QUESMA_logging_level=debug` overrides `logging.level` in the config file
110- // `QUESMA_licenseKey=arbitrary-license-key` overrides `licenseKey` in the config file
111- return strings .Replace (strings .TrimPrefix (s , "QUESMA_" ), "_" , "." , - 1 )
112- }), nil ); err != nil {
113- log .Fatalf ("error loading config form supplied env vars: %v" , err )
114- }
115- if err := k .Unmarshal ("" , & config ); err != nil {
116- log .Fatalf ("error unmarshalling config: %v" , err )
117- }
118- for name , idxConfig := range config .IndexConfig {
119- idxConfig .Name = name
120- config .IndexConfig [name ] = idxConfig
121- if idxConfig .SchemaOverrides != nil {
122- for fieldName , configuration := range idxConfig .SchemaOverrides .Fields {
123- idxConfig .SchemaOverrides .Fields [fieldName ] = configuration
124- }
125- }
126- }
127- return config
128- }
129-
13069func loadConfigFile () {
13170 var configPath string
13271 if configFileName , isSet := os .LookupEnv (configFileLocationEnvVar ); isSet {
0 commit comments