Skip to content

Commit

Permalink
Made fallback system for shuffle DB key work
Browse files Browse the repository at this point in the history
  • Loading branch information
frikky committed May 6, 2024
1 parent cf23304 commit 7915e4e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
2 changes: 1 addition & 1 deletion db-connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -10521,7 +10521,7 @@ func GetCacheKey(ctx context.Context, id string) (*CacheKeyData, error) {
log.Printf("[ERROR] Error in workflow loading. Migrating workflow to new workflow handler (2): %s", err)
err = nil
} else {
log.Printf("[ERROR] Error in cache key loading for %s: %s", id, err)
log.Printf("[WARNING] Error in cache key loading for %s: %s", id, err)

// Search for key by removing first uuid part
newId := id
Expand Down
37 changes: 32 additions & 5 deletions shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -14620,10 +14620,37 @@ func HandleGetCacheKey(resp http.ResponseWriter, request *http.Request) {
cacheId := fmt.Sprintf("%s_%s", tmpData.OrgId, tmpData.Key)
cacheData, err := GetCacheKey(ctx, cacheId)
if err != nil {
log.Printf("[WARNING][%s] Failed to GET cache key %s for org %s (get)", executionId, tmpData.Key, tmpData.OrgId)
resp.WriteHeader(401)
resp.Write([]byte(`{"success": false, "reason": "Failed authentication or key doesn't exist"}`))
return

// Doing a last resort search, e.g. to handle spaces and the like
allkeys, _, err := GetAllCacheKeys(ctx, org.Id, 30, "")
if err == nil {
cacheData = &CacheKeyData{}
searchkey := strings.ReplaceAll(strings.Trim(strings.ToLower(tmpData.Key), " "), " ", "_")

for _, key := range allkeys {
tmpkey := strings.ReplaceAll(strings.Trim(strings.ToLower(key.Key), " "), " ", "_")

log.Printf("%s vs %s", tmpkey, searchkey)
if tmpkey == searchkey {
log.Printf("\n\n[INFO] Found key %s for org %s\n\n", key.Key, org.Id)
cacheData = &key
break
}
}

if cacheData.Key == "" {
log.Printf("[WARNING] Failed to GET cache key %s for org %s (get)", tmpData.Key, tmpData.OrgId)
resp.WriteHeader(400)
resp.Write([]byte(`{"success": false, "reason": "Failed authentication or key doesn't exist"}`))
return
}

} else {
log.Printf("[WARNING][%s] Failed to GET cache key %s for org %s (get)", executionId, tmpData.Key, tmpData.OrgId)
resp.WriteHeader(400)
resp.Write([]byte(`{"success": false, "reason": "Failed authentication or key doesn't exist"}`))
return
}
}

if requireCacheAuth {
Expand Down Expand Up @@ -14737,7 +14764,7 @@ func HandleGetCacheKey(resp http.ResponseWriter, request *http.Request) {

b, err := json.Marshal(cacheData)
if err != nil {
log.Printf("[WARNING] Failed to GET cache key %s for org %s", tmpData.Key, tmpData.OrgId)
log.Printf("[WARNING] Failed to marshal cache data %s for org %s", tmpData.Key, tmpData.OrgId)
resp.WriteHeader(500)
resp.Write([]byte(`{"success": false, "reason": "Failed to get key. Does it exist?"}`))
return
Expand Down

0 comments on commit 7915e4e

Please sign in to comment.