Skip to content

Commit

Permalink
fix[opensearch-update-hotfix]: this should just feel like magic
Browse files Browse the repository at this point in the history
  • Loading branch information
0x0elliot committed May 23, 2024
1 parent 2b02023 commit bb8d41c
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions db-connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -10833,7 +10833,7 @@ func GetCacheKey(ctx context.Context, id string) (*CacheKeyData, error) {

var retryCount int

func RunInit(dbclient datastore.Client, storageClient storage.Client, gceProject, environment string, cacheDb bool, dbType string) (ShuffleStorage, error) {
func RunInit(dbclient datastore.Client, storageClient storage.Client, gceProject, environment string, cacheDb bool, dbType string, defaultCreds bool, count int) (ShuffleStorage, error) {
if dbType == "elasticsearch" {
dbType = "opensearch"
}
Expand Down Expand Up @@ -10871,7 +10871,7 @@ func RunInit(dbclient datastore.Client, storageClient storage.Client, gceProject
requestCache = cache.New(35*time.Minute, 35*time.Minute)
if strings.ToLower(environment) != "worker" && (strings.ToLower(dbType) == "opensearch" || strings.ToLower(dbType) == "opensearch") {

project.Es = *GetEsConfig()
project.Es = *GetEsConfig(defaultCreds)

ret, err := project.Es.Info()
if err != nil {
Expand Down Expand Up @@ -10900,7 +10900,7 @@ func RunInit(dbclient datastore.Client, storageClient storage.Client, gceProject
os.Setenv("SHUFFLE_OPENSEARCH_SKIPSSL_VERIFY", "true")

retryCount += 1
return RunInit(dbclient, storageClient, gceProject, environment, cacheDb, dbType)
return RunInit(dbclient, storageClient, gceProject, environment, cacheDb, dbType, false, 0)
}
}

Expand All @@ -10917,6 +10917,12 @@ func RunInit(dbclient datastore.Client, storageClient storage.Client, gceProject
log.Printf("[ERROR] Bad Status from ES: %d", ret.StatusCode)
log.Printf("[ERROR] Bad Body from ES: %s", string(respBody))

if count == 0 {
count += 1
log.Printf("[ERROR] Trying default creds for ES once before failing")
return RunInit(dbclient, storageClient, gceProject, environment, cacheDb, dbType, true, count)
}

return project, errors.New(fmt.Sprintf("Bad status code from ES: %d", ret.StatusCode))
} else {
//log.Printf("\n\n[INFO] Should check for SSO during setup - finding main org\n\n")
Expand All @@ -10941,7 +10947,7 @@ func RunInit(dbclient datastore.Client, storageClient storage.Client, gceProject
return project, nil
}

func GetEsConfig() *opensearch.Client {
func GetEsConfig(defaultCreds bool) *opensearch.Client {
esUrl := os.Getenv("SHUFFLE_OPENSEARCH_URL")
if len(esUrl) == 0 {
esUrl = "https://shuffle-opensearch:9200"
Expand All @@ -10959,6 +10965,13 @@ func GetEsConfig() *opensearch.Client {
password = "StrongShufflePassword321!"
}

if defaultCreds {
log.Printf("[DEBUG] Using default credentials for Opensearch (previous versions)")

username = "admin"
password = "admin"
}

log.Printf("[DEBUG] Using custom opensearch url '%s'", esUrl)

// https://github.com/elastic/go-opensearch/blob/f741c073f324c15d3d401d945ee05b0c410bd06d/opensearch.go#L98
Expand Down

0 comments on commit bb8d41c

Please sign in to comment.