Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
frikky committed May 21, 2024
2 parents be7e713 + bd086c5 commit 3e0099c
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 223 deletions.
35 changes: 21 additions & 14 deletions db-connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -6072,6 +6072,8 @@ func GetPrioritizedApps(ctx context.Context, user User) ([]WorkflowApp, error) {
}
}



return allApps, nil
}

Expand Down Expand Up @@ -6170,6 +6172,8 @@ func fixAppAppend(allApps []WorkflowApp, innerApp WorkflowApp) ([]WorkflowApp, W

func GetUserApps(ctx context.Context, userId string) ([]WorkflowApp, error) {
wrapper := []WorkflowApp{}
var err error

cacheKey := fmt.Sprintf("userapps-%s", userId)
if project.CacheDb {
cache, err := GetCache(ctx, cacheKey)
Expand Down Expand Up @@ -6207,8 +6211,8 @@ func GetUserApps(ctx context.Context, userId string) ([]WorkflowApp, error) {
},
},
},
"minimum_should_match": 1,
},
"minimum_should_match": 1,
},
}

Expand All @@ -6234,8 +6238,9 @@ func GetUserApps(ctx context.Context, userId string) ([]WorkflowApp, error) {
}

if res.StatusCode != 200 && res.StatusCode != 201 {
return []WorkflowApp{}, fmt.Errorf("bad statuscode: %d", res.StatusCode)
return []WorkflowApp{}, errors.New(fmt.Sprintf("Bad statuscode: %d", res.StatusCode))
}

respBody, err := ioutil.ReadAll(res.Body)
if err != nil {
return []WorkflowApp{}, err
Expand Down Expand Up @@ -7861,17 +7866,17 @@ func GetHooks(ctx context.Context, OrgId string) ([]Hook, error) {
}
wrapper := AllHooksWrapper{}
err = json.Unmarshal(respBody, &wrapper)

if err != nil {
return []Hook{}, err
}

for _, hit := range wrapper.Hits.Hits {
hook := hit.Source
hooks = append(hooks, hook)
hook := hit.Source
hooks = append(hooks, hook)
}
return hooks, err

} else {
q := datastore.NewQuery(nameKey).Filter("org_id = ", OrgId).Limit(1000)

Expand Down Expand Up @@ -7942,7 +7947,7 @@ func GetPipelines(ctx context.Context, OrgId string) ([]Pipeline, error) {

if res.StatusCode != 200 && res.StatusCode != 201 {
return []Pipeline{}, fmt.Errorf("bad statuscode: %d", res.StatusCode)

}

respBody, err := ioutil.ReadAll(res.Body)
Expand All @@ -7951,17 +7956,17 @@ func GetPipelines(ctx context.Context, OrgId string) ([]Pipeline, error) {
}
wrapper := AllPipelinesWrapper{}
err = json.Unmarshal(respBody, &wrapper)

if err != nil {
return []Pipeline{}, err
}

for _, hit := range wrapper.Hits.Hits {
pipeline := hit.Source
pipelines = append(pipelines, pipeline)
pipeline := hit.Source
pipelines = append(pipelines, pipeline)
}
return pipelines, err

} else {
// q := datastore.NewQuery(nameKey).Filter("org_id = ", OrgId).Limit(1000)

Expand Down Expand Up @@ -8332,7 +8337,7 @@ func SetHook(ctx context.Context, hook Hook) error {
func GetPipeline(ctx context.Context, triggerId string) (*Pipeline, error) {
pipeline := &Pipeline{}
nameKey := "pipelines"

triggerId = strings.ToLower(triggerId)

if project.DbType == "opensearch" {
Expand All @@ -8359,7 +8364,7 @@ func GetPipeline(ctx context.Context, triggerId string) (*Pipeline, error) {
}

pipeline = &wrapped.Source
} else {
} else {
// key := datastore.NameKey(nameKey, triggerId, nil)
// err := project.Dbclient.Get(ctx, key, pipeline)
// if err != nil {
Expand Down Expand Up @@ -8463,7 +8468,7 @@ func GetFile(ctx context.Context, id string) (*File, error) {
fileData, err := json.Marshal(curFile)
if err != nil {
log.Printf("[WARNING] Failed marshalling in getfile: %s", err)
return curFile, nil
return curFile, nil
}

err = SetCache(ctx, cacheKey, fileData, 30)
Expand Down Expand Up @@ -8566,6 +8571,7 @@ func SetFile(ctx context.Context, file File) error {
DeleteCache(ctx, fmt.Sprintf("files_%s_%s", file.OrgId, file.Namespace))
DeleteCache(ctx, fmt.Sprintf("files_%s_", file.OrgId))


return nil
}

Expand Down Expand Up @@ -8996,6 +9002,7 @@ func GetAllFiles(ctx context.Context, orgId, namespace string) ([]File, error) {
log.Printf("[WARNING] Failed updating file cache: %s", err)
}
}


return files, nil
}
Expand Down
21 changes: 4 additions & 17 deletions oauth2.go
Original file line number Diff line number Diff line change
Expand Up @@ -4081,32 +4081,19 @@ func VerifyIdToken(ctx context.Context, idToken string) (IdTokenCheck, error) {
foundOrg := ""
foundChallenge := ""
stateSplit := strings.Split(string(parsedState), "&")
regexPattern := `EXTRA string=([A-Za-z0-9~.]+)`
re := regexp.MustCompile(regexPattern)
for _, innerstate := range stateSplit {
itemsplit := strings.SplitN(innerstate, "=", 2)
itemsplit := strings.Split(innerstate, "=")
if len(itemsplit) <= 1 {
log.Printf("[WARNING] No key:value: %s", innerstate)
continue
}

key := strings.TrimSpace(itemsplit[0])
value := strings.TrimSpace(itemsplit[1])
if itemsplit[0] == "org" {
foundOrg = value
foundOrg = strings.TrimSpace(itemsplit[1])
}

if key == "challenge" {
// Extract the "extra string" value from the challenge value
matches := re.FindStringSubmatch(value)
if len(matches) > 1 {
extractedString := matches[1]
foundChallenge = extractedString
log.Printf("Extracted 'extra string' value is: %s", extractedString)
} else {
foundChallenge = strings.TrimSpace(itemsplit[1])
log.Printf("No 'extra string' value found in challenge: %s", value)
}
if itemsplit[0] == "challenge" {
foundChallenge = strings.TrimSpace(itemsplit[1])
}
}

Expand Down
Loading

0 comments on commit 3e0099c

Please sign in to comment.