Skip to content

Commit

Permalink
Onprem fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
frikky committed Mar 30, 2021
1 parent 7bf1b9a commit eb31195
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 15 deletions.
2 changes: 1 addition & 1 deletion codegen.go
Original file line number Diff line number Diff line change
Expand Up @@ -1641,7 +1641,7 @@ func HandlePost(swagger *openapi3.Swagger, api WorkflowApp, extraParameters []Wo
newName := string(fmt.Sprintf("%s", string(fieldname)))
if newName[0] == 0x22 && newName[len(newName)-1] == 0x22 {
parsedName := newName[1 : len(newName)-1]
log.Printf("Parse name: %s", parsedName)
//log.Printf("Parse name: %s", parsedName)
fileField = parsedName

curParam := WorkflowAppActionParameter{
Expand Down
6 changes: 5 additions & 1 deletion db-connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,10 @@ func GetEnvironments(ctx context.Context, orgId string) ([]Environment, error) {
// 2. Get USERs' private apps
// 3. Get PUBLIC apps
func GetPrioritizedApps(ctx context.Context, user User) ([]WorkflowApp, error) {
if project.Environment != "cloud" {
return GetAllWorkflowApps(ctx, 500)
}

allApps := []WorkflowApp{}
//log.Printf("[INFO] LOOPING REAL APPS: %d. Private: %d", len(user.PrivateApps))

Expand Down Expand Up @@ -1410,7 +1414,7 @@ func SetFile(ctx context.Context, file File) error {

func GetAllFiles(ctx context.Context, orgId string) ([]File, error) {
var files []File
q := datastore.NewQuery("Files").Filter("org_id =", orgId).Limit(100)
q := datastore.NewQuery("Files").Filter("org_id =", orgId).Order("-updated_at").Limit(100)

_, err := project.Dbclient.GetAll(ctx, q, &files)
if err != nil {
Expand Down
5 changes: 2 additions & 3 deletions files.go
Original file line number Diff line number Diff line change
Expand Up @@ -623,8 +623,7 @@ func HandleUploadFile(resp http.ResponseWriter, request *http.Request) {
contents := buf.Bytes()
file.FileSize = int64(len(contents))
md5 := Md5sum(contents)
contentType := http.DetectContentType(contents)
log.Printf("CONTENTTYPE: %s", contentType)
file.ContentType = http.DetectContentType(contents)

buf.Reset()

Expand Down Expand Up @@ -673,7 +672,7 @@ func HandleUploadFile(resp http.ResponseWriter, request *http.Request) {
file.Status = "active"
file.Md5sum = md5
file.Sha256sum = fmt.Sprintf("%x", sha256Sum)
log.Printf("[INFO] MD5 for file %s (%s) is %s and SHA256 is %s", file.Filename, file.Id, file.Md5sum, file.Sha256sum)
log.Printf("[INFO] MD5 for file %s (%s) is %s and SHA256 is %s. Type: %s", file.Filename, file.Id, file.Md5sum, file.Sha256sum, file.ContentType)

err = SetFile(ctx, *file)
if err != nil {
Expand Down
31 changes: 21 additions & 10 deletions shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -1397,8 +1397,9 @@ func GetWorkflows(resp http.ResponseWriter, request *http.Request) {
for _, workflow := range workflows {
newActions := []Action{}
for _, action := range workflow.Actions {
action.LargeImage = ""
action.SmallImage = ""
// Removed because of exports. These are needed there.
//action.LargeImage = ""
//action.SmallImage = ""
newActions = append(newActions, action)
}

Expand Down Expand Up @@ -1937,6 +1938,10 @@ func SetNewWorkflow(resp http.ResponseWriter, request *http.Request) {
for _, action := range workflow.Actions {
if action.Environment == "" {
//action.Environment = baseEnvironment
if project.IsCloud {
action.Environment = "cloud"
}

action.IsValid = true
}

Expand Down Expand Up @@ -2256,17 +2261,21 @@ func SaveWorkflow(resp http.ResponseWriter, request *http.Request) {
}

if action.Environment == "" {
if workflow.PreviouslySaved {
resp.WriteHeader(401)
resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "An environment for %s is required"}`, action.Label)))
return
if project.Environment == "cloud" {
action.Environment = "cloud"
} else {
if workflow.PreviouslySaved {
resp.WriteHeader(401)
resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "An environment for %s is required"}`, action.Label)))
return
}
action.IsValid = true
}
action.IsValid = true
}

// FIXME: Have a good way of tracking errors. ID's or similar.
if !action.IsValid && len(action.Errors) > 0 {
log.Printf("Node %s is invalid and needs to be remade. Errors: %s", action.Label, strings.Join(action.Errors, "\n"))
log.Printf("[INFO] Node %s is invalid and needs to be remade. Errors: %s", action.Label, strings.Join(action.Errors, "\n"))

if workflow.PreviouslySaved {
resp.WriteHeader(401)
Expand Down Expand Up @@ -2327,7 +2336,7 @@ func SaveWorkflow(resp http.ResponseWriter, request *http.Request) {
workflow.IsValid = false
workflow.Errors = []string{"Trigger is missing a parameter: %s", param.Name}

log.Printf("No type specified for user input node")
log.Printf("[WARNING] No type specified for user input node")
if workflow.PreviouslySaved {
resp.WriteHeader(401)
resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "Trigger %s is missing the parameter %s"}`, trigger.Label, param.Name)))
Expand Down Expand Up @@ -2563,7 +2572,7 @@ func SaveWorkflow(resp http.ResponseWriter, request *http.Request) {
}

if !authFound {
log.Printf("App auth %s doesn't exist. Setting error", action.AuthenticationId)
log.Printf("[WARNING] App auth %s doesn't exist. Setting error", action.AuthenticationId)
workflow.Errors = append(workflow.Errors, fmt.Sprintf("App authentication for %s doesn't exist!", action.AppName))
workflow.IsValid = false

Expand All @@ -2581,6 +2590,7 @@ func SaveWorkflow(resp http.ResponseWriter, request *http.Request) {
} else {
curapp := WorkflowApp{}
// FIXME - can this work with ONLY AppID?
// ^ Doubtful.
for _, app := range workflowapps {
if app.ID == action.AppID {
curapp = app
Expand All @@ -2595,6 +2605,7 @@ func SaveWorkflow(resp http.ResponseWriter, request *http.Request) {
}

// Check to see if the whole app is valid
//log.Printf("NAME: %s vs %s", curapp.Name, action.AppName)
if curapp.Name != action.AppName {
workflow.Errors = append(workflow.Errors, fmt.Sprintf("App %s doesn't exist", action.AppName))
action.Errors = append(action.Errors, "This app doesn't exist.")
Expand Down

0 comments on commit eb31195

Please sign in to comment.