Skip to content

Commit

Permalink
make the code work for dredd testing
Browse files Browse the repository at this point in the history
  • Loading branch information
ManoelMilchev committed Sep 27, 2022
1 parent c63595e commit f198b09
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions cmd/content-rw-elasticsearch/main.go
Expand Up @@ -18,6 +18,8 @@ import (
cli "github.com/jawher/mow.cli"
)

const defaultESTestingEndpoint = "http://localhost:9000"

func main() {
app := cli.App(config.AppName, config.AppDescription)

Expand Down Expand Up @@ -100,22 +102,30 @@ func main() {

log := logger.NewUPPLogger(*appSystemCode, *logLevel)
log.Info("[Startup] Application is starting")
awsSession, sessionErr := session.NewSession()
if sessionErr != nil {
log.WithError(sessionErr).Fatal("Failed to initialize AWS session")
}
credValues, err := awsSession.Config.Credentials.Get()
if err != nil {
log.WithError(err).Fatal("Failed to obtain AWS credentials values")
}
log.Infof("Obtaining AWS credentials by using [%s] as provider", credValues.ProviderName)

app.Action = func() {
accessConfig := es.AccessConfig{
AccessKey: credValues.AccessKeyID,
SecretKey: credValues.SecretAccessKey,
SessionToken: credValues.SessionToken,
Endpoint: *esEndpoint,
Endpoint: *esEndpoint,
}

if *esEndpoint != defaultESTestingEndpoint {
log.Info("Trying to get session credentials")
awsSession, sessionErr := session.NewSession()
if sessionErr != nil {
log.WithError(sessionErr).Fatal("Failed to initialize AWS session")
}
credValues, err := awsSession.Config.Credentials.Get()
if err != nil {
log.WithError(err).Fatal("Failed to obtain AWS credentials values")
}
log.Infof("Obtaining AWS credentials by using [%s] as provider", credValues.ProviderName)

accessConfig = es.AccessConfig{
AccessKey: credValues.AccessKeyID,
SecretKey: credValues.SecretAccessKey,
SessionToken: credValues.SessionToken,
Endpoint: *esEndpoint,
}
}

httpClient := pkghttp.NewHTTPClient()
Expand Down Expand Up @@ -160,7 +170,7 @@ func main() {

handler.Stop()
}
err = app.Run(os.Args)
err := app.Run(os.Args)
if err != nil {
log.WithError(err).WithTime(time.Now()).Fatal("App could not start")
return
Expand Down

0 comments on commit f198b09

Please sign in to comment.