-
Notifications
You must be signed in to change notification settings - Fork 22
/
type.go
56 lines (45 loc) · 1.6 KB
/
type.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
package directcreds
import (
"github.com/open-component-model/ocm/pkg/common"
"github.com/open-component-model/ocm/pkg/contexts/credentials/cpi"
"github.com/open-component-model/ocm/pkg/runtime"
)
const (
Type = "Credentials"
TypeV1 = Type + runtime.VersionSeparator + "v1"
)
func init() {
cpi.RegisterRepositoryType(cpi.NewRepositoryType[*RepositorySpec](Type))
cpi.RegisterRepositoryType(cpi.NewRepositoryType[*RepositorySpec](TypeV1, cpi.WithDescription(usage), cpi.WithFormatSpec(format)))
}
// RepositorySpec describes a repository interface for single direct credentials.
type RepositorySpec struct {
runtime.ObjectVersionedType `json:",inline"`
Properties common.Properties `json:"properties"`
}
var (
_ cpi.RepositorySpec = &RepositorySpec{}
_ cpi.CredentialsSpec = &RepositorySpec{}
)
// NewRepositorySpec creates a new RepositorySpec.
func NewRepositorySpec(credentials common.Properties) *RepositorySpec {
return &RepositorySpec{
ObjectVersionedType: runtime.NewVersionedTypedObject(Type),
Properties: credentials,
}
}
func (a *RepositorySpec) GetType() string {
return Type
}
func (a *RepositorySpec) Repository(ctx cpi.Context, creds cpi.Credentials) (cpi.Repository, error) {
return NewRepository(cpi.NewCredentials(a.Properties)), nil
}
func (a *RepositorySpec) Credentials(context cpi.Context, source ...cpi.CredentialsSource) (cpi.Credentials, error) {
return cpi.NewCredentials(a.Properties), nil
}
func (a *RepositorySpec) GetCredentialsName() string {
return ""
}
func (a *RepositorySpec) GetRepositorySpec(context cpi.Context) cpi.RepositorySpec {
return a
}