TP-55555 clean up

This commit is contained in:
varnit-goyal_navi
2024-08-19 16:56:00 +05:30
parent 384c003ceb
commit 3470c3361f
4 changed files with 13 additions and 11 deletions

View File

@@ -4,6 +4,7 @@ type ElasticConfig struct {
Addresses []string Addresses []string
Username string Username string
Password string Password string
APIKey string
} }
func getElasticConfig() *ElasticConfig { func getElasticConfig() *ElasticConfig {
@@ -11,5 +12,6 @@ func getElasticConfig() *ElasticConfig {
Addresses: getStringSlice("elastic.addresses", true), Addresses: getStringSlice("elastic.addresses", true),
Username: getString("elastic.username", true), Username: getString("elastic.username", true),
Password: getString("elastic.password", true), Password: getString("elastic.password", true),
APIKey: getString("elastic.api_key", true),
} }
} }

View File

@@ -66,13 +66,12 @@ DocumentService:
mock: mock:
generate_token: DOCUMENT_SERVICE_MOCK_GENERATE_TOKEN generate_token: DOCUMENT_SERVICE_MOCK_GENERATE_TOKEN
elastic: elastic:
addresses: http://localhost:9200 addresses: https://localhost:9200
username: aa username: elastic
password: aa password: 9457611267
error: index: cybertron
index: cybertron api_key: Uk1ScGFKRUJYaHF5bTJkOWRuUmY6eWhIRGpFc1lUak9sRjcxY0taMzUydw==
aws: aws:
region: ap-south-1 region: ap-south-1

1
go.mod
View File

@@ -10,7 +10,6 @@ require (
github.com/gin-contrib/zap v0.2.0 github.com/gin-contrib/zap v0.2.0
github.com/gin-gonic/gin v1.9.1 github.com/gin-gonic/gin v1.9.1
github.com/golang-migrate/migrate/v4 v4.17.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/prometheus/client_golang v1.19.1
github.com/spf13/cobra v1.8.0 github.com/spf13/cobra v1.8.0
github.com/spf13/viper v1.17.0 github.com/spf13/viper v1.17.0

View File

@@ -16,8 +16,7 @@ type ElasticSearchClient struct {
func NewElasticClient(elasticConfig configs.ElasticConfig) (*ElasticSearchClient, error) { func NewElasticClient(elasticConfig configs.ElasticConfig) (*ElasticSearchClient, error) {
cfg := elasticsearch8.Config{ cfg := elasticsearch8.Config{
Addresses: elasticConfig.Addresses, Addresses: elasticConfig.Addresses,
Username: elasticConfig.Username, APIKey: elasticConfig.APIKey,
Password: elasticConfig.Password,
Transport: &http.Transport{ Transport: &http.Transport{
TLSClientConfig: &tls.Config{ TLSClientConfig: &tls.Config{
InsecureSkipVerify: true, InsecureSkipVerify: true,
@@ -26,6 +25,9 @@ func NewElasticClient(elasticConfig configs.ElasticConfig) (*ElasticSearchClient
} }
client, err := elasticsearch8.NewTypedClient(cfg) client, err := elasticsearch8.NewTypedClient(cfg)
if err != nil {
log.Fatalf("Error creating the client: %s", err)
}
return &ElasticSearchClient{ return &ElasticSearchClient{
client: client, client: client,
}, err }, err
@@ -34,9 +36,9 @@ func NewElasticClient(elasticConfig configs.ElasticConfig) (*ElasticSearchClient
func (el *ElasticSearchClient) IndexDocument(document interface{}) { func (el *ElasticSearchClient) IndexDocument(document interface{}) {
_, err := el.client.Index("cybertron"). _, err := el.client.Index("cybertron").
Request(document). Request(document).
Do(context.TODO()) Do(context.Background())
if err != nil { if err != nil {
log.Fatal(err) log.Fatalf("Error ingesting the doc: %s", err)
} }
} }