-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
client.go
47 lines (38 loc) · 1019 Bytes
/
client.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
package harbor
import (
"errors"
"fmt"
harbor "github.com/mittwald/goharbor-client/v5/apiv2"
harborCfg "github.com/mittwald/goharbor-client/v5/apiv2/pkg/config"
)
// harborClient creates an object storing
// the client.
type harborClient struct {
*harbor.RESTClient
}
// newClient creates a new client to access harbor
// and exposes it for any secrets or roles to use.
func newClient(config *harborConfig) (*harborClient, error) {
if config == nil {
return nil, errors.New("client configuration was nil")
}
if config.Username == "" {
return nil, errors.New("client username was not defined")
}
if config.Password == "" {
return nil, errors.New("client password was not defined")
}
if config.URL == "" {
return nil, errors.New("client URL was not defined")
}
c, err := harbor.NewRESTClientForHost(
fmt.Sprintf("%s/api/v2.0", config.URL),
config.Username,
config.Password,
&harborCfg.Options{PageSize: 100},
)
if err != nil {
return nil, err
}
return &harborClient{c}, nil
}