forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
manifest.go
43 lines (34 loc) · 1.02 KB
/
manifest.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package util
import (
"context"
"net/http"
"net/url"
"github.com/docker/distribution/digest"
"github.com/openshift/origin/pkg/image/importer"
)
// GetImageManifestByIDFromRegistry retrieves the image manifest from the registry using the basic
// authentication using the image ID.
func GetImageManifestByIDFromRegistry(registry *url.URL, repositoryName, imageID, username, password string) ([]byte, error) {
ctx := context.Background()
credentials := importer.NewBasicCredentials()
credentials.Add(registry, username, password)
repo, err := importer.NewContext(http.DefaultTransport, http.DefaultTransport).
WithCredentials(credentials).
Repository(ctx, registry, repositoryName, true)
if err != nil {
return nil, err
}
manifests, err := repo.Manifests(ctx, nil)
if err != nil {
return nil, err
}
manifest, err := manifests.Get(ctx, digest.Digest(imageID))
if err != nil {
return nil, err
}
_, manifestPayload, err := manifest.Payload()
if err != nil {
return nil, err
}
return manifestPayload, nil
}