-
Notifications
You must be signed in to change notification settings - Fork 8
/
apprclient.go
57 lines (45 loc) · 1.57 KB
/
apprclient.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
package apprclient
import (
"net/url"
"github.com/go-openapi/runtime"
httptransport "github.com/go-openapi/runtime/client"
"github.com/go-openapi/strfmt"
apprclient "github.com/operator-framework/go-appr/appregistry"
)
// NewClientFactory return a factory which can be used to instantiate a new appregistry client
func NewClientFactory() ClientFactory {
return &factory{}
}
type Options struct {
// Source refers to the URL of the remote app registry server.
Source string
// AuthToken refers to the authorization token required to access operator
// manifest in private repositories.
//
// If not set, it is assumed that the remote registry is public.
AuthToken string
}
// ClientFactory is an interface that wraps the New method.
type ClientFactory interface {
// New returns a new instance of appregistry Client from the specified source.
New(options Options) (Client, error)
}
type factory struct{}
func (f *factory) New(options Options) (Client, error) {
u, err := url.Parse(options.Source)
if err != nil {
return nil, err
}
transport := httptransport.New(u.Host, u.Path, []string{u.Scheme})
transport.Consumers["application/x-gzip"] = runtime.ByteStreamConsumer()
// If a token has been specified then we should pass it along in the headers
if options.AuthToken != "" {
tokenAuthWriter := httptransport.APIKeyAuth("Authorization", "header", options.AuthToken)
transport.DefaultAuthentication = tokenAuthWriter
}
c := apprclient.New(transport, strfmt.Default)
return &client{
adapter: &apprApiAdapterImpl{client: c},
decoder: &blobDecoderImpl{},
}, nil
}