-
Notifications
You must be signed in to change notification settings - Fork 18
/
repository.go
66 lines (52 loc) · 1.59 KB
/
repository.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
// SPDX-FileCopyrightText: 2022 SAP SE or an SAP affiliate company and Open Component Model contributors.
//
// SPDX-License-Identifier: Apache-2.0
package internal
import (
"github.com/open-component-model/ocm/pkg/common"
"github.com/open-component-model/ocm/pkg/generics"
)
type Repository interface {
ExistsCredentials(name string) (bool, error)
LookupCredentials(name string) (Credentials, error)
WriteCredentials(name string, creds Credentials) (Credentials, error)
}
type Credentials interface {
CredentialsSource
ExistsProperty(name string) bool
GetProperty(name string) string
PropertyNames() generics.Set[string]
Properties() common.Properties
}
type DirectCredentials common.Properties
var _ Credentials = (*DirectCredentials)(nil)
func NewCredentials(props common.Properties) DirectCredentials {
if props == nil {
props = common.Properties{}
} else {
props = props.Copy()
}
return DirectCredentials(props)
}
func (c DirectCredentials) ExistsProperty(name string) bool {
_, ok := c[name]
return ok
}
func (c DirectCredentials) GetProperty(name string) string {
return c[name]
}
func (c DirectCredentials) PropertyNames() generics.Set[string] {
return common.Properties(c).Names()
}
func (c DirectCredentials) Properties() common.Properties {
return common.Properties(c).Copy()
}
func (c DirectCredentials) Credentials(Context, ...CredentialsSource) (Credentials, error) {
return c, nil
}
func (c DirectCredentials) Copy() DirectCredentials {
return DirectCredentials(common.Properties(c).Copy())
}
func (c DirectCredentials) String() string {
return common.Properties(c).String()
}