Skip to content

Commit 96fc535

Browse files
committed
adapt plugin interface
1 parent 9463d5b commit 96fc535

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed

api/ocm/plugin/ppi/cmds/upload/put/cmd.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/mandelsoft/goutils/errors"
1010
"github.com/spf13/cobra"
1111
"github.com/spf13/pflag"
12+
"ocm.software/ocm/api/ocm/refhints"
1213

1314
"ocm.software/ocm/api/credentials"
1415
"ocm.software/ocm/api/ocm/plugin/descriptor"
@@ -59,22 +60,25 @@ type Options struct {
5960
MediaType string
6061
ArtifactType string
6162

62-
Hint string
63+
hint string
64+
65+
Hints ppi.ReferenceHints
6366
}
6467

6568
func (o *Options) AddFlags(fs *pflag.FlagSet) {
6669
flag.YAMLVarP(fs, &o.Credentials, OptCreds, "c", nil, "credentials")
6770
flag.StringToStringVarPF(fs, &o.Credentials, "credential", "C", nil, "dedicated credential value")
6871
fs.StringVarP(&o.MediaType, OptMedia, "m", "", "media type of input blob")
6972
fs.StringVarP(&o.ArtifactType, OptArt, "a", "", "artifact type of input blob")
70-
fs.StringVarP(&o.Hint, OptHint, "H", "", "reference hint for storing blob")
73+
fs.StringVarP(&o.hint, OptHint, "H", "", "reference hint for storing blob")
7174
}
7275

7376
func (o *Options) Complete(args []string) error {
7477
o.Name = args[0]
7578
if err := runtime.DefaultYAMLEncoding.Unmarshal([]byte(args[1]), &o.Specification); err != nil {
7679
return errors.Wrapf(err, "invalid repository specification")
7780
}
81+
o.Hints = refhints.ParseHints(o.hint)
7882
return nil
7983
}
8084

@@ -88,7 +92,7 @@ func Command(p ppi.Plugin, cmd *cobra.Command, opts *Options) error {
8892
if u == nil {
8993
return errors.ErrNotFound(descriptor.KIND_UPLOADER, fmt.Sprintf("%s:%s", opts.ArtifactType, opts.MediaType))
9094
}
91-
w, h, err := u.Writer(p, opts.ArtifactType, opts.MediaType, opts.Hint, spec, opts.Credentials)
95+
w, h, err := u.Writer(p, opts.ArtifactType, opts.MediaType, opts.Hints, spec, opts.Credentials)
9296
if err != nil {
9397
return err
9498
}

api/ocm/plugin/ppi/interface.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"io"
66

77
"github.com/spf13/cobra"
8+
"ocm.software/ocm/api/ocm/refhints"
89

910
"ocm.software/ocm/api/config/cpi"
1011
"ocm.software/ocm/api/credentials"
@@ -106,14 +107,18 @@ type AccessSpecProvider func() AccessSpec
106107

107108
type UploadFormats runtime.KnownTypes[runtime.TypedObject, runtime.TypedObjectDecoder[runtime.TypedObject]]
108109

110+
type ReferenceHints = refhints.ReferenceHints
111+
112+
type ReferenceHint = refhints.ReferenceHint
113+
109114
type Uploader interface {
110115
Decoders() UploadFormats
111116

112117
Name() string
113118
Description() string
114119

115120
ValidateSpecification(p Plugin, spec UploadTargetSpec) (info *UploadTargetSpecInfo, err error)
116-
Writer(p Plugin, arttype, mediatype string, hint string, spec UploadTargetSpec, creds credentials.Credentials) (io.WriteCloser, AccessSpecProvider, error)
121+
Writer(p Plugin, arttype, mediatype string, hints ReferenceHints, spec UploadTargetSpec, creds credentials.Credentials) (io.WriteCloser, AccessSpecProvider, error)
117122
}
118123

119124
type UploadTargetSpec = runtime.TypedObject

cmds/demoplugin/accessmethods/demo.go

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

99
"github.com/mandelsoft/filepath/pkg/filepath"
1010
"github.com/mandelsoft/goutils/errors"
11+
"ocm.software/ocm/api/ocm/refhints"
1112

1213
"ocm.software/ocm/api/credentials"
1314
"ocm.software/ocm/api/credentials/cpi"
@@ -25,6 +26,8 @@ const (
2526
VERSION = "v1"
2627
)
2728

29+
const ReferenceHintType = "demo"
30+
2831
type AccessSpec struct {
2932
runtime.ObjectVersionedType `json:",inline"`
3033

@@ -86,7 +89,7 @@ func (a *AccessMethod) ValidateSpecification(p ppi.Plugin, spec ppi.AccessSpec)
8689
identity.ID_PATHPREFIX: my.Path,
8790
}
8891
info.Short = "temp file " + my.Path
89-
info.Hint = "temp file " + my.Path
92+
info.Hint = refhints.New(ReferenceHintType, my.Path).Serialize()
9093
return &info, nil
9194
}
9295

cmds/demoplugin/uploaders/demo.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func (a *Uploader) ValidateSpecification(p ppi.Plugin, spec ppi.UploadTargetSpec
7272
return &info, nil
7373
}
7474

75-
func (a *Uploader) Writer(p ppi.Plugin, arttype, mediatype, hint string, repo ppi.UploadTargetSpec, creds credentials.Credentials) (io.WriteCloser, ppi.AccessSpecProvider, error) {
75+
func (a *Uploader) Writer(p ppi.Plugin, arttype, mediatype string, hints ppi.ReferenceHints, repo ppi.UploadTargetSpec, creds credentials.Credentials) (io.WriteCloser, ppi.AccessSpecProvider, error) {
7676
var file *os.File
7777
var err error
7878

@@ -90,6 +90,12 @@ func (a *Uploader) Writer(p ppi.Plugin, arttype, mediatype, hint string, repo pp
9090
}
9191
}
9292

93+
h := hints.GetReferenceHint(accessmethods.ReferenceHintType, "")
94+
var hint string
95+
if h != nil {
96+
hint = h.GetReference()
97+
}
98+
9399
path := hint
94100
my := repo.(*TargetSpec)
95101
dir := root

0 commit comments

Comments
 (0)