MCPcopy Create free account
hub / github.com/chainloop-dev/chainloop / unmarshallResource

Function unmarshallResource

pkg/policies/loader.go:243–265  ·  view source on GitHub ↗
(raw []byte, ref string, digest string, dest proto.Message)

Source from the content-addressed store, hash-verified

241}
242
243func unmarshallResource(raw []byte, ref string, digest string, dest proto.Message) (*PolicyDescriptor, error) {
244 jsonContent, err := unmarshal.LoadJSONBytes(raw, filepath.Ext(ref))
245 if err != nil {
246 return nil, fmt.Errorf("loading resource spec: %w", err)
247 }
248
249 if err := protojson.Unmarshal(jsonContent, dest); err != nil {
250 return nil, fmt.Errorf("unmarshalling policy spec: %w", err)
251 }
252
253 // calculate hash of the raw data
254 h, _, err := crv1.SHA256(bytes.NewBuffer(raw))
255 if err != nil {
256 return nil, fmt.Errorf("calculating hash: %w", err)
257 }
258
259 // compare it with the wanted digest if needed
260 if digest != "" && h.String() != digest {
261 return nil, fmt.Errorf("digest mismatch: got %s, want %s", h.String(), digest)
262 }
263
264 return policyReferenceResourceDescriptor("", ref, "", h), nil
265}
266
267// IsProviderScheme takes a policy reference and returns whether it's referencing to an external provider or not
268func IsProviderScheme(ref string) bool {

Callers 4

LoadMethod · 0.85
LoadMethod · 0.85
LoadMethod · 0.85
LoadMethod · 0.85

Calls 3

LoadJSONBytesFunction · 0.92
StringMethod · 0.65

Tested by

no test coverage detected