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

Method Load

pkg/policies/group_loader.go:72–98  ·  view source on GitHub ↗
(_ context.Context, attachment *v1.PolicyGroupAttachment)

Source from the content-addressed store, hash-verified

70type HTTPSGroupLoader struct{}
71
72func (l *HTTPSGroupLoader) Load(_ context.Context, attachment *v1.PolicyGroupAttachment) (*v1.PolicyGroup, *PolicyDescriptor, error) {
73 ref, wantDigest := ExtractDigest(attachment.GetRef())
74
75 // and do not remove the scheme since we need http(s):// to make the request
76 if _, err := ensureScheme(ref, httpScheme, httpsScheme); err != nil {
77 return nil, nil, fmt.Errorf("invalid policy reference %q: %w", ref, err)
78 }
79
80 // #nosec G107
81 resp, err := http.Get(ref)
82 if err != nil {
83 return nil, nil, fmt.Errorf("requesting remote policy: %w", err)
84 }
85 defer resp.Body.Close()
86 raw, err := io.ReadAll(resp.Body)
87 if err != nil {
88 return nil, nil, fmt.Errorf("reading remote policy: %w", err)
89 }
90
91 var group v1.PolicyGroup
92 d, err := unmarshallResource(raw, ref, wantDigest, &group)
93 if err != nil {
94 return nil, nil, fmt.Errorf("unmarshalling policy spec: %w", err)
95 }
96
97 return &group, d, nil
98}
99
100// ChainloopGroupLoader loads groups referenced with chainloop://provider/name URLs
101type ChainloopGroupLoader struct {

Callers

nothing calls this directly

Calls 6

ExtractDigestFunction · 0.85
ensureSchemeFunction · 0.85
unmarshallResourceFunction · 0.85
GetMethod · 0.65
GetRefMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected