Skip to content

Commit 0b5af5c

Browse files
committed
options for composing artifact meta data
1 parent 26bbab7 commit 0b5af5c

File tree

4 files changed

+49
-1
lines changed

4 files changed

+49
-1
lines changed

api/ocm/compdesc/componentdescriptor.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ type ArtifactMetaAccess interface {
138138
GetType() string
139139
SetType(string)
140140
ReferenceHintProvider
141+
ReferenceHintSink
141142
}
142143

143144
type ReferenceHintProvider interface {

api/ocm/elements/artifacts.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,49 @@
11
package elements
22

3+
import (
4+
"ocm.software/ocm/api/ocm/compdesc"
5+
"ocm.software/ocm/api/ocm/refhints"
6+
)
7+
38
type ArtifactOption interface {
49
ResourceMetaOption
510
SourceMetaOption
611
}
12+
13+
type artifactAccessor interface {
14+
compdesc.ReferenceHintSink
15+
}
16+
17+
type artifactOption struct {
18+
apply func(meta artifactAccessor) error
19+
}
20+
21+
type artifactOptionI interface {
22+
apply(sink artifactAccessor) error
23+
}
24+
25+
func newArtifactOption[T artifactOptionI](e T) ArtifactOption {
26+
return artifactOption{e.apply}
27+
}
28+
29+
func (o artifactOption) ApplyToResourceMeta(m *compdesc.ResourceMeta) error {
30+
return o.apply(m)
31+
}
32+
33+
func (o artifactOption) ApplyToSourceMeta(m *compdesc.SourceMeta) error {
34+
return o.apply(m)
35+
}
36+
37+
////////////////////////////////////////////////////////////////////////////////
38+
39+
type refhint string
40+
41+
func (o refhint) apply(m artifactAccessor) error {
42+
m.SetReferenceHints(refhints.ParseHints(string(o)))
43+
return nil
44+
}
45+
46+
// WithHint sets a serialized list of hints for the artifact metadata.
47+
func WithHint(v string) ArtifactOption {
48+
return newArtifactOption(refhint(v))
49+
}

api/ocm/internal/repository.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,14 @@ type ComponentVersionAccess interface {
176176

177177
// AdjustResourceAccess is used to modify the access spec. The old and new one MUST refer to the same content.
178178
AdjustResourceAccess(meta *ResourceMeta, acc compdesc.AccessSpec, opts ...ModificationOption) error
179+
// SetResourceBlob sets a resource given by a blob access, the optional hints (must be implicit) are observed
180+
// when adding a local blob to store them as implicit hints.
179181
SetResourceBlob(meta *ResourceMeta, blob BlobAccess, hints []refhints.ReferenceHint, global AccessSpec, opts ...BlobModificationOption) error
180182
AdjustSourceAccess(meta *SourceMeta, acc compdesc.AccessSpec) error
181183
// SetSourceBlob updates or sets anew source. The options only use the
182184
// target options. All other options are ignored.
185+
// The optional hints (must be implicit) are observed
186+
// when adding a local blob to store them as implicit hints.
183187
SetSourceBlob(meta *SourceMeta, blob BlobAccess, hints []refhints.ReferenceHint, global AccessSpec, opts ...TargetElementOption) error
184188

185189
// AccessMethod provides an access method implementation for

examples/lib/tour/02-composing-a-component-version/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ optional additional information:
192192
(we don't use it, here).
193193

194194
```go
195-
err = cv.SetResourceBlob(meta, blob, "", nil)
195+
err = cv.SetResourceBlob(meta, blob, nil, nil)
196196
if err != nil {
197197
return errors.Wrapf(err, "cannot add yaml document")
198198
}

0 commit comments

Comments
 (0)