From e083832424799594d23be38f2c9a118374b8ce43 Mon Sep 17 00:00:00 2001 From: Frikky Date: Wed, 12 Jul 2023 23:31:14 +0200 Subject: [PATCH] Added base64 content parsing fix --- app_upload/stitcher.go | 8 +++---- codegen.go | 3 +++ db-connector.go | 48 ++++++++++++++++++++++++++++++++++++------ structs.go | 1 + 4 files changed, 50 insertions(+), 10 deletions(-) diff --git a/app_upload/stitcher.go b/app_upload/stitcher.go index 11a8795..6ee720a 100755 --- a/app_upload/stitcher.go +++ b/app_upload/stitcher.go @@ -41,8 +41,8 @@ var appSearchIndex = "appsearch" // CONFIGURE APP LOCATIONS TO USE // ALSO REQUIRES ACCESS TO UPLOAD TO CLOUD -var appbasefile = "/home/frikky/git/shuffle/backend/app_sdk/app_base.py" -var appfolder = "/home/frikky/git/shuffle-apps" +var appbasefile = "/Users/frikky/git/shuffle/backend/app_sdk/app_base.py" +var appfolder = "/Users/frikky/git/python-apps" var baseUrl = "" var apikey = "" @@ -836,8 +836,8 @@ func main() { //deployAll() //return - appname := "shuffle-tools" - appversion := "1.2.0" + appname := "shuffle-ai" + appversion := "1.0.0" err := deployConfigToBackend(appfolder, appname, appversion) if err != nil { log.Printf("[WARNING] Failed uploading config: %s", err) diff --git a/codegen.go b/codegen.go index fe4f804..4dfead4 100755 --- a/codegen.go +++ b/codegen.go @@ -754,6 +754,9 @@ func MakePythoncode(swagger *openapi3.Swagger, name, url, method string, paramet print(f"[WARNING] Something went wrong when adding extra returns (2). {e}") if to_file: + # If content encoding or transfer encoding is base64, decode it + if "content-encoding" in ret.headers.keys() and ret.headers["content-encoding"].lower() == "base64": + ret._content = base64.b64decode(ret.content) filedata = { "filename": "response", "data": ret.content, diff --git a/db-connector.go b/db-connector.go index c7bb213..0132b14 100755 --- a/db-connector.go +++ b/db-connector.go @@ -2652,10 +2652,12 @@ func GetOrg(ctx context.Context, id string) (*Org, error) { return &Org{}, err } } + } - if len(curOrg.Id) == 0 { - return &Org{}, errors.New(fmt.Sprintf("Couldn't find org with ID %s", curOrg.Id)) - } + // How does this happen? + if len(curOrg.Id) == 0 { + curOrg.Id = id + return curOrg, errors.New(fmt.Sprintf("Couldn't find org with ID %s", curOrg.Id)) } newUsers := []User{} @@ -2684,8 +2686,8 @@ func GetOrg(ctx context.Context, id string) (*Org, error) { newPriorities = append(newPriorities, priority) } - curOrg.Priorities = newPriorities + curOrg.Priorities = newPriorities if project.CacheDb { neworg, err := json.Marshal(curOrg) if err != nil { @@ -2873,6 +2875,22 @@ func SetOrg(ctx context.Context, data Org, id string) error { return errors.New(fmt.Sprintf("No ID provided for org %s", data.Name)) } + if id != data.Id && len(data.Id) > 0 { + log.Printf("[ERROR] Org ID mismatch: %s != %s. Resetting ID", id, data.Id) + id = data.Id + } + + data.Id = id + if len(data.Name) == 0 { + data.Name = "tmp" + + if len(data.Org) > 0 { + data.Name = data.Org + } else { + data.Org = data.Name + } + } + nameKey := "Organizations" timeNow := int64(time.Now().Unix()) if data.Created == 0 { @@ -3808,7 +3826,7 @@ func fixUserOrg(ctx context.Context, user *User) *User { org.Users = append(org.Users, innerUser) } - err = SetOrg(ctx, *org, orgId) + err = SetOrg(ctx, *org, org.Id) if err != nil { log.Printf("[WARNING] Failed setting org %s (2)", orgId) } @@ -7783,6 +7801,7 @@ func GetCacheKey(ctx context.Context, id string) (*CacheKeyData, error) { return cacheData, nil } +var retryCount int func RunInit(dbclient datastore.Client, storageClient storage.Client, gceProject, environment string, cacheDb bool, dbType string) (ShuffleStorage, error) { if dbType == "elasticsearch" { dbType = "opensearch" @@ -7819,7 +7838,24 @@ func RunInit(dbclient datastore.Client, storageClient storage.Client, gceProject ret, err := project.Es.Info() if err != nil { - log.Printf("[ERROR] Failed setting up Opensearch: %s", err) + log.Printf("[WARNING] Failed setting up Opensearch: %s. Typically means the backend can't connect, or that there's a HTTPS vs HTTP problem", err) + if strings.Contains(fmt.Sprintf("%s", err), "x509: certificate signed by unknown authority") || strings.Contains(fmt.Sprintf("%s", err), "EOF") { + if retryCount == 0 { + esUrl := os.Getenv("SHUFFLE_OPENSEARCH_URL") + if strings.Contains(esUrl, "http://") { + esUrl = strings.Replace(esUrl, "http://", "https://", 1) + } + + os.Setenv("SHUFFLE_OPENSEARCH_URL", esUrl) + + log.Printf("[ERROR] Automatically skipping SSL verification for Opensearch connection and swapping http/https.") + os.Setenv("SHUFFLE_OPENSEARCH_SKIPSSL_VERIFY", "true") + + retryCount += 1 + return RunInit(dbclient, storageClient, gceProject, environment, cacheDb, dbType) + } + } + return project, err } diff --git a/structs.go b/structs.go index f713804..b1d0855 100755 --- a/structs.go +++ b/structs.go @@ -1037,6 +1037,7 @@ type Workflow struct { Created int64 `json:"created" datastore:"created"` Edited int64 `json:"edited" datastore:"edited"` LastRuntime int64 `json:"last_runtime" datastore:"last_runtime"` + DueDate int64 `json:"due_date" datastore:"due_date"` Errors []string `json:"errors,omitempty" datastore:"errors"` Tags []string `json:"tags,omitempty" datastore:"tags"` ID string `json:"id" datastore:"id"`