Skip to content

Commit

Permalink
[webhook] index a list of predefined attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
williamchong committed Jun 13, 2024
1 parent f169f70 commit 38eeab0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions webhook/attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ package webhook

import (
"fmt"
"slices"

"github.com/starlinglab/integrity-v2/aa"
"github.com/starlinglab/integrity-v2/util"
)

// list of attributes that should be indexed as string
var indexedStringKeys []string = []string{"file_name", "asset_origin_id"}

// ParseMapToAttributes parses a map and a file stat map
// to a slice of attributes for POSTing to the AA server
// It also reads the encryption keys from the filesystem,
Expand All @@ -30,6 +34,8 @@ func ParseMapToAttributes(cid string, attrMap map[string]any, fileAttributes map
}
attributes = append(attributes, aa.PostKV{Key: pKey, Value: pValue, EncKey: encKey})
}
} else if slices.Contains(indexedStringKeys, key) {
attributes = append(attributes, aa.PostKV{Key: key, Value: value, Type: "str"})
} else {
attributes = append(attributes, aa.PostKV{Key: key, Value: value})
}
Expand Down
2 changes: 1 addition & 1 deletion webhook/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func handleGenericFileUpload(w http.ResponseWriter, r *http.Request) {
writeJsonResponse(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
return
}
err = aa.SetAttestations(cid, false, attributes)
err = aa.SetAttestations(cid, true, attributes)
if err != nil {
fmt.Println("Error setting attestations:", err)
writeJsonResponse(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
Expand Down

0 comments on commit 38eeab0

Please sign in to comment.