Skip to content

Commit 970c7bf

Browse files
committed
incorporate review
1 parent 4ce7daa commit 970c7bf

File tree

16 files changed

+85
-78
lines changed

16 files changed

+85
-78
lines changed

api/ocm/plugin/interface.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ type (
5151
TargetRepositorySpec = internal.TargetRepositorySpec
5252
TransferOptions = internal.TransferOptions
5353

54-
Artifact = internal.Artifact
55-
AccessInfo = internal.UniformAccessSpecInfo
56-
Question = internal.Question
57-
ComponentVersionQuestion = internal.ComponentVersionQuestion
58-
ComponentReferenceQuestion = internal.ComponentReferenceQuestion
59-
ArtifactQuestion = internal.ArtifactQuestion
60-
Resolution = internal.Resolution
61-
DecisionRequestResult = internal.DecisionRequestResult
54+
Artifact = internal.Artifact
55+
AccessInfo = internal.UniformAccessSpecInfo
56+
QuestionArguments = internal.QuestionArguments
57+
ComponentVersionQuestionArguments = internal.ComponentVersionQuestionArguments
58+
ComponentReferenceQuestionArguments = internal.ComponentReferenceQuestionArguments
59+
ArtifactQuestionArguments = internal.ArtifactQuestionArguments
60+
Resolution = internal.Resolution
61+
DecisionRequestResult = internal.DecisionRequestResult
6262
)

api/ocm/plugin/internal/transfer.go

+37-17
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ const (
2222
)
2323

2424
var TransferHandlerQuestions = map[string]reflect.Type{
25-
Q_UPDATE_VERSION: generics.TypeOf[ComponentVersionQuestion](),
26-
Q_ENFORCE_TRANSPORT: generics.TypeOf[ComponentVersionQuestion](),
27-
Q_OVERWRITE_VERSION: generics.TypeOf[ComponentVersionQuestion](),
28-
Q_TRANSFER_VERSION: generics.TypeOf[ComponentReferenceQuestion](),
29-
Q_TRANSFER_RESOURCE: generics.TypeOf[ArtifactQuestion](),
30-
Q_TRANSFER_SOURCE: generics.TypeOf[ArtifactQuestion](),
25+
Q_UPDATE_VERSION: generics.TypeOf[ComponentVersionQuestionArguments](),
26+
Q_ENFORCE_TRANSPORT: generics.TypeOf[ComponentVersionQuestionArguments](),
27+
Q_OVERWRITE_VERSION: generics.TypeOf[ComponentVersionQuestionArguments](),
28+
Q_TRANSFER_VERSION: generics.TypeOf[ComponentReferenceQuestionArguments](),
29+
Q_TRANSFER_RESOURCE: generics.TypeOf[ArtifactQuestionArguments](),
30+
Q_TRANSFER_SOURCE: generics.TypeOf[ArtifactQuestionArguments](),
3131
}
3232

3333
type UniformAccessSpecInfo = tech.UniformAccessSpecInfo
@@ -83,27 +83,35 @@ type DecisionRequestResult struct {
8383
Resolution *Resolution `json:"resolution,omitempty"`
8484
}
8585

86-
// Question is the interface for the question attributes
86+
// QuestionArguments is the interface for the question attributes
8787
// differing for the various questions types.
8888
// There are three basic attribute sets:
89-
// - ComponentVersionQuestion
90-
// - ComponentReferenceQuestion
91-
// - ArtifactQuestion
89+
// - ComponentVersionQuestionArguments
90+
// - ComponentReferenceQuestionArguments
91+
// - ArtifactQuestionArguments
9292
//
9393
// For type assignments see TransferHandlerQuestions.
94-
type Question interface{}
94+
type QuestionArguments interface {
95+
QuestionArgumentsType() string
96+
}
9597

