/
componentversion.go
98 lines (76 loc) · 2.91 KB
/
componentversion.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
// SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and Gardener contributors
//
// SPDX-License-Identifier: Apache-2.0
package ocmlib
import (
"context"
"errors"
"fmt"
cdv2 "github.com/gardener/component-spec/bindings-go/apis/v2"
"github.com/open-component-model/ocm/pkg/contexts/ocm"
lsv1alpha1 "github.com/gardener/landscaper/apis/core/v1alpha1"
"github.com/gardener/landscaper/pkg/components/model"
"github.com/gardener/landscaper/pkg/components/model/componentoverwrites"
"github.com/gardener/landscaper/pkg/components/model/types"
)
type ComponentVersion struct {
registryAccess *RegistryAccess
componentVersionAccess ocm.ComponentVersionAccess
componentDescriptorV2 cdv2.ComponentDescriptor
}
var _ model.ComponentVersion = &ComponentVersion{}
func (c *ComponentVersion) GetSchemaVersion() string {
return c.componentVersionAccess.GetDescriptor().SchemaVersion()
}
func (c *ComponentVersion) GetName() string {
return c.componentVersionAccess.GetName()
}
func (c *ComponentVersion) GetVersion() string {
return c.componentVersionAccess.GetVersion()
}
func (c *ComponentVersion) GetComponentDescriptor() *types.ComponentDescriptor {
return &c.componentDescriptorV2
}
func (c *ComponentVersion) GetRepositoryContext() *types.UnstructuredTypedObject {
return c.componentDescriptorV2.GetEffectiveRepositoryContext()
}
func (c *ComponentVersion) GetComponentReferences() []types.ComponentReference {
return c.componentDescriptorV2.ComponentReferences
}
func (c *ComponentVersion) GetComponentReference(name string) *types.ComponentReference {
refs := c.GetComponentReferences()
for i := range refs {
ref := &refs[i]
if ref.GetName() == name {
return ref
}
}
return nil
}
func (c *ComponentVersion) GetReferencedComponentVersion(ctx context.Context, ref *types.ComponentReference, repositoryContext *types.UnstructuredTypedObject, overwriter componentoverwrites.Overwriter) (model.ComponentVersion, error) {
if ref == nil {
return nil, errors.New("component reference cannot be nil")
}
cdRef := &lsv1alpha1.ComponentDescriptorReference{
RepositoryContext: repositoryContext,
ComponentName: ref.ComponentName,
Version: ref.Version,
}
return model.GetComponentVersionWithOverwriter(ctx, c.registryAccess, cdRef, overwriter)
}
func (c *ComponentVersion) GetResource(name string, identity map[string]string) (model.Resource, error) {
resources, err := c.componentVersionAccess.GetResourcesByName(name, cdv2.Identity(identity))
if err != nil {
return nil, err
}
if len(resources) < 1 {
return nil, fmt.Errorf("no resource with name %s and extra identities %v found", name, identity)
}
if len(resources) > 1 {
return nil, fmt.Errorf("there is more than one resource with name %s and extra identities %v", name, identity)
}
return NewResource(resources[0]), nil
}
func (c *ComponentVersion) GetOCMObject() ocm.ComponentVersionAccess {
return c.componentVersionAccess
}