From 2511c00db7f122a7fcd7dd69c9b948cc1b515ef2 Mon Sep 17 00:00:00 2001 From: ionutboangiu Date: Wed, 27 Nov 2024 19:08:41 +0200 Subject: [PATCH] Add elsCAPath opt and improve opt comments --- config/config_defaults.go | 32 +++++++++++----------- config/eescfg.go | 4 +++ config/eescfg_test.go | 2 ++ config/libconfig_json.go | 1 + data/conf/cgrates/cgrates.json | 32 +++++++++++----------- data/conf/samples/ees_elastic/cgrates.json | 2 +- ees/elastic.go | 4 +-- 7 files changed, 42 insertions(+), 35 deletions(-) diff --git a/config/config_defaults.go b/config/config_defaults.go index 637f760c6..40bfa2bd3 100644 --- a/config/config_defaults.go +++ b/config/config_defaults.go @@ -523,22 +523,22 @@ const CGRATES_CFG_JSON = ` // Elasticsearch options - // "elsCloud":true, // ExportPath will be an CLoud ID deployment - // "elsApiKey": "", // Base64-encoded token for authorization; if set, overrides username/password and service token. - // "elsUsername":"", // Username for HTTP Basic Authentication. - // "elsPassword":"", // Password for HTTP Basic Authentication. - // "elsServiceToken":"" // Service token for authorization; if set, overrides username/password. - // "elsCertificateFingerPrint":"" // SHA256 hex fingerprint given by Elasticsearch on first launch. - // "elsDiscoverNodesOnStart":false, // Discover nodes when initializing the client. Default: false. - // "elsDiscoverNodesInterval":"10s", // Discover nodes periodically. Default: disabled. - // "elsEnableDebugLogger":"false", // Enable the debug logging. - // "elsLogger":"", // The logger type can either be elsJson,elsColor and elsText - // "elsCompressRequestBody":false, // Enable compression on requests - // "elsCompressRequestBodyLevel":0, // Default: gzip.DefaultCompression, 9:BestCompression,-2:HuffmanOnly,1:BestSpeed - // "elsRetryOnStatus":[], // List of status codes for retry. Default: 502, 503, 504. - // "elsMaxRetries": 0, // Default: 3. - // "elsDisableRetry": false, // Default: false. - + // "elsCloud": true, // if true, use cloud ID deployment + // "elsApiKey": "", // base64-encoded token for auth; overrides username/password and service token + // "elsUsername": "", // username for HTTP Basic Authentication + // "elsPassword": "", // password for HTTP Basic Authentication + // "elsServiceToken": "", // service token for auth; if set, overrides username/password + // "elsCertificateFingerPrint": "", // SHA256 hex fingerprint given by Elasticsearch on first launch + // "elsCAPath": "", // path to CA certificate + // "elsDiscoverNodesOnStart": false, // discover nodes when initializing the client + // "elsDiscoverNodesInterval": "10s", // discover nodes periodically + // "elsEnableDebugLogger": "false", // enable the debug logging + // "elsLogger": "", // logger type + // "elsCompressRequestBody": false, // enable compression on requests + // "elsCompressRequestBodyLevel": 0, // compression level <0(gzip)|9(best compression)|-2(HuffmanOnly)|1(best speed)> + // "elsRetryOnStatus": [502,503,504], // status codes for retry + // "elsMaxRetries": 3, // maximum number of retries + // "elsDisableRetry": false, // disable retry mechanism // "elsIndex": "", // target elasticsearch index // "elsRefresh": "false", // controls when changes become searchable diff --git a/config/eescfg.go b/config/eescfg.go index f57145f3c..7c8ef1943 100644 --- a/config/eescfg.go +++ b/config/eescfg.go @@ -173,6 +173,7 @@ type ElsOpts struct { WaitForActiveShards *string // elasticsearch client opts + CAPath *string DiscoverNodesOnStart *bool DiscoverNodeInterval *time.Duration Cloud *bool @@ -329,6 +330,9 @@ func (elsOpts *ElsOpts) loadFromJSONCfg(jsnCfg *EventExporterOptsJson) (err erro if jsnCfg.ElsPassword != nil { elsOpts.Password = jsnCfg.ElsPassword } + if jsnCfg.ElsCAPath != nil { + elsOpts.CAPath = jsnCfg.ElsCAPath + } if jsnCfg.ElsDiscoverNodesOnStart != nil { elsOpts.DiscoverNodesOnStart = jsnCfg.ElsDiscoverNodesOnStart } diff --git a/config/eescfg_test.go b/config/eescfg_test.go index 2d345cedd..7cebe24af 100644 --- a/config/eescfg_test.go +++ b/config/eescfg_test.go @@ -1116,6 +1116,7 @@ func TestEEsCfgloadFromJSONCfg(t *testing.T) { ElsCertificateFingerprint: &str, ElsUsername: &str, ElsPassword: &str, + ElsCAPath: &str, ElsDiscoverNodesOnStart: &bl, ElsDiscoverNodesInterval: &tms, ElsEnableDebugLogger: &bl, @@ -1175,6 +1176,7 @@ func TestEEsCfgloadFromJSONCfg(t *testing.T) { exp := &ElsOpts{ Index: &str, Refresh: &str, + CAPath: &str, DiscoverNodesOnStart: &bl, DiscoverNodeInterval: &tm, Cloud: &bl, diff --git a/config/libconfig_json.go b/config/libconfig_json.go index 21629a778..110b7542c 100644 --- a/config/libconfig_json.go +++ b/config/libconfig_json.go @@ -307,6 +307,7 @@ type EventExporterOptsJson struct { ElsCertificateFingerprint *string `json:"elsCertificateFingerPrint"` ElsUsername *string `json:"elsUsername"` ElsPassword *string `json:"elsPassword"` + ElsCAPath *string `json:"elsCAPath"` ElsDiscoverNodesOnStart *bool `json:"elsDiscoverNodesOnStart"` ElsDiscoverNodesInterval *string `json:"elsDiscoverNodesInterval"` ElsEnableDebugLogger *bool `json:"elsEnableDebugLogger"` diff --git a/data/conf/cgrates/cgrates.json b/data/conf/cgrates/cgrates.json index 4a261ea65..6f83f27e3 100755 --- a/data/conf/cgrates/cgrates.json +++ b/data/conf/cgrates/cgrates.json @@ -502,22 +502,22 @@ // // Elasticsearch options -// // "elsCloud":true, // ExportPath will be an CLoud ID deployment -// // "elsApiKey": "", // Base64-encoded token for authorization; if set, overrides username/password and service token. -// // "elsUsername":"", // Username for HTTP Basic Authentication. -// // "elsPassword":"", // Password for HTTP Basic Authentication. -// // "elsServiceToken":"" // Service token for authorization; if set, overrides username/password. -// // "elsCertificateFingerPrint":"" // SHA256 hex fingerprint given by Elasticsearch on first launch. -// // "elsDiscoverNodesOnStart":false, // Discover nodes when initializing the client. Default: false. -// // "elsDiscoverNodesInterval":"10s", // Discover nodes periodically. Default: disabled. -// // "elsEnableDebugLogger":"false", // Enable the debug logging. -// // "elsLogger":"", // The logger type can either be elsJson,elsColor and elsText -// // "elsCompressRequestBody":false, // Enable compression on requests -// // "elsCompressRequestBodyLevel":0, // Default: gzip.DefaultCompression, 9:BestCompression,-2:HuffmanOnly,1:BestSpeed -// // "elsRetryOnStatus":[], // List of status codes for retry. Default: 502, 503, 504. -// // "elsMaxRetries": 0, // Default: 3. -// // "elsDisableRetry": false, // Default: false. - +// // "elsCloud": true, // if true, use cloud ID deployment +// // "elsApiKey": "", // base64-encoded token for auth; overrides username/password and service token +// // "elsUsername": "", // username for HTTP Basic Authentication +// // "elsPassword": "", // password for HTTP Basic Authentication +// // "elsServiceToken": "", // service token for auth; if set, overrides username/password +// // "elsCertificateFingerPrint": "", // SHA256 hex fingerprint given by Elasticsearch on first launch +// // "elsCAPath": "", // path to CA certificate +// // "elsDiscoverNodesOnStart": false, // discover nodes when initializing the client +// // "elsDiscoverNodesInterval": "10s", // discover nodes periodically +// // "elsEnableDebugLogger": "false", // enable the debug logging +// // "elsLogger": "", // logger type +// // "elsCompressRequestBody": false, // enable compression on requests +// // "elsCompressRequestBodyLevel": 0, // compression level <0(gzip)|9(best compression)|-2(HuffmanOnly)|1(best speed)> +// // "elsRetryOnStatus": [502,503,504], // status codes for retry +// // "elsMaxRetries": 3, // maximum number of retries +// // "elsDisableRetry": false, // disable retry mechanism // // "elsIndex": "", // target elasticsearch index // // "elsRefresh": "false", // controls when changes become searchable diff --git a/data/conf/samples/ees_elastic/cgrates.json b/data/conf/samples/ees_elastic/cgrates.json index ee8cf1e1b..85922e844 100644 --- a/data/conf/samples/ees_elastic/cgrates.json +++ b/data/conf/samples/ees_elastic/cgrates.json @@ -70,7 +70,7 @@ "elsIndex": "cdrs", "elsUsername": "elastic", // "elsPassword":"", - "caPath": "/path/to/http_ca.crt" + "elsCAPath": "/path/to/http_ca.crt" // "elsCloud":true, // "elsApiKey": "", // "elsServiceToken": "", diff --git a/ees/elastic.go b/ees/elastic.go index a2560bb53..042d7546d 100644 --- a/ees/elastic.go +++ b/ees/elastic.go @@ -74,8 +74,8 @@ func (e *ElasticEE) parseClientOpts() error { if opts.APIKey != nil { e.clientCfg.APIKey = *opts.APIKey } - if e.Cfg().Opts.RPC.CAPath != nil { - cacert, err := os.ReadFile(*e.Cfg().Opts.RPC.CAPath) + if opts.CAPath != nil { + cacert, err := os.ReadFile(*opts.CAPath) if err != nil { return err }