96-
// ComponentVersionQuestion describes the question arguments
98+
// ComponentVersionQuestionArguments describes the question arguments
9799
// given for a component version related question.
98-
type ComponentVersionQuestion struct {
100+
type ComponentVersionQuestionArguments struct {
99101
Source SourceComponentVersion `json:"source"`
100102
Target TargetRepositorySpec `json:"target"`
101103
Options TransferOptions `json:"options"`
102104
}
103105

104-
// ComponentReferenceQuestion describes the question arguments
106+
var _ QuestionArguments = (*ComponentVersionQuestionArguments)(nil)
107+
108+
func (a *ComponentVersionQuestionArguments) QuestionArgumentsType() string {
109+
return "ComponentVersionQuestionArguments"
110+
}
111+
112+
// ComponentReferenceQuestionArguments describes the question arguments
105113
// given for a component version reference related question.
106-
type ComponentReferenceQuestion struct {
114+
type ComponentReferenceQuestionArguments struct {
107115
Source SourceComponentVersion `json:"source"`
108116
Target TargetRepositorySpec `json:"target"`
109117

@@ -113,16 +121,28 @@ type ComponentReferenceQuestion struct {
113121
Options TransferOptions `json:"options"`
114122
}
115123

124+
var _ QuestionArguments = (*ComponentReferenceQuestionArguments)(nil)
125+
126+
func (a *ComponentReferenceQuestionArguments) QuestionArgumentsType() string {
127+
return "ComponentReferenceQuestionArguments"
128+
}
129+
116130
type Artifact struct {
117131
Meta v2.ElementMeta `json:"metadata"`
118132
Access ocm.GenericAccessSpec `json:"access"`
119133
AccessInfo UniformAccessSpecInfo `json:"accessInfo"`
120134
}
121135

122-
// ArtifactQuestion describes the question arguments
136+
// ArtifactQuestionArguments describes the question arguments
123137
// given for an artifact related question.
124-
type ArtifactQuestion struct {
138+
type ArtifactQuestionArguments struct {
125139
Source SourceComponentVersion `json:"source"`
126140
Artifact Artifact `json:"artifact"`
127141
Options TransferOptions `json:"options"`
128142
}
143+
144+
var _ QuestionArguments = (*ArtifactQuestionArguments)(nil)
145+
146+
func (a *ArtifactQuestionArguments) QuestionArgumentsType() string {
147+
return "ArtifactQuestionArguments"
148+
}

api/ocm/plugin/ppi/cmds/transferhandler/cmd.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88

99
"github.com/spf13/cobra"
1010
"github.com/spf13/pflag"
11-
1211
"ocm.software/ocm/api/ocm/plugin/ppi"
1312
)
1413

@@ -94,7 +93,7 @@ func Command(p ppi.Plugin, cmd *cobra.Command, opts *Options) error {
9493
return err
9594
}
9695

97-
args := reflect.New(t).Interface()
96+
args := reflect.New(t).Interface().(ppi.QuestionArguments)
9897
err = json.Unmarshal(data, args)
9998
if err != nil {
10099
return err

api/ocm/plugin/ppi/cmds/valueset/compose/cmd.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ This command is only used, if for a value set descriptor configuration
3232
no direct composition rules are configured (<CMD>` + p.Name() + ` descriptor</CMD>).
3333
3434
The purpose describes the purpose the values set is used for:
35-
- <code>routingslip</code>a value used for a routing slip entry.
35+
- <code>routingslip</code> a value used for a routing slip entry.
3636
3737
If possible, predefined standard options should be used. In such a case only the
3838
<code>name</code> field should be defined for an option. If required, new options can be

api/ocm/plugin/ppi/interface.go

+12-12
Original file line numberDiff line numberDiff line change
@@ -247,22 +247,22 @@ type DecisionHandler interface {
247247
GetLabels() *[]string
248248

249249
// DecideOn implements the calculation of the answer to
250-
// the question.The given question contains the arguments for
250+
// the question. The given question contains the arguments for
251251
// the questions. There are three kinds of arguments:
252-
// ArtifactQuestion, ComponentVersionQuestion and ComponentReferenceQuestion.
252+
// ArtifactQuestionArguments, ComponentVersionQuestionArguments and ComponentReferenceQuestionArguments.
253253
// TransferHandlerQuestions maps the question name to the used
254254
// argument type.
255-
DecideOn(p Plugin, question Question) (bool, error)
255+
DecideOn(p Plugin, question QuestionArguments) (bool, error)
256256
}
257257

258258
type (
259-
TransferOptions = internal.TransferOptions
260-
Artifact = internal.Artifact
261-
AccessInfo = internal.UniformAccessSpecInfo
262-
Question = internal.Question
263-
ComponentVersionQuestion = internal.ComponentVersionQuestion
264-
ComponentReferenceQuestion = internal.ComponentReferenceQuestion
265-
ArtifactQuestion = internal.ArtifactQuestion
266-
Resolution = internal.Resolution
267-
DecisionRequestResult = internal.DecisionRequestResult
259+
TransferOptions = internal.TransferOptions
260+
Artifact = internal.Artifact
261+
AccessInfo = internal.UniformAccessSpecInfo
262+
QuestionArguments = internal.QuestionArguments
263+
ComponentVersionQuestionArguments = internal.ComponentVersionQuestionArguments
264+
ComponentReferenceQuestionArguments = internal.ComponentReferenceQuestionArguments
265+
ArtifactQuestionArguments = internal.ArtifactQuestionArguments
266+
Resolution = internal.Resolution
267+
DecisionRequestResult = internal.DecisionRequestResult
268268
)

api/ocm/plugin/ppi/utils.go

+14-12
Original file line numberDiff line numberDiff line change
@@ -186,39 +186,41 @@ func NewDecisionHandlerBase(q, desc string, labels ...string) DecisionHandlerBas
186186

187187
////////////////////////////////////////////////////////////////////////////////
188188

189-
func ComponentVersionQuestionFunv(f func(p Plugin, question *ComponentVersionQuestion) (bool, error)) func(p Plugin, question Question) (bool, error) {
190-
return func(p Plugin, question Question) (bool, error) {
191-
return f(p, question.(*ComponentVersionQuestion))
189+
type QuestionResultFunc func(p Plugin, question QuestionArguments) (bool, error)
190+
191+
func ComponentVersionQuestionFunc(f func(p Plugin, question *ComponentVersionQuestionArguments) (bool, error)) QuestionResultFunc {
192+
return func(p Plugin, question QuestionArguments) (bool, error) {
193+
return f(p, question.(*ComponentVersionQuestionArguments))
192194
}
193195
}
194196

195-
func ComponentReferenceQuestionFunc(f func(p Plugin, question *ComponentReferenceQuestion) (bool, error)) func(p Plugin, question Question) (bool, error) {
196-
return func(p Plugin, question Question) (bool, error) {
197-
return f(p, question.(*ComponentReferenceQuestion))
197+
func ComponentReferenceQuestionFunc(f func(p Plugin, question *ComponentReferenceQuestionArguments) (bool, error)) QuestionResultFunc {
198+
return func(p Plugin, question QuestionArguments) (bool, error) {
199+
return f(p, question.(*ComponentReferenceQuestionArguments))
198200
}
199201
}
200202

201-
func ArtifactQuestionFunc(f func(p Plugin, question *ArtifactQuestion) (bool, error)) func(p Plugin, question Question) (bool, error) {
202-
return func(p Plugin, question Question) (bool, error) {
203-
return f(p, question.(*ArtifactQuestion))
203+
func ArtifactQuestionFunc(f func(p Plugin, question *ArtifactQuestionArguments) (bool, error)) QuestionResultFunc {
204+
return func(p Plugin, question QuestionArguments) (bool, error) {
205+
return f(p, question.(*ArtifactQuestionArguments))
204206
}
205207
}
206208

207209
type defaultDecisionHandler struct {
208210
DecisionHandlerBase
209-
handler func(p Plugin, question Question) (bool, error)
211+
handler func(p Plugin, question QuestionArguments) (bool, error)
210212
}
211213

212214
// NewDecisionHandler provides a default decision handler based on its standard
213215
// fields and a handler function.
214-
func NewDecisionHandler(q, desc string, h func(p Plugin, question Question) (bool, error), labels ...string) DecisionHandler {
216+
func NewDecisionHandler(q, desc string, h func(p Plugin, question QuestionArguments) (bool, error), labels ...string) DecisionHandler {
215217
return &defaultDecisionHandler{
216218
DecisionHandlerBase: NewDecisionHandlerBase(q, desc, labels...),
217219
handler: h,
218220
}
219221
}
220222

221-
func (d *defaultDecisionHandler) DecideOn(p Plugin, question Question) (bool, error) {
223+
func (d *defaultDecisionHandler) DecideOn(p Plugin, question QuestionArguments) (bool, error) {
222224
return d.handler(p, question)
223225
}
224226

api/ocm/tools/transfer/transfer.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ func copyVersion(printer common.Printer, log logging.Logger, hist common.History
255255
hint := ocmcpi.ArtifactNameHint(a, src)
256256
old, err = cur.GetResourceByIdentity(r.Meta().GetIdentity(srccd.Resources))
257257

258-
changed := err != nil || old.Digest == nil || r.Meta().Digest == nil || !old.Digest.Equal(r.Meta().Digest)
258+
changed := err != nil || old.Digest == nil || !old.Digest.Equal(r.Meta().Digest)
259259
valueNeeded := err == nil && needsTransport(src.GetContext(), r, &old)
260260
if changed || valueNeeded {
261261
var msgs []interface{}

api/ocm/tools/transfer/transferhandler/options.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@ import (
77
//////////////////////////////////////////////////////////////////////////////
88

99
// ConfigOption describes generic non-standard options.
10-
// Specialized option set implementation map such generic
11-
//
12-
// config to their specialized settings. The format depends
13-
//
10+
// Specialized option set implementation maps such generic
11+
// config to their specialized settings. The format depends
1412
// on the option target. For example, for spiff it is a spiff
1513
// script.
1614
type ConfigOption interface {

api/ocm/tools/transfer/transferhandler/plugin/handler.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ func (h *Handler) askComponentVersionQuestion(question string, src ocm.Component
182182
return false, err
183183
}
184184

185-
args := plugin.ComponentVersionQuestion{
185+
args := plugin.ComponentVersionQuestionArguments{
186186
Source: *s,
187187
Target: *t,
188188
Options: *o,
@@ -214,7 +214,7 @@ func (h *Handler) askArtifactQuestion(question string, src ocm.ComponentVersionA
214214
return false, err
215215
}
216216

217-
args := plugin.ArtifactQuestion{
217+
args := plugin.ArtifactQuestionArguments{
218218
Source: *s,
219219
Artifact: *a,
220220
Options: *o,
@@ -289,7 +289,7 @@ func (h *Handler) TransferVersion(repo ocm.Repository, src ocm.ComponentVersionA
289289
return nil, nil, err
290290
}
291291

292-
args := plugin.ComponentReferenceQuestion{
292+
args := plugin.ComponentReferenceQuestionArguments{
293293
Source: *s,
294294
Target: *t,
295295
ElementMeta: v2.ElementMeta{

api/ocm/tools/transfer/transferhandler/plugin/options.go

-4
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ var (
3232

3333
type TransferOptionsCreator = transferhandler.SpecializedOptionsCreator[*Options, Options]
3434

35-
func (o *Options) NewOptions() transferhandler.TransferHandlerOptions {
36-
return &Options{}
37-
}
38-
3935
func (o *Options) NewTransferHandler() (transferhandler.TransferHandler, error) {
4036
return New(o)
4137
}

api/ocm/tools/transfer/transferhandler/spiff/options.go

-4
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ var (
2929

3030
type TransferOptionsCreator = transferhandler.SpecializedOptionsCreator[*Options, Options]
3131

32-
func (o *Options) NewOptions() transferhandler.TransferHandlerOptions {
33-
return &Options{}
34-
}
35-
3632
func (o *Options) NewTransferHandler() (transferhandler.TransferHandler, error) {
3733
return New(o)
3834
}

api/ocm/tools/transfer/transferhandler/standard/options.go

-4
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,6 @@ var (
5252

5353
type TransferOptionsCreator = transferhandler.SpecializedOptionsCreator[*Options, Options]
5454

55-
func (o *Options) NewOptions() transferhandler.TransferHandlerOptions {
56-
return &Options{}
57-
}
58-
5955
func (o *Options) NewTransferHandler() (transferhandler.TransferHandler, error) {
6056
return New(o)
6157
}

api/ocm/tools/transfer/transferhandler/standard/transfer_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ var _ = Describe("value transport with relative ocireg", func() {
142142

143143
} else {
144144
Expect(info.Host).To(Equal(OCIHOST2 + ".alias"))
145-
Expect(info.Info).To(Equal("ocm/value:v2.0"))
145+
Expect(info.Info).To(Equal("ocm/value:v2.0@sha256:" + D_OCIMANIFEST1))
146146
}
147147

148148
CheckBlob(r, dig, size)
@@ -173,7 +173,7 @@ var _ = Describe("value transport with relative ocireg", func() {
173173
Expect(info.Info).To(Equal("sha256:" + H_OCIARCHMANIFEST1))
174174

175175
} else {
176-
Expect(info.Info).To(Equal("ocm/value:v2.0"))
176+
Expect(info.Info).To(Equal("ocm/value:v2.0@sha256:" + D_OCIMANIFEST1))
177177
}
178178

179179
MustBeSuccessful(ctcv.Close())

cmds/transferplugin/transferhandlers/demo.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ func NewDecision(typ string, optfunc func(opts *ppi.TransferOptions) bool, desc
3636
}
3737
}
3838

39-
func (d DecisionHandler) DecideOn(p ppi.Plugin, question ppi.Question) (bool, error) {
40-
q := question.(*ppi.ArtifactQuestion)
39+
func (d DecisionHandler) DecideOn(p ppi.Plugin, question ppi.QuestionArguments) (bool, error) {
40+
q := question.(*ppi.ArtifactQuestionArguments)
4141

4242
var cfg *config.Config
4343

cmds/transferplugin/transferhandlers/demo_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ var _ = Describe("Test Environment", func() {
3131

3232
config := Must(vfs.ReadFile(osfs.OsFs, "testdata/config"))
3333

34-
question := &ppi.ArtifactQuestion{
34+
question := &ppi.ArtifactQuestionArguments{
3535
Source: ppi.SourceComponentVersion{
3636
Name: "",
3737
Version: "",

docs/pluginreference/plugin_valueset_compose.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ This command is only used, if for a value set descriptor configuration
2424
no direct composition rules are configured ([plugin descriptor](plugin_descriptor.md)).
2525

2626
The purpose describes the purpose the values set is used for:
27-
- <code>routingslip</code>a value used for a routing slip entry.
27+
- <code>routingslip</code> a value used for a routing slip entry.
2828

2929
If possible, predefined standard options should be used. In such a case only the
3030
<code>name</code> field should be defined for an option. If required, new options can be

0 commit comments

Comments
 (0)