Don't use pointers for image interfaces (#51)
* Don't use pointers for image interfaces * Also for oci layout * Remove default case
This commit is contained in:
@@ -130,7 +130,7 @@ func TestReferencesInDifferentRepo(t *testing.T) {
|
||||
// push signed attestation image to the ref server
|
||||
for _, img := range signedImages {
|
||||
// push references using subject-digest.att convention
|
||||
err = mirror.PushToRegistry(&img.Image, fmt.Sprintf("%s/%s:tag-does-not-matter", refServerUrl.Host, repoName))
|
||||
err = mirror.PushToRegistry(img.Image, fmt.Sprintf("%s/%s:tag-does-not-matter", refServerUrl.Host, repoName))
|
||||
require.NoError(t, err)
|
||||
}
|
||||
mfs2, err := attIdx.Index.IndexManifest()
|
||||
|
||||
@@ -39,18 +39,16 @@ func PushToRegistry(image any, imageName string) error {
|
||||
}
|
||||
// Push the image to the registry
|
||||
switch image := image.(type) {
|
||||
case *v1.Image:
|
||||
if err := remote.Write(ref, *image, remote.WithAuth(auth)); err != nil {
|
||||
case v1.Image:
|
||||
if err := remote.Write(ref, image, remote.WithAuth(auth)); err != nil {
|
||||
return fmt.Errorf("failed to push image %s: %w", imageName, err)
|
||||
}
|
||||
case *v1.ImageIndex:
|
||||
if err := remote.WriteIndex(ref, *image, remote.WithAuth(auth)); err != nil {
|
||||
case v1.ImageIndex:
|
||||
if err := remote.WriteIndex(ref, image, remote.WithAuth(auth)); err != nil {
|
||||
return fmt.Errorf("failed to push image index %s: %w", imageName, err)
|
||||
}
|
||||
default:
|
||||
if err := remote.WriteIndex(ref, image.(v1.ImageIndex), remote.WithAuth(auth)); err != nil {
|
||||
return fmt.Errorf("failed to push image index %s: %w", imageName, err)
|
||||
}
|
||||
return fmt.Errorf("unknown image type")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -62,26 +60,23 @@ func SaveAsOCILayout(image any, path string) error {
|
||||
return fmt.Errorf("failed to create directory: %w", err)
|
||||
}
|
||||
switch image := image.(type) {
|
||||
case *v1.Image:
|
||||
case v1.Image:
|
||||
index := empty.Index
|
||||
l, err := layout.Write(path, index)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create index: %w", err)
|
||||
}
|
||||
err = l.AppendImage(*image)
|
||||
err = l.AppendImage(image)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to append image to index: %w", err)
|
||||
}
|
||||
case *v1.ImageIndex:
|
||||
_, err := layout.Write(path, *image)
|
||||
case v1.ImageIndex:
|
||||
_, err := layout.Write(path, image)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create index: %w", err)
|
||||
}
|
||||
default:
|
||||
_, err := layout.Write(path, image.(v1.ImageIndex))
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create index: %w", err)
|
||||
}
|
||||
return fmt.Errorf("unknown image type")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user