-
Notifications
You must be signed in to change notification settings - Fork 35
/
client.go
42 lines (38 loc) · 1.2 KB
/
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
package oras
import (
"context"
"net/http"
"github.com/Azure/acr-cli/version"
"github.com/google/uuid"
"oras.land/oras-go/v2/registry/remote"
"oras.land/oras-go/v2/registry/remote/auth"
)
// ClientOptions type includes a Credential that stores the credentials
// of the client. CredentialStore will be used if a Credential is not
// provided. ClientOptions also includes a Debug flag.
type ClientOptions struct {
Credential auth.Credential
CredentialStore *Store
Debug bool
}
// NewClient generates a client based on the passed in options.
func NewClient(opts ClientOptions) remote.Client {
client := &auth.Client{
Cache: auth.NewCache(),
ClientID: "acr-cli",
Header: http.Header{},
}
client.Header.Set("x-ms-correlation-request-id", uuid.New().String())
client.SetUserAgent("acr-cli/" + version.FullVersion())
if opts.Debug {
client.Client.Transport = NewDebugTransport(client.Client.Transport)
}
if opts.Credential != auth.EmptyCredential {
client.Credential = func(_ context.Context, _ string) (auth.Credential, error) {
return opts.Credential, nil
}
} else if opts.CredentialStore != nil {
client.Credential = opts.CredentialStore.Credential
}
return client
}