Skip to content

Commit

Permalink
Added base64 content parsing fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Frikky authored and Frikky committed Jul 12, 2023
1 parent 33696b0 commit e083832
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 10 deletions.
8 changes: 4 additions & 4 deletions app_upload/stitcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""

Expand Down Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions codegen.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
48 changes: 42 additions & 6 deletions db-connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

Expand Down
1 change: 1 addition & 0 deletions structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down

0 comments on commit e083832

Please sign in to comment.