forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
manifest.go
50 lines (39 loc) · 1.22 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
44
45
46
47
48
49
50
package image
import (
"context"
"net/http"
"net/url"
godigest "github.com/opencontainers/go-digest"
"k8s.io/client-go/rest"
"github.com/openshift/origin/pkg/image/registryclient"
)
// 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, insecure bool) ([]byte, error) {
ctx := context.Background()
credentials := registryclient.NewBasicCredentials()
credentials.Add(registry, username, password)
insecureRT, err := rest.TransportFor(&rest.Config{TLSClientConfig: rest.TLSClientConfig{Insecure: true}})
if err != nil {
return nil, err
}
repo, err := registryclient.NewContext(http.DefaultTransport, insecureRT).
WithCredentials(credentials).
Repository(ctx, registry, repositoryName, insecure)
if err != nil {
return nil, err
}
manifests, err := repo.Manifests(ctx, nil)
if err != nil {
return nil, err
}
manifest, err := manifests.Get(ctx, godigest.Digest(imageID))
if err != nil {
return nil, err
}
_, manifestPayload, err := manifest.Payload()
if err != nil {
return nil, err
}
return manifestPayload, nil
}