-
Notifications
You must be signed in to change notification settings - Fork 8
/
registry_session.go
40 lines (31 loc) · 959 Bytes
/
registry_session.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
package main
import (
"fmt"
"github.com/docker/docker/registry"
)
type registrySession struct {
registry.Session
indexInfo *registry.IndexInfo
}
//return a registrySession associated with the repository contained in imageName
func newRegistrySession(userName, password string) (*registrySession, error) {
//IndexInfo
indexInfo := ®istry.IndexInfo{
Name: registry.INDEXNAME,
Mirrors: []string{},
Secure: true,
Official: true,
}
endpoint, err := registry.NewEndpoint(indexInfo)
if err != nil {
return nil, err
}
fmt.Printf("Index endpoint: %s\n", endpoint)
authConfig := ®istry.AuthConfig{Username: userName, Password: password}
var metaHeaders map[string][]string
session, err := registry.NewSession(authConfig, registry.HTTPRequestFactory(metaHeaders), endpoint, true)
if err != nil {
return nil, fmt.Errorf("failed to create registry session: %v", err)
}
return ®istrySession{*session, indexInfo}, nil
}