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

Method Load

pkg/policies/loader.go:102–127  ·  view source on GitHub ↗
(_ context.Context, attachment *v1.PolicyAttachment)

Source from the content-addressed store, hash-verified

100type FileLoader struct{}
101
102func (l *FileLoader) Load(_ context.Context, attachment *v1.PolicyAttachment) (*v1.Policy, *PolicyDescriptor, error) {
103 var (
104 raw []byte
105 err error
106 )
107
108 // First remove the digest if present
109 ref, wantDigest := ExtractDigest(attachment.GetRef())
110 filePath, err := ensureScheme(ref, fileScheme)
111 if err != nil {
112 return nil, nil, err
113 }
114
115 raw, err = os.ReadFile(filepath.Clean(filePath))
116 if err != nil {
117 return nil, nil, fmt.Errorf("loading policy spec: %w", err)
118 }
119
120 var policy v1.Policy
121 d, err := unmarshallResource(raw, ref, wantDigest, &policy)
122 if err != nil {
123 return nil, nil, fmt.Errorf("unmarshalling policy spec: %w", err)
124 }
125
126 return &policy, d, nil
127}
128
129// HTTPSLoader loader loads policies from HTTP or HTTPS references
130type HTTPSLoader struct{}

Callers

nothing calls this directly

Calls 4

ExtractDigestFunction · 0.85
ensureSchemeFunction · 0.85
unmarshallResourceFunction · 0.85
GetRefMethod · 0.45

Tested by

no test coverage detected