-
Notifications
You must be signed in to change notification settings - Fork 18
/
credentials.go
67 lines (56 loc) · 1.57 KB
/
credentials.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
package dockerconfig
import (
"github.com/docker/cli/cli/config/configfile"
dockercred "github.com/docker/cli/cli/config/credentials"
"github.com/docker/cli/cli/config/types"
"github.com/mandelsoft/goutils/set"
"github.com/open-component-model/ocm/pkg/common"
"github.com/open-component-model/ocm/pkg/contexts/credentials/cpi"
)
type Credentials struct {
config *configfile.ConfigFile
name string
store dockercred.Store
}
var _ cpi.Credentials = (*Credentials)(nil)
// NewCredentials describes a default getter method for a authentication method.
func NewCredentials(cfg *configfile.ConfigFile, name string, store dockercred.Store) cpi.Credentials {
return &Credentials{
config: cfg,
name: name,
store: store,
}
}
func (c *Credentials) get() common.Properties {
auth, err := c.config.GetAuthConfig(c.name)
if err != nil {
return common.Properties{}
}
return newCredentials(auth).Properties()
}
func (c *Credentials) Credentials(context cpi.Context, source ...cpi.CredentialsSource) (cpi.Credentials, error) {
var auth types.AuthConfig
var err error
if c.store == nil {
auth, err = c.config.GetAuthConfig(c.name)
} else {
auth, err = c.store.Get(c.name)
}
if err != nil {
return nil, err
}
return newCredentials(auth), nil
}
func (c *Credentials) ExistsProperty(name string) bool {
_, ok := c.get()[name]
return ok
}
func (c *Credentials) GetProperty(name string) string {
return c.get()[name]
}
func (c *Credentials) PropertyNames() set.Set[string] {
return c.get().Names()
}
func (c *Credentials) Properties() common.Properties {
return c.get()
}