MCPcopy Create free account
hub / github.com/conforma/cli / createAndPushPolicyBundle

Function createAndPushPolicyBundle

acceptance/image/image.go:1186–1224  ·  view source on GitHub ↗

createAndPushPolicyBundle creates a OCI policy bundle with the given files as layers

(ctx context.Context, imageName string, files *godog.Table)

Source from the content-addressed store, hash-verified

1184// createAndPushPolicyBundle creates a OCI policy bundle with the given files as
1185// layers
1186func createAndPushPolicyBundle(ctx context.Context, imageName string, files *godog.Table) (context.Context, error) {
1187 bundle := mutate.MediaType(empty.Image, types.OCIManifestSchema1)
1188 bundle = mutate.ConfigMediaType(bundle, types.OCIConfigJSON)
1189
1190 // add each row as a layer to the bundle
1191 for _, row := range files.Rows {
1192 file := row.Cells[0].Value
1193
1194 source := row.Cells[1].Value
1195
1196 bytes, err := os.ReadFile(path.Join("acceptance", source))
1197 if err != nil {
1198 return ctx, err
1199 }
1200
1201 if bundle, err = mutate.Append(bundle, mutate.Addendum{
1202 MediaType: openPolicyAgentData,
1203 Layer: s.NewLayer(bytes, openPolicyAgentData),
1204 Annotations: map[string]string{
1205 title: file,
1206 },
1207 }); err != nil {
1208 return ctx, err
1209 }
1210 }
1211
1212 ref, err := registry.ImageReferenceInStubRegistry(ctx, imageName)
1213 if err != nil {
1214 return ctx, err
1215 }
1216
1217 // push to the registry
1218 err = remote.Write(ref, bundle)
1219 if err != nil {
1220 return ctx, err
1221 }
1222
1223 return ctx, nil
1224}
1225
1226// AttestationFrom finds the raw attestation created by the createAndPushAttestation
1227func AttestationFrom(ctx context.Context, imageName string) ([]byte, error) {

Callers

nothing calls this directly

Calls 3

MediaTypeMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected