Skip to content

Commit

Permalink
merge branch 'main' into feature/wacz
Browse files Browse the repository at this point in the history
  • Loading branch information
williamchong committed Jun 12, 2024
2 parents d61b814 + c2cf3a4 commit 8aa1c1a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 32 deletions.
1 change: 1 addition & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ jobs:
uses: golangci/golangci-lint-action@v6
with:
version: v1.58
args: --timeout=5m
27 changes: 15 additions & 12 deletions preprocessor/folder/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,15 @@ func getProofModeFileMetadatas(filePath string) ([]map[string]any, error) {
"asset_origin_id": assetOrigin,
"asset_origin_type": []string{"proofmode"},
"media_type": asset.MediaType,
"proofmode": map[string]any{
"metadata": string(asset.MetadataBytes),
"meta_sig": string(asset.MetadataSignature),
"media_sig": string(asset.AssetSignature),
"pubkey": string(asset.PubKey),
"ots": asset.Ots,
"gst": string(asset.Gst),
"private": map[string]any{ // "private" fields are encrypted
"proofmode": map[string]any{
"metadata": string(asset.MetadataBytes),
"meta_sig": string(asset.MetadataSignature),
"media_sig": string(asset.AssetSignature),
"pubkey": string(asset.PubKey),
"ots": asset.Ots,
"gst": string(asset.Gst),
},
},
}
metadatas = append(metadatas, metadata)
Expand Down Expand Up @@ -105,11 +107,12 @@ func getFileMetadata(filePath string, mediaType string) (map[string]any, error)
return nil, err
}
return map[string]any{
"media_type": mediaType,
"asset_origin_id": getAssetOriginRoot(filePath),
"file_name": fileInfo.Name(),
"last_modified": fileInfo.ModTime().UTC().Format(time.RFC3339),
"time_created": fileInfo.ModTime().UTC().Format(time.RFC3339),
"media_type": mediaType,
"asset_origin_id": getAssetOriginRoot(filePath),
"asset_origin_type": []string{"folder"},
"file_name": fileInfo.Name(),
"last_modified": fileInfo.ModTime().UTC().Format(time.RFC3339),
"time_created": fileInfo.ModTime().UTC().Format(time.RFC3339),
}, nil
}

Expand Down
4 changes: 1 addition & 3 deletions upload/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ It also supports the following:
web3.storage requires providing the "space" the file is uploaded to instead of
a path.
For traditional storage providers, the path is always a directory.
CIDs are retrieved from the "files" and "c2pa" storage locations.`)
For traditional storage providers, the path is always a directory.`)
return nil
}
if len(args) < 2 {
Expand Down
36 changes: 19 additions & 17 deletions webhook/attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,41 @@ package webhook

import (
"fmt"
"slices"

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

// fields that are marked as private
var privateFields = []string{"private", "proofmode"}

// 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,
// if fields are marked as private
// if fields are put under "private" key.
// Note that all keys under "private" are promoted to top level
// in encrypted form
func ParseMapToAttributes(cid string, attrMap map[string]any, fileAttributes map[string]any) ([]aa.PostKV, error) {

var attributes []aa.PostKV

for k, v := range attrMap {
// TODO: add whitelist/blacklist for attributes in config

var encKey []byte
if slices.Contains(privateFields, k) {
_, keyBytes, _, err := util.GenerateEncKey(cid, k)
if err != nil {
return nil, fmt.Errorf("error reading key: %w", err)
for key, value := range attrMap {
if key == "private" {
privMap, ok := value.(map[string]any)
if !ok {
return nil, fmt.Errorf("private must be a map of private key-value pairs")
}
for pKey, pValue := range privMap {
_, encKey, _, err := util.GenerateEncKey(cid, pKey)
if err != nil {
return nil, fmt.Errorf("error reading key: %w", err)
}
attributes = append(attributes, aa.PostKV{Key: pKey, Value: pValue, EncKey: encKey})
}
encKey = keyBytes
} else {
attributes = append(attributes, aa.PostKV{Key: key, Value: value})
}
attributes = append(attributes, aa.PostKV{Key: k, Value: v, EncKey: encKey})
}

for k, v := range fileAttributes {
attributes = append(attributes, aa.PostKV{Key: k, Value: v})
for key, value := range fileAttributes {
attributes = append(attributes, aa.PostKV{Key: key, Value: value})
}

return attributes, nil
Expand Down

0 comments on commit 8aa1c1a

Please sign in to comment.