From 3470c3361f861c5c971ad46bb5a83d09c198ca22 Mon Sep 17 00:00:00 2001 From: varnit-goyal_navi Date: Mon, 19 Aug 2024 16:56:00 +0530 Subject: [PATCH] TP-55555 clean up --- configs/Elastic.go | 2 ++ configs/application.yml | 11 +++++------ go.mod | 1 - pkg/db/elastic.go | 10 ++++++---- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/configs/Elastic.go b/configs/Elastic.go index bb41d6e..fb37246 100644 --- a/configs/Elastic.go +++ b/configs/Elastic.go @@ -4,6 +4,7 @@ type ElasticConfig struct { Addresses []string Username string Password string + APIKey string } func getElasticConfig() *ElasticConfig { @@ -11,5 +12,6 @@ func getElasticConfig() *ElasticConfig { Addresses: getStringSlice("elastic.addresses", true), Username: getString("elastic.username", true), Password: getString("elastic.password", true), + APIKey: getString("elastic.api_key", true), } } diff --git a/configs/application.yml b/configs/application.yml index cb722a7..e9566aa 100644 --- a/configs/application.yml +++ b/configs/application.yml @@ -66,13 +66,12 @@ DocumentService: mock: generate_token: DOCUMENT_SERVICE_MOCK_GENERATE_TOKEN - elastic: - addresses: http://localhost:9200 - username: aa - password: aa - error: - index: cybertron + addresses: https://localhost:9200 + username: elastic + password: 9457611267 + index: cybertron + api_key: Uk1ScGFKRUJYaHF5bTJkOWRuUmY6eWhIRGpFc1lUak9sRjcxY0taMzUydw== aws: region: ap-south-1 diff --git a/go.mod b/go.mod index 5f12346..c6acaee 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,6 @@ require ( github.com/gin-contrib/zap v0.2.0 github.com/gin-gonic/gin v1.9.1 github.com/golang-migrate/migrate/v4 v4.17.1 - github.com/google/uuid v1.6.0 github.com/prometheus/client_golang v1.19.1 github.com/spf13/cobra v1.8.0 github.com/spf13/viper v1.17.0 diff --git a/pkg/db/elastic.go b/pkg/db/elastic.go index 304320a..36b6acc 100644 --- a/pkg/db/elastic.go +++ b/pkg/db/elastic.go @@ -16,8 +16,7 @@ type ElasticSearchClient struct { func NewElasticClient(elasticConfig configs.ElasticConfig) (*ElasticSearchClient, error) { cfg := elasticsearch8.Config{ Addresses: elasticConfig.Addresses, - Username: elasticConfig.Username, - Password: elasticConfig.Password, + APIKey: elasticConfig.APIKey, Transport: &http.Transport{ TLSClientConfig: &tls.Config{ InsecureSkipVerify: true, @@ -26,6 +25,9 @@ func NewElasticClient(elasticConfig configs.ElasticConfig) (*ElasticSearchClient } client, err := elasticsearch8.NewTypedClient(cfg) + if err != nil { + log.Fatalf("Error creating the client: %s", err) + } return &ElasticSearchClient{ client: client, }, err @@ -34,9 +36,9 @@ func NewElasticClient(elasticConfig configs.ElasticConfig) (*ElasticSearchClient func (el *ElasticSearchClient) IndexDocument(document interface{}) { _, err := el.client.Index("cybertron"). Request(document). - Do(context.TODO()) + Do(context.Background()) if err != nil { - log.Fatal(err) + log.Fatalf("Error ingesting the doc: %s", err) } }