/
type.go
52 lines (42 loc) · 1.53 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
// SPDX-FileCopyrightText: 2022 SAP SE or an SAP affiliate company and Open Component Model contributors.
//
// SPDX-License-Identifier: Apache-2.0
package docker
import (
"github.com/open-component-model/ocm/v2/pkg/contexts/credentials"
"github.com/open-component-model/ocm/v2/pkg/contexts/oci/cpi"
"github.com/open-component-model/ocm/v2/pkg/runtime"
"github.com/open-component-model/ocm/v2/pkg/utils"
)
const (
Type = "DockerDaemon"
TypeV1 = Type + runtime.VersionSeparator + "v1"
)
func init() {
cpi.RegisterRepositoryType(cpi.NewRepositoryType[*RepositorySpec](Type))
cpi.RegisterRepositoryType(cpi.NewRepositoryType[*RepositorySpec](TypeV1))
}
// RepositorySpec describes an OCI registry interface backed by an oci registry.
type RepositorySpec struct {
runtime.ObjectVersionedType `json:",inline"`
DockerHost string `json:"dockerHost,omitempty"`
}
// NewRepositorySpec creates a new RepositorySpec for an optional host.
func NewRepositorySpec(host ...string) *RepositorySpec {
return &RepositorySpec{
ObjectVersionedType: runtime.NewVersionedTypedObject(Type),
DockerHost: utils.Optional(host...),
}
}
func (a *RepositorySpec) GetType() string {
return Type
}
func (a *RepositorySpec) Name() string {
return Type
}
func (a *RepositorySpec) UniformRepositorySpec() *cpi.UniformRepositorySpec {
return cpi.UniformRepositorySpecForHostURL(Type, a.DockerHost)
}
func (a *RepositorySpec) Repository(ctx cpi.Context, creds credentials.Credentials) (cpi.Repository, error) {
return NewRepository(ctx, a)
}