gittuf/internal/attestations/common/common.go
Aditya Sirish A Yelgundhalli 17b058f7f4
*: Support multiple predicate versions
This commit moves existing implementations of attestation predicates into
subpackages to start supporting multiple versions in parallel.

Signed-off-by: Aditya Sirish A Yelgundhalli <ayelgundhall@bloomberg.net>
2024-10-23 10:37:01 -04:00

24 lines
513 B
Go

// Copyright The gittuf Authors
// SPDX-License-Identifier: Apache-2.0
package common
import (
"encoding/json"
"google.golang.org/protobuf/types/known/structpb"
)
func PredicateToPBStruct(predicate any) (*structpb.Struct, error) {
predicateBytes, err := json.Marshal(predicate)
if err != nil {
return nil, err
}
predicateInterface := &map[string]any{}
if err := json.Unmarshal(predicateBytes, predicateInterface); err != nil {
return nil, err
}
return structpb.NewStruct(*predicateInterface)
}