-
Notifications
You must be signed in to change notification settings - Fork 18
/
bridge_r.go
115 lines (91 loc) · 3.01 KB
/
bridge_r.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and Open Component Model contributors.
//
// SPDX-License-Identifier: Apache-2.0
package repocpi
import (
"io"
"github.com/open-component-model/ocm/pkg/contexts/ocm/cpi"
"github.com/open-component-model/ocm/pkg/errors"
"github.com/open-component-model/ocm/pkg/refmgmt"
"github.com/open-component-model/ocm/pkg/refmgmt/resource"
"github.com/open-component-model/ocm/pkg/utils"
)
type ComponentAccessInfo struct {
Impl ComponentAccessImpl
Kind string
Main bool
}
type RepositoryImpl interface {
SetBridge(bridge RepositoryBridge)
GetContext() cpi.Context
IsReadOnly() bool
SetReadOnly()
GetSpecification() cpi.RepositorySpec
ComponentLister() cpi.ComponentLister
ExistsComponentVersion(name string, version string) (bool, error)
LookupComponent(name string) (*ComponentAccessInfo, error)
io.Closer
}
type _repositoryBridgeBase = resource.ResourceImplBase[cpi.Repository]
type repositoryBridge struct {
*_repositoryBridgeBase
ctx cpi.Context
kind string
impl RepositoryImpl
}
var _ utils.Unwrappable = (*repositoryBridge)(nil)
func newRepositoryBridge(impl RepositoryImpl, kind string, closer ...io.Closer) RepositoryBridge {
base := resource.NewSimpleResourceImplBase[cpi.Repository](closer...)
b := &repositoryBridge{
_repositoryBridgeBase: base,
ctx: impl.GetContext(),
impl: impl,
}
impl.SetBridge(b)
return b
}
func (b *repositoryBridge) Close() error {
list := errors.ErrListf("closing %s", b.kind)
refmgmt.AllocLog.Trace("closing repository bridge", "kind", b.kind)
list.Add(b.impl.Close())
list.Add(b._repositoryBridgeBase.Close())
refmgmt.AllocLog.Trace("closed repository bridge", "kind", b.kind)
return list.Result()
}
func (b *repositoryBridge) GetContext() cpi.Context {
return b.ctx
}
func (b *repositoryBridge) IsReadOnly() bool {
return b.impl.IsReadOnly()
}
func (b *repositoryBridge) SetReadOnly() {
b.impl.SetReadOnly()
}
func (b *repositoryBridge) Unwrap() interface{} {
return b.impl
}
func (b *repositoryBridge) GetSpecification() cpi.RepositorySpec {
return b.impl.GetSpecification()
}
func (b *repositoryBridge) ComponentLister() cpi.ComponentLister {
return b.impl.ComponentLister()
}
func (b *repositoryBridge) ExistsComponentVersion(name string, version string) (bool, error) {
return b.impl.ExistsComponentVersion(name, version)
}
func (b *repositoryBridge) LookupComponentVersion(name string, version string) (cv cpi.ComponentVersionAccess, rerr error) {
c, err := b.LookupComponent(name)
if err != nil {
return nil, err
}
defer refmgmt.PropagateCloseTemporary(&rerr, c) // temporary component object not exposed.
refmgmt.AllocLog.Trace("lookup version for temporary component ref", "component", name, "version", version)
return c.LookupVersion(version)
}
func (b *repositoryBridge) LookupComponent(name string) (cpi.ComponentAccess, error) {
i, err := b.impl.LookupComponent(name)
if err != nil {
return nil, err
}
return NewComponentAccess(i.Impl, i.Kind, i.Main)
}