forked from ehazlett/shipyard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
registry.go
81 lines (66 loc) · 2.15 KB
/
registry.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package shipyard
import (
"crypto/tls"
registry "github.com/shipyard/shipyard/registry/v2"
"strings"
)
type Registry struct {
ID string `json:"id,omitempty" gorethink:"id,omitempty"`
Name string `json:"name,omitempty" gorethink:"name,omitempty"`
Addr string `json:"addr,omitempty" gorethink:"addr,omitempty"`
Username string `json:"username,omitempty" gorethink:"username,omitempty"`
Password string `json:"password,omitempty" gorethink:"password,omitempty"`
TlsSkipVerify bool `json:"tls_skip_verify,omitempty" gorethink:"tls_skip_verify,omitempty"`
registryClient *registry.RegistryClient `json:"-" gorethink:"-"`
}
func NewRegistry(id, name, addr, username, password string, tls_skip_verify bool) (*Registry, error) {
var tlsConfig *tls.Config
if tls_skip_verify {
tlsConfig = &tls.Config{InsecureSkipVerify: true}
}
rClient, err := registry.NewRegistryClient(addr, tlsConfig, username, password)
if err != nil {
return nil, err
}
return &Registry{
ID: id,
Name: name,
Addr: addr,
Username: username,
Password: password,
TlsSkipVerify: tls_skip_verify,
registryClient: rClient,
}, nil
}
func (r *Registry) InitRegistryClient() error {
var tlsConfig *tls.Config
if r.TlsSkipVerify {
tlsConfig = &tls.Config{InsecureSkipVerify: true}
}
rClient, err := registry.NewRegistryClient(r.Addr, tlsConfig, r.Username, r.Password)
if err != nil {
return err
}
r.registryClient = rClient
return nil
}
func (r *Registry) Repositories() ([]*registry.Repository, error) {
res, err := r.registryClient.Search("")
if err != nil {
return nil, err
}
return res, nil
}
func (r *Registry) Repository(name string) (*registry.Repository, error) {
repoPath := name
tag := "latest"
parts := strings.Split(name, ":")
if len(parts) == 2 {
repoPath = parts[0]
tag = parts[1]
}
return r.registryClient.Repository(r.Addr, repoPath, tag)
}
func (r *Registry) DeleteRepository(name string) error {
return r.registryClient.DeleteRepository(name)
}