diff --git a/api/ocm/extensions/accessmethods/options/deprecated.go b/api/ocm/extensions/accessmethods/options/deprecated.go new file mode 100644 index 0000000000..c175f6b3a7 --- /dev/null +++ b/api/ocm/extensions/accessmethods/options/deprecated.go @@ -0,0 +1,97 @@ +package options + +import ( + "ocm.software/ocm/api/utils/cobrautils/flagsets" +) + +const ( + // Deprecated: use package [flagsets]. + TYPE_STRING = flagsets.TYPE_STRING + // Deprecated: use package [flagsets]. + TYPE_STRINGARRAY = flagsets.TYPE_STRINGARRAY + // Deprecated: use package [flagsets]. + TYPE_STRING2STRING = flagsets.TYPE_STRING2STRING + // Deprecated: use package [flagsets]. + TYPE_INT = flagsets.TYPE_INT + // Deprecated: use package [flagsets]. + TYPE_BOOL = flagsets.TYPE_BOOL + // Deprecated: use package [flagsets]. + TYPE_YAML = flagsets.TYPE_YAML + // Deprecated: use package [flagsets]. + TYPE_STRINGMAPYAML = flagsets.TYPE_STRINGMAPYAML + // Deprecated: use package [flagsets]. + TYPE_STRING2YAML = flagsets.TYPE_STRING2YAML + // Deprecated: use package [flagsets]. + TYPE_STRING2STRINGSLICE = flagsets.TYPE_STRING2STRINGSLICE + // Deprecated: use package [flagsets]. + TYPE_STRINGCOLONSTRINGSLICE = flagsets.TYPE_STRINGCOLONSTRINGSLICE + // Deprecated: use package [flagsets]. + TYPE_BYTES = flagsets.TYPE_BYTES + // Deprecated: use package [flagsets]. + TYPE_IDENTITYPATH = flagsets.TYPE_IDENTITYPATH +) + +// Deprecated: use packagge [flagsets]. +type OptionType = flagsets.ConfigOptionType + +//////////////////////////////////////////////////////////////////////////////// + +// Deprecated: use packagge [flagsets]. +func NewStringOptionType(name, desc string) OptionType { + return flagsets.NewStringOptionType(name, desc) +} + +// Deprecated: use packagge [flagsets]. +func NewStringArrayOptionType(name, desc string) OptionType { + return flagsets.NewStringArrayOptionType(name, desc) +} + +// Deprecated: use packagge [flagsets]. +func NewIntOptionType(name, desc string) OptionType { + return flagsets.NewIntOptionType(name, desc) +} + +// Deprecated: use packagge [flagsets]. +func NewBoolOptionType(name, desc string) OptionType { + return flagsets.NewBoolOptionType(name, desc) +} + +// Deprecated: use packagge [flagsets]. +func NewYAMLOptionType(name, desc string) OptionType { + return flagsets.NewYAMLOptionType(name, desc) +} + +// Deprecated: use packagge [flagsets]. +func NewValueMapYAMLOptionType(name, desc string) OptionType { + return flagsets.NewValueMapYAMLOptionType(name, desc) +} + +// Deprecated: use packagge [flagsets]. +func NewValueMapOptionType(name, desc string) OptionType { + return flagsets.NewValueMapOptionType(name, desc) +} + +// Deprecated: use packagge [flagsets]. +func NewStringMapOptionType(name, desc string) OptionType { + return flagsets.NewStringMapOptionType(name, desc) +} + +// Deprecated: use packagge [flagsets]. +func NewStringSliceMapOptionType(name, desc string) OptionType { + return flagsets.NewStringSliceMapOptionType(name, desc) +} + +// Deprecated: use packagge [flagsets]. +func NewStringSliceMapColonOptionType(name, desc string) OptionType { + return flagsets.NewStringSliceMapColonOptionType(name, desc) +} + +// Deprecated: use packagge [flagsets]. +func NewBytesOptionType(name, desc string) OptionType { + return flagsets.NewBytesOptionType(name, desc) +} + +// Deprecated: use packagge [flagsets]. +func NewIdentityPathOptionType(name, desc string) OptionType { + return flagsets.NewIdentityPathOptionType(name, desc) +} diff --git a/api/ocm/extensions/accessmethods/options/init.go b/api/ocm/extensions/accessmethods/options/init.go index 7e815b8f30..f0ff625e01 100644 --- a/api/ocm/extensions/accessmethods/options/init.go +++ b/api/ocm/extensions/accessmethods/options/init.go @@ -1,34 +1,10 @@ package options -const ( - TYPE_STRING = "string" - TYPE_STRINGARRAY = "[]string" - TYPE_STRING2STRING = "string=string" - TYPE_INT = "int" - TYPE_BOOL = "bool" - TYPE_YAML = "YAML" - TYPE_STRINGMAPYAML = "map[string]YAML" - TYPE_STRING2YAML = "string=YAML" - TYPE_STRING2STRINGSLICE = "string=string,string" - TYPE_STRINGCOLONSTRINGSLICE = "string:string,string" - TYPE_BYTES = "[]byte" - TYPE_IDENTITYPATH = "[]identity" +import ( + "ocm.software/ocm/api/utils/cobrautils/flagsets" ) -func init() { - DefaultRegistry.RegisterValueType(TYPE_STRING, NewStringOptionType, "string value") - DefaultRegistry.RegisterValueType(TYPE_STRINGARRAY, NewStringArrayOptionType, "list of string values") - DefaultRegistry.RegisterValueType(TYPE_STRING2STRING, NewStringMapOptionType, "string map defined by dedicated assignments") - DefaultRegistry.RegisterValueType(TYPE_INT, NewIntOptionType, "integer value") - DefaultRegistry.RegisterValueType(TYPE_BOOL, NewBoolOptionType, "boolean flag") - DefaultRegistry.RegisterValueType(TYPE_YAML, NewYAMLOptionType, "JSON or YAML document string") - DefaultRegistry.RegisterValueType(TYPE_STRINGMAPYAML, NewValueMapYAMLOptionType, "JSON or YAML map") - DefaultRegistry.RegisterValueType(TYPE_STRING2YAML, NewValueMapOptionType, "string map with arbitrary values defined by dedicated assignments") - DefaultRegistry.RegisterValueType(TYPE_STRING2STRINGSLICE, NewStringSliceMapOptionType, "string map defined by dedicated assignment of comma separated strings") - DefaultRegistry.RegisterValueType(TYPE_STRINGCOLONSTRINGSLICE, NewStringSliceMapColonOptionType, "string map defined by dedicated assignment of comma separated strings") - DefaultRegistry.RegisterValueType(TYPE_BYTES, NewBytesOptionType, "byte value") - DefaultRegistry.RegisterValueType(TYPE_IDENTITYPATH, NewIdentityPathOptionType, "identity path") -} +var DefaultRegistry = flagsets.SetBaseTypes(flagsets.NewConfigOptionTypeRegistry()) func RegisterOption(o OptionType) OptionType { DefaultRegistry.RegisterOptionType(o) diff --git a/api/ocm/extensions/accessmethods/options/registry_test.go b/api/ocm/extensions/accessmethods/options/registry_test.go deleted file mode 100644 index 675823db0f..0000000000 --- a/api/ocm/extensions/accessmethods/options/registry_test.go +++ /dev/null @@ -1,50 +0,0 @@ -package options - -import ( - . "github.com/mandelsoft/goutils/testutils" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" -) - -var _ = Describe("registry", func() { - var reg Registry - - BeforeEach(func() { - reg = New() - }) - - It("sets and retrieves type", func() { - reg.RegisterValueType("string", NewStringOptionType, "string") - - t := reg.GetValueType("string") - Expect(t).NotTo(BeNil()) - - o := Must(reg.CreateOptionType("string", "test", "some test")) - Expect(o.GetName()).To(Equal("test")) - Expect(o.GetDescription()).To(Equal("[*string*] some test")) - }) - - It("sets and retrieves option", func() { - reg.RegisterOptionType(HostnameOption) - - t := reg.GetOptionType(HostnameOption.GetName()) - Expect(t).NotTo(BeNil()) - }) - - It("creates merges a new type", func() { - reg.RegisterValueType("string", NewStringOptionType, "string") - reg.RegisterOptionType(HostnameOption) - - o := Must(reg.CreateOptionType("string", HostnameOption.GetName(), "some test")) - Expect(o).To(BeIdenticalTo(HostnameOption)) - }) - - It("fails creating existing", func() { - reg.RegisterValueType("string", NewStringOptionType, "string") - reg.RegisterValueType("int", NewIntOptionType, "int") - reg.RegisterOptionType(HostnameOption) - - _, err := reg.CreateOptionType("int", HostnameOption.GetName(), "some test") - MustFailWithMessage(err, "option \"accessHostname\" already exists") - }) -}) diff --git a/api/ocm/extensions/accessmethods/options/standard.go b/api/ocm/extensions/accessmethods/options/standard.go index a2b6ccb99b..0ebefbbd7d 100644 --- a/api/ocm/extensions/accessmethods/options/standard.go +++ b/api/ocm/extensions/accessmethods/options/standard.go @@ -1,84 +1,88 @@ package options +import ( + "ocm.software/ocm/api/utils/cobrautils/flagsets" +) + // HintOption . -var HintOption = RegisterOption(NewStringOptionType("hint", "(repository) hint for local artifacts")) +var HintOption = RegisterOption(flagsets.NewStringOptionType("hint", "(repository) hint for local artifacts")) // MediatypeOption . -var MediatypeOption = RegisterOption(NewStringOptionType("mediaType", "media type for artifact blob representation")) +var MediatypeOption = RegisterOption(flagsets.NewStringOptionType("mediaType", "media type for artifact blob representation")) // SizeOption . -var SizeOption = RegisterOption(NewIntOptionType("size", "blob size")) +var SizeOption = RegisterOption(flagsets.NewIntOptionType("size", "blob size")) // DigestOption . -var DigestOption = RegisterOption(NewStringOptionType("digest", "blob digest")) +var DigestOption = RegisterOption(flagsets.NewStringOptionType("digest", "blob digest")) // ReferenceOption . -var ReferenceOption = RegisterOption(NewStringOptionType("reference", "reference name")) +var ReferenceOption = RegisterOption(flagsets.NewStringOptionType("reference", "reference name")) // PackageOption . -var PackageOption = RegisterOption(NewStringOptionType("package", "package or object name")) +var PackageOption = RegisterOption(flagsets.NewStringOptionType("package", "package or object name")) // ArtifactOption . -var ArtifactOption = RegisterOption(NewStringOptionType("artifactId", "maven artifact id")) +var ArtifactOption = RegisterOption(flagsets.NewStringOptionType("artifactId", "maven artifact id")) // GroupOption . -var GroupOption = RegisterOption(NewStringOptionType("groupId", "maven group id")) +var GroupOption = RegisterOption(flagsets.NewStringOptionType("groupId", "maven group id")) // RepositoryOption . -var RepositoryOption = RegisterOption(NewStringOptionType("accessRepository", "repository or registry URL")) +var RepositoryOption = RegisterOption(flagsets.NewStringOptionType("accessRepository", "repository or registry URL")) // HostnameOption . -var HostnameOption = RegisterOption(NewStringOptionType("accessHostname", "hostname used for access")) +var HostnameOption = RegisterOption(flagsets.NewStringOptionType("accessHostname", "hostname used for access")) // CommitOption . -var CommitOption = RegisterOption(NewStringOptionType("commit", "git commit id")) +var CommitOption = RegisterOption(flagsets.NewStringOptionType("commit", "git commit id")) // GlobalAccessOption . -var GlobalAccessOption = RegisterOption(NewValueMapYAMLOptionType("globalAccess", "access specification for global access")) +var GlobalAccessOption = RegisterOption(flagsets.NewValueMapYAMLOptionType("globalAccess", "access specification for global access")) // RegionOption . -var RegionOption = RegisterOption(NewStringOptionType("region", "region name")) +var RegionOption = RegisterOption(flagsets.NewStringOptionType("region", "region name")) // BucketOption . -var BucketOption = RegisterOption(NewStringOptionType("bucket", "bucket name")) +var BucketOption = RegisterOption(flagsets.NewStringOptionType("bucket", "bucket name")) // VersionOption . -var VersionOption = RegisterOption(NewStringOptionType("accessVersion", "version for access specification")) +var VersionOption = RegisterOption(flagsets.NewStringOptionType("accessVersion", "version for access specification")) // ComponentOption. -var ComponentOption = RegisterOption(NewStringOptionType("accessComponent", "component for access specification")) +var ComponentOption = RegisterOption(flagsets.NewStringOptionType("accessComponent", "component for access specification")) // IdentityPathOption. -var IdentityPathOption = RegisterOption(NewIdentityPathOptionType("identityPath", "identity path for specification")) +var IdentityPathOption = RegisterOption(flagsets.NewIdentityPathOptionType("identityPath", "identity path for specification")) // URLOption. -var URLOption = RegisterOption(NewStringOptionType("url", "artifact or server url")) +var URLOption = RegisterOption(flagsets.NewStringOptionType("url", "artifact or server url")) -var HTTPHeaderOption = RegisterOption(NewStringSliceMapColonOptionType("header", "http headers")) +var HTTPHeaderOption = RegisterOption(flagsets.NewStringSliceMapColonOptionType("header", "http headers")) -var HTTPVerbOption = RegisterOption(NewStringOptionType("verb", "http request method")) +var HTTPVerbOption = RegisterOption(flagsets.NewStringOptionType("verb", "http request method")) -var HTTPBodyOption = RegisterOption(NewStringOptionType("body", "body of a http request")) +var HTTPBodyOption = RegisterOption(flagsets.NewStringOptionType("body", "body of a http request")) -var HTTPRedirectOption = RegisterOption(NewBoolOptionType("noredirect", "http redirect behavior")) +var HTTPRedirectOption = RegisterOption(flagsets.NewBoolOptionType("noredirect", "http redirect behavior")) // CommentOption . -var CommentOption = RegisterOption(NewStringOptionType("comment", "comment field value")) +var CommentOption = RegisterOption(flagsets.NewStringOptionType("comment", "comment field value")) // ClassifierOption the optional classifier of a maven resource. -var ClassifierOption = RegisterOption(NewStringOptionType("classifier", "maven classifier")) +var ClassifierOption = RegisterOption(flagsets.NewStringOptionType("classifier", "maven classifier")) // ExtensionOption the optional extension of a maven resource. -var ExtensionOption = RegisterOption(NewStringOptionType("extension", "maven extension name")) +var ExtensionOption = RegisterOption(flagsets.NewStringOptionType("extension", "maven extension name")) // NPMRegistryOption sets the registry of the npm resource. -var NPMRegistryOption = RegisterOption(NewStringOptionType("registry", "npm package registry")) +var NPMRegistryOption = RegisterOption(flagsets.NewStringOptionType("registry", "npm package registry")) // NPMPackageOption sets what package should be fetched from the npm registry. -var NPMPackageOption = RegisterOption(NewStringOptionType("package", "npm package name")) +var NPMPackageOption = PackageOption // NPMVersionOption sets the version of the npm package. -var NPMVersionOption = RegisterOption(NewStringOptionType("version", "npm package version")) +var NPMVersionOption = RegisterOption(flagsets.NewStringOptionType("version", "npm package version")) // IdPathOption is a path of identity specs. -var IdPathOption = RegisterOption(NewStringArrayOptionType("idpath", "identity path (attr=value{,attr=value}")) +var IdPathOption = RegisterOption(flagsets.NewStringArrayOptionType("idpath", "identity path (attr=value{,attr=value}")) diff --git a/api/ocm/extensions/accessmethods/options/types.go b/api/ocm/extensions/accessmethods/options/types.go deleted file mode 100644 index f02ecd03f7..0000000000 --- a/api/ocm/extensions/accessmethods/options/types.go +++ /dev/null @@ -1,125 +0,0 @@ -package options - -import ( - "fmt" - - "ocm.software/ocm/api/utils/cobrautils/flagsets" -) - -type OptionType interface { - flagsets.ConfigOptionType - ValueType() string - GetDescriptionText() string -} - -type base = flagsets.ConfigOptionType - -type option struct { - base - valueType string -} - -func (o *option) Equal(t flagsets.ConfigOptionType) bool { - if ot, ok := t.(*option); ok { - return o.valueType == ot.valueType && o.GetName() == ot.GetName() - } - return false -} - -func (o *option) ValueType() string { - return o.valueType -} - -func (o *option) GetDescription() string { - return fmt.Sprintf("[*%s*] %s", o.ValueType(), o.base.GetDescription()) -} - -func (o *option) GetDescriptionText() string { - return o.base.GetDescription() -} - -//////////////////////////////////////////////////////////////////////////////// - -func NewStringOptionType(name, desc string) OptionType { - return &option{ - base: flagsets.NewStringOptionType(name, desc), - valueType: TYPE_STRING, - } -} - -func NewStringArrayOptionType(name, desc string) OptionType { - return &option{ - base: flagsets.NewStringArrayOptionType(name, desc), - valueType: TYPE_STRINGARRAY, - } -} - -func NewIntOptionType(name, desc string) OptionType { - return &option{ - base: flagsets.NewIntOptionType(name, desc), - valueType: TYPE_INT, - } -} - -func NewBoolOptionType(name, desc string) OptionType { - return &option{ - base: flagsets.NewBoolOptionType(name, desc), - valueType: TYPE_BOOL, - } -} - -func NewYAMLOptionType(name, desc string) OptionType { - return &option{ - base: flagsets.NewYAMLOptionType(name, desc), - valueType: TYPE_YAML, - } -} - -func NewValueMapYAMLOptionType(name, desc string) OptionType { - return &option{ - base: flagsets.NewValueMapYAMLOptionType(name, desc), - valueType: TYPE_STRINGMAPYAML, - } -} - -func NewValueMapOptionType(name, desc string) OptionType { - return &option{ - base: flagsets.NewValueMapOptionType(name, desc), - valueType: TYPE_STRING2YAML, - } -} - -func NewStringMapOptionType(name, desc string) OptionType { - return &option{ - base: flagsets.NewStringMapOptionType(name, desc), - valueType: TYPE_STRING2STRING, - } -} - -func NewStringSliceMapOptionType(name, desc string) OptionType { - return &option{ - base: flagsets.NewStringSliceMapOptionType(name, desc), - valueType: TYPE_STRING2STRINGSLICE, - } -} - -func NewStringSliceMapColonOptionType(name, desc string) OptionType { - return &option{ - base: flagsets.NewStringSliceMapColonOptionType(name, desc), - valueType: TYPE_STRINGCOLONSTRINGSLICE, - } -} - -func NewBytesOptionType(name, desc string) OptionType { - return &option{ - base: flagsets.NewBytesOptionType(name, desc), - valueType: TYPE_BYTES, - } -} - -func NewIdentityPathOptionType(name, desc string) OptionType { - return &option{ - base: flagsets.NewIdentityPathOptionType(name, desc), - valueType: TYPE_IDENTITYPATH, - } -} diff --git a/api/ocm/plugin/common/describe.go b/api/ocm/plugin/common/describe.go index a5553e3235..09586658f8 100644 --- a/api/ocm/plugin/common/describe.go +++ b/api/ocm/plugin/common/describe.go @@ -14,6 +14,7 @@ import ( "ocm.software/ocm/api/ocm/extensions/accessmethods/options" "ocm.software/ocm/api/ocm/plugin/descriptor" "ocm.software/ocm/api/utils" + "ocm.software/ocm/api/utils/cobrautils/flagsets" common "ocm.software/ocm/api/utils/misc" "ocm.software/ocm/api/utils/semverutils" ) @@ -103,7 +104,7 @@ type MethodInfo struct { type MethodVersion struct { Name string Format string - Options map[string]options.OptionType + Options map[string]flagsets.ConfigOptionType } func GetAccessMethodInfo(methods []descriptor.AccessMethodDescriptor) map[string]*MethodInfo { @@ -129,7 +130,7 @@ func GetAccessMethodInfo(methods []descriptor.AccessMethodDescriptor) map[string if v == nil { v = &MethodVersion{ Name: vers, - Options: map[string]options.OptionType{}, + Options: map[string]flagsets.ConfigOptionType{}, } i.Versions[vers] = v } @@ -328,7 +329,7 @@ type ValueSetInfo struct { type ValueSetVersion struct { Name string Format string - Options map[string]options.OptionType + Options map[string]flagsets.ConfigOptionType } func GetValueSetInfo(valuesets []descriptor.ValueSetDescriptor) map[string]*ValueSetInfo { @@ -357,7 +358,7 @@ func GetValueSetInfo(valuesets []descriptor.ValueSetDescriptor) map[string]*Valu if v == nil { v = &ValueSetVersion{ Name: vers, - Options: map[string]options.OptionType{}, + Options: map[string]flagsets.ConfigOptionType{}, } i.Versions[vers] = v } diff --git a/api/ocm/plugin/plugin_input.go b/api/ocm/plugin/plugin_input.go index 6566ca1eb5..4b04df5a27 100644 --- a/api/ocm/plugin/plugin_input.go +++ b/api/ocm/plugin/plugin_input.go @@ -60,8 +60,8 @@ func (p *pluginImpl) ComposeInputSpec(name string, opts flagsets.ConfigOptions, return nil } -func (p *pluginImpl) GetInputBlob(w io.Writer, creds, spec json.RawMessage) error { - args := []string{input.Name, get.Name, string(spec)} +func (p *pluginImpl) GetInputBlob(w io.Writer, dir string, creds, spec json.RawMessage) error { + args := []string{input.Name, get.Name, dir, string(spec)} if creds != nil { args = append(args, "--"+get.OptCreds, string(creds)) } diff --git a/api/ocm/plugin/ppi/cmds/input/compose/cmd.go b/api/ocm/plugin/ppi/cmds/input/compose/cmd.go index d96040c1f8..5add87613f 100644 --- a/api/ocm/plugin/ppi/cmds/input/compose/cmd.go +++ b/api/ocm/plugin/ppi/cmds/input/compose/cmd.go @@ -7,10 +7,10 @@ import ( "github.com/spf13/cobra" "github.com/spf13/pflag" - "ocm.software/ocm/api/ocm/extensions/accessmethods/options" "ocm.software/ocm/api/ocm/plugin/descriptor" "ocm.software/ocm/api/ocm/plugin/ppi" "ocm.software/ocm/api/utils/runtime" + "ocm.software/ocm/cmds/ocm/commands/ocmcmds/common/inputs/options" ) const Name = "compose" diff --git a/api/ocm/plugin/ppi/cmds/input/get/cmd.go b/api/ocm/plugin/ppi/cmds/input/get/cmd.go index 0c15759041..d310a32786 100644 --- a/api/ocm/plugin/ppi/cmds/input/get/cmd.go +++ b/api/ocm/plugin/ppi/cmds/input/get/cmd.go @@ -27,12 +27,12 @@ func New(p ppi.Plugin) *cobra.Command { opts := Options{} cmd := &cobra.Command{ - Use: Name + " [] ", + Use: Name + " [] [] ", Short: "get blob", Long: ` Evaluate the given input specification and return the described blob on *stdout*.`, - Args: cobra.ExactArgs(1), + Args: cobra.RangeArgs(1, 2), PersistentPreRunE: func(cmd *cobra.Command, args []string) error { return opts.Complete(args) }, @@ -47,6 +47,7 @@ Evaluate the given input specification and return the described blob on type Options struct { Credentials credentials.DirectCredentials Specification json.RawMessage + Dir string } func (o *Options) AddFlags(fs *pflag.FlagSet) { @@ -55,7 +56,14 @@ func (o *Options) AddFlags(fs *pflag.FlagSet) { } func (o *Options) Complete(args []string) error { - if err := runtime.DefaultYAMLEncoding.Unmarshal([]byte(args[0]), &o.Specification); err != nil { + creds := 0 + if len(args) > 1 { + o.Dir = args[creds] + creds++ + } else { + o.Dir = "." + } + if err := runtime.DefaultYAMLEncoding.Unmarshal([]byte(args[creds]), &o.Specification); err != nil { return errors.Wrapf(err, "invalid repository specification") } @@ -73,11 +81,11 @@ func Command(p ppi.Plugin, cmd *cobra.Command, opts *Options) error { if m == nil { return errors.ErrUnknown(descriptor.KIND_INPUTTYPE, spec.GetType()) } - _, err = m.ValidateSpecification(p, spec) + _, err = m.ValidateSpecification(p, opts.Dir, spec) if err != nil { return err } - r, err := m.Reader(p, spec, opts.Credentials) + r, err := m.Reader(p, opts.Dir, spec, opts.Credentials) if err != nil { return err } diff --git a/api/ocm/plugin/ppi/cmds/input/validate/cmd.go b/api/ocm/plugin/ppi/cmds/input/validate/cmd.go index 827b9ff5ef..60a08c787d 100644 --- a/api/ocm/plugin/ppi/cmds/input/validate/cmd.go +++ b/api/ocm/plugin/ppi/cmds/input/validate/cmd.go @@ -48,7 +48,7 @@ following fields: The consumer id used to determine optional credentials for the underlying repository. If specified, at least the type field must be set. `, - Args: cobra.ExactArgs(1), + Args: cobra.RangeArgs(1, 2), PersistentPreRunE: func(cmd *cobra.Command, args []string) error { return opts.Complete(args) }, @@ -62,13 +62,21 @@ following fields: type Options struct { Specification json.RawMessage + Dir string } func (o *Options) AddFlags(fs *pflag.FlagSet) { } func (o *Options) Complete(args []string) error { - if err := runtime.DefaultYAMLEncoding.Unmarshal([]byte(args[0]), &o.Specification); err != nil { + creds := 0 + if len(args) > 1 { + o.Dir = args[creds] + creds++ + } else { + o.Dir = "." + } + if err := runtime.DefaultYAMLEncoding.Unmarshal([]byte(args[creds]), &o.Specification); err != nil { return errors.Wrapf(err, "invalid access specification") } return nil @@ -91,7 +99,7 @@ func Command(p ppi.Plugin, cmd *cobra.Command, opts *Options) error { if m == nil { return errors.ErrUnknown(descriptor.KIND_INPUTTYPE, spec.GetType()) } - info, err := m.ValidateSpecification(p, spec) + info, err := m.ValidateSpecification(p, opts.Dir, spec) if err != nil { return err } diff --git a/api/ocm/plugin/ppi/interface.go b/api/ocm/plugin/ppi/interface.go index 8a6c4ac6fe..eba7fe0906 100644 --- a/api/ocm/plugin/ppi/interface.go +++ b/api/ocm/plugin/ppi/interface.go @@ -9,10 +9,10 @@ import ( "ocm.software/ocm/api/config/cpi" "ocm.software/ocm/api/credentials" "ocm.software/ocm/api/datacontext/action" - "ocm.software/ocm/api/ocm/extensions/accessmethods/options" "ocm.software/ocm/api/ocm/plugin/descriptor" "ocm.software/ocm/api/ocm/plugin/internal" "ocm.software/ocm/api/tech/signing" + "ocm.software/ocm/api/utils/cobrautils/flagsets" "ocm.software/ocm/api/utils/runtime" ) @@ -113,15 +113,15 @@ type InputType interface { // Options provides the list of CLI options supported to compose the access // specification. - Options() []options.OptionType + Options() []flagsets.ConfigOptionType // Description provides a general description for the access mehod kind. Description() string // Format describes the attributes of the dedicated version. Format() string - ValidateSpecification(p Plugin, spec InputSpec) (info *InputSpecInfo, err error) - Reader(p Plugin, spec InputSpec, creds credentials.Credentials) (io.ReadCloser, error) + ValidateSpecification(p Plugin, dir string, spec InputSpec) (info *InputSpecInfo, err error) + Reader(p Plugin, dir string, spec InputSpec, creds credentials.Credentials) (io.ReadCloser, error) ComposeSpecification(p Plugin, opts Config, config Config) error } @@ -137,7 +137,7 @@ type AccessMethod interface { // Options provides the list of CLI options supported to compose the access // specification. - Options() []options.OptionType + Options() []flagsets.ConfigOptionType // Description provides a general description for the access mehod kind. Description() string @@ -230,7 +230,7 @@ type ValueSet interface { // Options provides the list of CLI options supported to compose the access // specification. - Options() []options.OptionType + Options() []flagsets.ConfigOptionType // Description provides a general description for the access mehod kind. Description() string diff --git a/api/ocm/plugin/ppi/plugin.go b/api/ocm/plugin/ppi/plugin.go index d05a0776c5..7b0d5a6c74 100644 --- a/api/ocm/plugin/ppi/plugin.go +++ b/api/ocm/plugin/ppi/plugin.go @@ -18,8 +18,10 @@ import ( "ocm.software/ocm/api/ocm/ocmutils/registry" "ocm.software/ocm/api/ocm/plugin/descriptor" "ocm.software/ocm/api/utils/cobrautils" + "ocm.software/ocm/api/utils/cobrautils/flagsets" "ocm.software/ocm/api/utils/errkind" "ocm.software/ocm/api/utils/runtime" + inpoptions "ocm.software/ocm/cmds/ocm/commands/ocmcmds/common/inputs/options" ) type plugin struct { @@ -291,10 +293,10 @@ func (p *plugin) DecodeUploadTargetSpecification(data []byte) (UploadTargetSpec, //////////////////////////////////////////////////////////////////////////////// -func cliOpts(optTypes []options.OptionType) ([]CLIOption, error) { +func cliOpts(reg flagsets.ConfigOptionTypeRegistry, optTypes []flagsets.ConfigOptionType) ([]CLIOption, error) { var optlist []CLIOption for _, o := range optTypes { - known := options.DefaultRegistry.GetOptionType(o.GetName()) + known := reg.GetOptionType(o.GetName()) if known != nil { if o.ValueType() != known.ValueType() { return nil, fmt.Errorf("option type %s[%s] conflicts with standard option type using value type %s", o.GetName(), o.ValueType(), known.ValueType()) @@ -306,7 +308,7 @@ func cliOpts(optTypes []options.OptionType) ([]CLIOption, error) { optlist = append(optlist, CLIOption{ Name: o.GetName(), Type: o.ValueType(), - Description: o.GetDescriptionText(), + Description: o.GetDescription(), }) } } @@ -319,7 +321,7 @@ func (p *plugin) RegisterInputType(m InputType) error { return errors.ErrAlreadyExists(descriptor.KIND_INPUTTYPE, n) } - optlist, err := cliOpts(m.Options()) + optlist, err := cliOpts(inpoptions.DefaultRegistry, m.Options()) if err != nil { return err } @@ -359,7 +361,7 @@ func (p *plugin) RegisterAccessMethod(m AccessMethod) error { return errors.ErrAlreadyExists(errkind.KIND_ACCESSMETHOD, n) } - optlist, err := cliOpts(m.Options()) + optlist, err := cliOpts(options.DefaultRegistry, m.Options()) if err != nil { return err } @@ -515,24 +517,11 @@ func (p *plugin) RegisterValueSet(s ValueSet) error { } } - var optlist []CLIOption - for _, o := range s.Options() { - known := options.DefaultRegistry.GetOptionType(o.GetName()) - if known != nil { - if o.ValueType() != known.ValueType() { - return fmt.Errorf("option type %s[%s] conflicts with standard option type using value type %s", o.GetName(), o.ValueType(), known.ValueType()) - } - optlist = append(optlist, CLIOption{ - Name: o.GetName(), - }) - } else { - optlist = append(optlist, CLIOption{ - Name: o.GetName(), - Type: o.ValueType(), - Description: o.GetDescriptionText(), - }) - } + optlist, err := cliOpts(options.DefaultRegistry, s.Options()) + if err != nil { + return err } + vers := s.Version() if vers == "" { set := descriptor.ValueSetDescriptor{ diff --git a/api/ocm/plugin/ppi/utils.go b/api/ocm/plugin/ppi/utils.go index a8eefdbd29..7db240c94b 100644 --- a/api/ocm/plugin/ppi/utils.go +++ b/api/ocm/plugin/ppi/utils.go @@ -8,9 +8,9 @@ import ( "github.com/mandelsoft/goutils/generics" "golang.org/x/exp/slices" - "ocm.software/ocm/api/ocm/extensions/accessmethods/options" "ocm.software/ocm/api/ocm/plugin/descriptor" "ocm.software/ocm/api/tech/signing" + "ocm.software/ocm/api/utils/cobrautils/flagsets" "ocm.software/ocm/api/utils/runtime" ) @@ -311,7 +311,7 @@ func (c Config) GetValue(name string) (interface{}, bool) { return v, ok } -func (c Config) ConvertFor(list ...options.OptionType) error { +func (c Config) ConvertFor(list ...flagsets.ConfigOptionType) error { for _, o := range list { if v, ok := c[o.GetName()]; ok { t := reflect.TypeOf(o.Create().Value()) diff --git a/api/ocm/plugin/utils.go b/api/ocm/plugin/utils.go index bbcb8afd46..05a1195e4f 100644 --- a/api/ocm/plugin/utils.go +++ b/api/ocm/plugin/utils.go @@ -17,12 +17,16 @@ type BlobAccessWriter struct { getter func(writer io.Writer, creds json.RawMessage, spec json.RawMessage) error } -func NewAccessDataWriter(p Plugin, creds, accspec json.RawMessage) *BlobAccessWriter { - return &BlobAccessWriter{creds, accspec, p.Get} +func NewAccessDataWriter(p Plugin, creds, spec json.RawMessage) *BlobAccessWriter { + return &BlobAccessWriter{creds, spec, p.Get} } -func NewInputDataWriter(p Plugin, creds, accspec json.RawMessage) *BlobAccessWriter { - return &BlobAccessWriter{creds, accspec, p.GetInputBlob} +func NewInputDataWriter(p Plugin, dir string, creds, spec json.RawMessage) *BlobAccessWriter { + return &BlobAccessWriter{ + creds: creds, + spec: spec, + getter: func(w io.Writer, creds, spec json.RawMessage) error { return p.GetInputBlob(w, dir, creds, spec) }, + } } func (d *BlobAccessWriter) WriteTo(w accessio.Writer) (int64, digest.Digest, error) { diff --git a/api/utils/cobrautils/flagsets/configoptionset.go b/api/utils/cobrautils/flagsets/configoptionset.go index ae846beb2f..d964af3c04 100644 --- a/api/utils/cobrautils/flagsets/configoptionset.go +++ b/api/utils/cobrautils/flagsets/configoptionset.go @@ -11,6 +11,8 @@ import ( type ConfigOptionType interface { GetName() string + GetDescriptionText() string + ValueType() string GetDescription() string Create() Option @@ -293,7 +295,7 @@ func (s *configOptionTypeSet) check(list []ConfigOptionType) error { for _, o := range list { old := s.options[o.GetName()] if old != nil && !old.Equal(o) { - return fmt.Errorf("option type %s doesn't match (%T<->%T)", o.GetName(), o, old) + return fmt.Errorf("option type %q doesn't match ([%T,%s]<->[%T,%s])", o.GetName(), o, o.GetDescription(), old, old.GetDescription()) } } return nil diff --git a/api/ocm/extensions/accessmethods/options/registry.go b/api/utils/cobrautils/flagsets/registry.go similarity index 65% rename from api/ocm/extensions/accessmethods/options/registry.go rename to api/utils/cobrautils/flagsets/registry.go index f45c5dbb16..b5ef53c477 100644 --- a/api/ocm/extensions/accessmethods/options/registry.go +++ b/api/utils/cobrautils/flagsets/registry.go @@ -1,4 +1,4 @@ -package options +package flagsets import ( "sync" @@ -13,10 +13,10 @@ const ( KIND_OPTION = "option" ) -type OptionTypeCreator func(name string, description string) OptionType +type ConfigOptionTypeCreator func(name string, description string) ConfigOptionType type ValueTypeInfo struct { - OptionTypeCreator + ConfigOptionTypeCreator Description string } @@ -24,33 +24,31 @@ func (i ValueTypeInfo) GetDescription() string { return i.Description } -type Registry = *registry - -var DefaultRegistry = New() +type ConfigOptionTypeRegistry = *registry type registry struct { lock sync.RWMutex valueTypes map[string]ValueTypeInfo - optionTypes map[string]OptionType + optionTypes map[string]ConfigOptionType } -func New() Registry { +func NewConfigOptionTypeRegistry() ConfigOptionTypeRegistry { return ®istry{ valueTypes: map[string]ValueTypeInfo{}, - optionTypes: map[string]OptionType{}, + optionTypes: map[string]ConfigOptionType{}, } } -func (r *registry) RegisterOptionType(t OptionType) { +func (r *registry) RegisterOptionType(t ConfigOptionType) { r.lock.Lock() defer r.lock.Unlock() r.optionTypes[t.GetName()] = t } -func (r *registry) RegisterValueType(name string, c OptionTypeCreator, desc string) { +func (r *registry) RegisterValueType(name string, c ConfigOptionTypeCreator, desc string) { r.lock.Lock() defer r.lock.Unlock() - r.valueTypes[name] = ValueTypeInfo{OptionTypeCreator: c, Description: desc} + r.valueTypes[name] = ValueTypeInfo{ConfigOptionTypeCreator: c, Description: desc} } func (r *registry) GetValueType(name string) *ValueTypeInfo { @@ -62,13 +60,13 @@ func (r *registry) GetValueType(name string) *ValueTypeInfo { return nil } -func (r *registry) GetOptionType(name string) OptionType { +func (r *registry) GetOptionType(name string) ConfigOptionType { r.lock.RLock() defer r.lock.RUnlock() return r.optionTypes[name] } -func (r *registry) CreateOptionType(typ, name, desc string) (OptionType, error) { +func (r *registry) CreateOptionType(typ, name, desc string) (ConfigOptionType, error) { r.lock.RLock() defer r.lock.RUnlock() t, ok := r.valueTypes[typ] @@ -76,7 +74,7 @@ func (r *registry) CreateOptionType(typ, name, desc string) (OptionType, error) return nil, errors.ErrUnknown(KIND_OPTIONTYPE, typ) } - n := t.OptionTypeCreator(name, desc) + n := t.ConfigOptionTypeCreator(name, desc) o := r.optionTypes[name] if o != nil { if o.ValueType() != n.ValueType() { diff --git a/api/utils/cobrautils/flagsets/registry_test.go b/api/utils/cobrautils/flagsets/registry_test.go new file mode 100644 index 0000000000..8fe13f02c9 --- /dev/null +++ b/api/utils/cobrautils/flagsets/registry_test.go @@ -0,0 +1,53 @@ +package flagsets_test + +import ( + . "github.com/mandelsoft/goutils/testutils" + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + "ocm.software/ocm/api/utils/cobrautils/flagsets" + + "ocm.software/ocm/api/ocm/extensions/accessmethods/options" +) + +var _ = Describe("registry", func() { + var reg flagsets.ConfigOptionTypeRegistry + + BeforeEach(func() { + reg = flagsets.NewConfigOptionTypeRegistry() + }) + + It("sets and retrieves type", func() { + reg.RegisterValueType("string", flagsets.NewStringOptionType, "string") + + t := reg.GetValueType("string") + Expect(t).NotTo(BeNil()) + + o := Must(reg.CreateOptionType("string", "test", "some test")) + Expect(o.GetName()).To(Equal("test")) + Expect(o.GetDescription()).To(Equal("[*string*] some test")) + }) + + It("sets and retrieves option", func() { + reg.RegisterOptionType(options.HostnameOption) + + t := reg.GetOptionType(options.HostnameOption.GetName()) + Expect(t).NotTo(BeNil()) + }) + + It("creates merges a new type", func() { + reg.RegisterValueType("string", flagsets.NewStringOptionType, "string") + reg.RegisterOptionType(options.HostnameOption) + + o := Must(reg.CreateOptionType("string", options.HostnameOption.GetName(), "some test")) + Expect(o).To(BeIdenticalTo(options.HostnameOption)) + }) + + It("fails creating existing", func() { + reg.RegisterValueType("string", flagsets.NewStringOptionType, "string") + reg.RegisterValueType("int", flagsets.NewIntOptionType, "int") + reg.RegisterOptionType(options.HostnameOption) + + _, err := reg.CreateOptionType("int", options.HostnameOption.GetName(), "some test") + MustFailWithMessage(err, "option \"accessHostname\" already exists") + }) +}) diff --git a/api/utils/cobrautils/flagsets/types.go b/api/utils/cobrautils/flagsets/types.go index b3aaacf097..f205fa9179 100644 --- a/api/utils/cobrautils/flagsets/types.go +++ b/api/utils/cobrautils/flagsets/types.go @@ -1,7 +1,7 @@ package flagsets import ( - "reflect" + "fmt" "github.com/spf13/pflag" @@ -10,9 +10,41 @@ import ( "ocm.software/ocm/api/utils/cobrautils/groups" ) +const ( + TYPE_STRING = "string" + TYPE_STRINGARRAY = "[]string" + TYPE_STRING2STRING = "string=string" + TYPE_INT = "int" + TYPE_BOOL = "bool" + TYPE_YAML = "YAML" + TYPE_STRINGMAPYAML = "map[string]YAML" + TYPE_STRING2YAML = "string=YAML" + TYPE_STRING2STRINGSLICE = "string=string,string" + TYPE_STRINGCOLONSTRINGSLICE = "string:string,string" + TYPE_BYTES = "[]byte" + TYPE_IDENTITYPATH = "[]identity" +) + +func SetBaseTypes(r ConfigOptionTypeRegistry) ConfigOptionTypeRegistry { + r.RegisterValueType(TYPE_STRING, NewStringOptionType, "string value") + r.RegisterValueType(TYPE_STRINGARRAY, NewStringArrayOptionType, "list of string values") + r.RegisterValueType(TYPE_STRING2STRING, NewStringMapOptionType, "string map defined by dedicated assignments") + r.RegisterValueType(TYPE_INT, NewIntOptionType, "integer value") + r.RegisterValueType(TYPE_BOOL, NewBoolOptionType, "boolean flag") + r.RegisterValueType(TYPE_YAML, NewYAMLOptionType, "JSON or YAML document string") + r.RegisterValueType(TYPE_STRINGMAPYAML, NewValueMapYAMLOptionType, "JSON or YAML map") + r.RegisterValueType(TYPE_STRING2YAML, NewValueMapOptionType, "string map with arbitrary values defined by dedicated assignments") + r.RegisterValueType(TYPE_STRING2STRINGSLICE, NewStringSliceMapOptionType, "string map defined by dedicated assignment of comma separated strings") + r.RegisterValueType(TYPE_STRINGCOLONSTRINGSLICE, NewStringSliceMapColonOptionType, "string map defined by dedicated assignment of comma separated strings") + r.RegisterValueType(TYPE_BYTES, NewBytesOptionType, "byte value") + r.RegisterValueType(TYPE_IDENTITYPATH, NewIdentityPathOptionType, "identity path") + return r +} + type TypeOptionBase struct { name string description string + valueType string } func (b *TypeOptionBase) GetName() string { @@ -20,9 +52,23 @@ func (b *TypeOptionBase) GetName() string { } func (b *TypeOptionBase) GetDescription() string { + return fmt.Sprintf("[*%s*] %s", b.ValueType(), b.description) +} + +func (b *TypeOptionBase) GetDescriptionText() string { return b.description } +func (o *TypeOptionBase) ValueType() string { + return o.valueType +} + +func (o *TypeOptionBase) Equal(t ConfigOptionType) bool { + return o.name == t.GetName() && + o.description == t.GetDescriptionText() && + o.valueType == t.ValueType() +} + //////////////////////////////////////////////////////////////////////////////// type OptionBase struct { @@ -44,7 +90,7 @@ func (b *OptionBase) GetName() string { } func (b *OptionBase) Description() string { - return b.otyp.GetDescription() + return b.otyp.GetDescriptionText() } func (b *OptionBase) Changed() bool { @@ -80,14 +126,10 @@ type StringOptionType struct { func NewStringOptionType(name string, description string) ConfigOptionType { return &StringOptionType{ - TypeOptionBase: TypeOptionBase{name, description}, + TypeOptionBase: TypeOptionBase{name, description, TYPE_STRING}, } } -func (s *StringOptionType) Equal(optionType ConfigOptionType) bool { - return reflect.DeepEqual(s, optionType) -} - func (s *StringOptionType) Create() Option { return &StringOption{ OptionBase: NewOptionBase(s), @@ -102,7 +144,7 @@ type StringOption struct { var _ Option = (*StringOption)(nil) func (o *StringOption) AddFlags(fs *pflag.FlagSet) { - o.TweakFlag(flag.StringVarPF(fs, &o.value, o.otyp.GetName(), "", "", o.otyp.GetDescription())) + o.TweakFlag(flag.StringVarPF(fs, &o.value, o.otyp.GetName(), "", "", o.otyp.GetDescriptionText())) } func (o *StringOption) Value() interface{} { @@ -117,14 +159,10 @@ type StringArrayOptionType struct { func NewStringArrayOptionType(name string, description string) ConfigOptionType { return &StringArrayOptionType{ - TypeOptionBase: TypeOptionBase{name, description}, + TypeOptionBase: TypeOptionBase{name, description, TYPE_STRINGARRAY}, } } -func (s *StringArrayOptionType) Equal(optionType ConfigOptionType) bool { - return reflect.DeepEqual(s, optionType) -} - func (s *StringArrayOptionType) Create() Option { return &StringArrayOption{ OptionBase: NewOptionBase(s), @@ -139,87 +177,13 @@ type StringArrayOption struct { var _ Option = (*StringArrayOption)(nil) func (o *StringArrayOption) AddFlags(fs *pflag.FlagSet) { - o.TweakFlag(flag.StringArrayVarPF(fs, &o.value, o.otyp.GetName(), "", nil, o.otyp.GetDescription())) + o.TweakFlag(flag.StringArrayVarPF(fs, &o.value, o.otyp.GetName(), "", nil, o.otyp.GetDescriptionText())) } func (o *StringArrayOption) Value() interface{} { return o.value } -// PathOptionType ////////////////////////////////////////////////////////////////////////////// - -type PathOptionType struct { - TypeOptionBase -} - -func NewPathOptionType(name string, description string) ConfigOptionType { - return &PathOptionType{ - TypeOptionBase: TypeOptionBase{name, description}, - } -} - -func (s *PathOptionType) Equal(optionType ConfigOptionType) bool { - return reflect.DeepEqual(s, optionType) -} - -func (s *PathOptionType) Create() Option { - return &PathOption{ - OptionBase: NewOptionBase(s), - } -} - -type PathOption struct { - OptionBase - value string -} - -var _ Option = (*PathOption)(nil) - -func (o *PathOption) AddFlags(fs *pflag.FlagSet) { - o.TweakFlag(flag.PathVarPF(fs, &o.value, o.otyp.GetName(), "", "", o.otyp.GetDescription())) -} - -func (o *PathOption) Value() interface{} { - return o.value -} - -// PathArrayOptionType ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -type PathArrayOptionType struct { - TypeOptionBase -} - -func NewPathArrayOptionType(name string, description string) ConfigOptionType { - return &PathArrayOptionType{ - TypeOptionBase: TypeOptionBase{name, description}, - } -} - -func (s *PathArrayOptionType) Equal(optionType ConfigOptionType) bool { - return reflect.DeepEqual(s, optionType) -} - -func (s *PathArrayOptionType) Create() Option { - return &PathArrayOption{ - OptionBase: NewOptionBase(s), - } -} - -type PathArrayOption struct { - OptionBase - value []string -} - -var _ Option = (*PathArrayOption)(nil) - -func (o *PathArrayOption) AddFlags(fs *pflag.FlagSet) { - o.TweakFlag(flag.PathArrayVarPF(fs, &o.value, o.otyp.GetName(), "", nil, o.otyp.GetDescription())) -} - -func (o *PathArrayOption) Value() interface{} { - return o.value -} - //////////////////////////////////////////////////////////////////////////////// type BoolOptionType struct { @@ -228,14 +192,10 @@ type BoolOptionType struct { func NewBoolOptionType(name string, description string) ConfigOptionType { return &BoolOptionType{ - TypeOptionBase: TypeOptionBase{name, description}, + TypeOptionBase: TypeOptionBase{name, description, TYPE_BOOL}, } } -func (s *BoolOptionType) Equal(optionType ConfigOptionType) bool { - return reflect.DeepEqual(s, optionType) -} - func (s *BoolOptionType) Create() Option { return &BoolOption{ OptionBase: NewOptionBase(s), @@ -250,7 +210,7 @@ type BoolOption struct { var _ Option = (*BoolOption)(nil) func (o *BoolOption) AddFlags(fs *pflag.FlagSet) { - o.TweakFlag(flag.BoolVarPF(fs, &o.value, o.otyp.GetName(), "", false, o.otyp.GetDescription())) + o.TweakFlag(flag.BoolVarPF(fs, &o.value, o.otyp.GetName(), "", false, o.otyp.GetDescriptionText())) } func (o *BoolOption) Value() interface{} { @@ -265,14 +225,10 @@ type IntOptionType struct { func NewIntOptionType(name string, description string) ConfigOptionType { return &IntOptionType{ - TypeOptionBase: TypeOptionBase{name, description}, + TypeOptionBase: TypeOptionBase{name, description, TYPE_INT}, } } -func (s *IntOptionType) Equal(optionType ConfigOptionType) bool { - return reflect.DeepEqual(s, optionType) -} - func (s *IntOptionType) Create() Option { return &IntOption{ OptionBase: NewOptionBase(s), @@ -287,7 +243,7 @@ type IntOption struct { var _ Option = (*IntOption)(nil) func (o *IntOption) AddFlags(fs *pflag.FlagSet) { - o.TweakFlag(flag.IntVarPF(fs, &o.value, o.otyp.GetName(), "", 0, o.otyp.GetDescription())) + o.TweakFlag(flag.IntVarPF(fs, &o.value, o.otyp.GetName(), "", 0, o.otyp.GetDescriptionText())) } func (o *IntOption) Value() interface{} { @@ -302,14 +258,10 @@ type YAMLOptionType struct { func NewYAMLOptionType(name string, description string) ConfigOptionType { return &YAMLOptionType{ - TypeOptionBase: TypeOptionBase{name, description}, + TypeOptionBase: TypeOptionBase{name, description, TYPE_YAML}, } } -func (s *YAMLOptionType) Equal(optionType ConfigOptionType) bool { - return reflect.DeepEqual(s, optionType) -} - func (s *YAMLOptionType) Create() Option { return &YAMLOption{ OptionBase: NewOptionBase(s), @@ -324,7 +276,7 @@ type YAMLOption struct { var _ Option = (*YAMLOption)(nil) func (o *YAMLOption) AddFlags(fs *pflag.FlagSet) { - o.TweakFlag(flag.YAMLVarPF(fs, &o.value, o.otyp.GetName(), "", nil, o.otyp.GetDescription())) + o.TweakFlag(flag.YAMLVarPF(fs, &o.value, o.otyp.GetName(), "", nil, o.otyp.GetDescriptionText())) } func (o *YAMLOption) Value() interface{} { @@ -339,14 +291,10 @@ type ValueMapYAMLOptionType struct { func NewValueMapYAMLOptionType(name string, description string) ConfigOptionType { return &ValueMapYAMLOptionType{ - TypeOptionBase: TypeOptionBase{name, description}, + TypeOptionBase: TypeOptionBase{name, description, TYPE_STRINGMAPYAML}, } } -func (s *ValueMapYAMLOptionType) Equal(optionType ConfigOptionType) bool { - return reflect.DeepEqual(s, optionType) -} - func (s *ValueMapYAMLOptionType) Create() Option { return &ValueMapYAMLOption{ OptionBase: NewOptionBase(s), @@ -361,7 +309,7 @@ type ValueMapYAMLOption struct { var _ Option = (*ValueMapYAMLOption)(nil) func (o *ValueMapYAMLOption) AddFlags(fs *pflag.FlagSet) { - o.TweakFlag(flag.YAMLVarPF(fs, &o.value, o.otyp.GetName(), "", nil, o.otyp.GetDescription())) + o.TweakFlag(flag.YAMLVarPF(fs, &o.value, o.otyp.GetName(), "", nil, o.otyp.GetDescriptionText())) } func (o *ValueMapYAMLOption) Value() interface{} { @@ -376,14 +324,10 @@ type ValueMapOptionType struct { func NewValueMapOptionType(name string, description string) ConfigOptionType { return &ValueMapOptionType{ - TypeOptionBase: TypeOptionBase{name, description}, + TypeOptionBase: TypeOptionBase{name, description, TYPE_STRING2YAML}, } } -func (s *ValueMapOptionType) Equal(optionType ConfigOptionType) bool { - return reflect.DeepEqual(s, optionType) -} - func (s *ValueMapOptionType) Create() Option { return &ValueMapOption{ OptionBase: NewOptionBase(s), @@ -398,7 +342,7 @@ type ValueMapOption struct { var _ Option = (*ValueMapOption)(nil) func (o *ValueMapOption) AddFlags(fs *pflag.FlagSet) { - o.TweakFlag(flag.StringToValueVarPF(fs, &o.value, o.otyp.GetName(), "", nil, o.otyp.GetDescription())) + o.TweakFlag(flag.StringToValueVarPF(fs, &o.value, o.otyp.GetName(), "", nil, o.otyp.GetDescriptionText())) } func (o *ValueMapOption) Value() interface{} { @@ -413,14 +357,10 @@ type StringMapOptionType struct { func NewStringMapOptionType(name string, description string) ConfigOptionType { return &StringMapOptionType{ - TypeOptionBase: TypeOptionBase{name, description}, + TypeOptionBase: TypeOptionBase{name, description, TYPE_STRING2STRING}, } } -func (s *StringMapOptionType) Equal(optionType ConfigOptionType) bool { - return reflect.DeepEqual(s, optionType) -} - func (s *StringMapOptionType) Create() Option { return &StringMapOption{ OptionBase: NewOptionBase(s), @@ -435,7 +375,7 @@ type StringMapOption struct { var _ Option = (*StringMapOption)(nil) func (o *StringMapOption) AddFlags(fs *pflag.FlagSet) { - o.TweakFlag(flag.StringToStringVarPF(fs, &o.value, o.otyp.GetName(), "", nil, o.otyp.GetDescription())) + o.TweakFlag(flag.StringToStringVarPF(fs, &o.value, o.otyp.GetName(), "", nil, o.otyp.GetDescriptionText())) } func (o *StringMapOption) Value() interface{} { @@ -450,14 +390,10 @@ type BytesOptionType struct { func NewBytesOptionType(name string, description string) ConfigOptionType { return &BytesOptionType{ - TypeOptionBase: TypeOptionBase{name, description}, + TypeOptionBase: TypeOptionBase{name, description, TYPE_BYTES}, } } -func (s *BytesOptionType) Equal(optionType ConfigOptionType) bool { - return reflect.DeepEqual(s, optionType) -} - func (s *BytesOptionType) Create() Option { return &BytesOption{ OptionBase: NewOptionBase(s), @@ -472,7 +408,7 @@ type BytesOption struct { var _ Option = (*BytesOption)(nil) func (o *BytesOption) AddFlags(fs *pflag.FlagSet) { - o.TweakFlag(flag.BytesBase64VarPF(fs, &o.value, o.otyp.GetName(), "", nil, o.otyp.GetDescription())) + o.TweakFlag(flag.BytesBase64VarPF(fs, &o.value, o.otyp.GetName(), "", nil, o.otyp.GetDescriptionText())) } func (o *BytesOption) Value() interface{} { @@ -487,14 +423,10 @@ type StringSliceMapOptionType struct { func NewStringSliceMapOptionType(name string, description string) ConfigOptionType { return &StringSliceMapOptionType{ - TypeOptionBase: TypeOptionBase{name, description}, + TypeOptionBase: TypeOptionBase{name, description, TYPE_STRING2STRINGSLICE}, } } -func (s *StringSliceMapOptionType) Equal(optionType ConfigOptionType) bool { - return reflect.DeepEqual(s, optionType) -} - func (s *StringSliceMapOptionType) Create() Option { return &StringSliceMapOption{ OptionBase: NewOptionBase(s), @@ -509,7 +441,7 @@ type StringSliceMapOption struct { var _ Option = (*StringSliceMapOption)(nil) func (o *StringSliceMapOption) AddFlags(fs *pflag.FlagSet) { - o.TweakFlag(flag.StringToStringSliceVarPF(fs, &o.value, o.otyp.GetName(), "", nil, o.otyp.GetDescription())) + o.TweakFlag(flag.StringToStringSliceVarPF(fs, &o.value, o.otyp.GetName(), "", nil, o.otyp.GetDescriptionText())) } func (o *StringSliceMapOption) Value() interface{} { @@ -524,14 +456,10 @@ type StringSliceMapColonOptionType struct { func NewStringSliceMapColonOptionType(name string, description string) ConfigOptionType { return &StringSliceMapColonOptionType{ - TypeOptionBase: TypeOptionBase{name, description}, + TypeOptionBase: TypeOptionBase{name, description, TYPE_STRINGCOLONSTRINGSLICE}, } } -func (s *StringSliceMapColonOptionType) Equal(optionType ConfigOptionType) bool { - return reflect.DeepEqual(s, optionType) -} - func (s *StringSliceMapColonOptionType) Create() Option { return &StringSliceMapColonOption{ OptionBase: NewOptionBase(s), @@ -546,7 +474,7 @@ type StringSliceMapColonOption struct { var _ Option = (*StringSliceMapColonOption)(nil) func (o *StringSliceMapColonOption) AddFlags(fs *pflag.FlagSet) { - o.TweakFlag(flag.StringColonStringSliceVarPF(fs, &o.value, o.otyp.GetName(), "", nil, o.otyp.GetDescription())) + o.TweakFlag(flag.StringColonStringSliceVarPF(fs, &o.value, o.otyp.GetName(), "", nil, o.otyp.GetDescriptionText())) } func (o *StringSliceMapColonOption) Value() interface{} { @@ -561,14 +489,10 @@ type IdentityPathOptionType struct { func NewIdentityPathOptionType(name string, description string) ConfigOptionType { return &IdentityPathOptionType{ - TypeOptionBase: TypeOptionBase{name, description}, + TypeOptionBase: TypeOptionBase{name, description, TYPE_IDENTITYPATH}, } } -func (s *IdentityPathOptionType) Equal(optionType ConfigOptionType) bool { - return reflect.DeepEqual(s, optionType) -} - func (s *IdentityPathOptionType) Create() Option { return &IdentityPathOption{ OptionBase: NewOptionBase(s), @@ -583,7 +507,7 @@ type IdentityPathOption struct { var _ Option = (*IdentityPathOption)(nil) func (o *IdentityPathOption) AddFlags(fs *pflag.FlagSet) { - o.TweakFlag(flag.IdentityPathVarPF(fs, &o.value, o.otyp.GetName(), "", nil, o.otyp.GetDescription())) + o.TweakFlag(flag.IdentityPathVarPF(fs, &o.value, o.otyp.GetName(), "", nil, o.otyp.GetDescriptionText())) } func (o *IdentityPathOption) Value() interface{} { diff --git a/cmds/demoplugin/accessmethods/demo.go b/cmds/demoplugin/accessmethods/demo.go index cb41f5acf5..079e74a3bc 100644 --- a/cmds/demoplugin/accessmethods/demo.go +++ b/cmds/demoplugin/accessmethods/demo.go @@ -37,7 +37,7 @@ type AccessMethod struct { ppi.AccessMethodBase } -var PathOption = options.NewStringOptionType("accessPath", "path in temp repository") +var PathOption = flagsets.NewStringOptionType("accessPath", "path in temp repository") var _ ppi.AccessMethod = (*AccessMethod)(nil) @@ -47,8 +47,8 @@ func New() ppi.AccessMethod { } } -func (a *AccessMethod) Options() []options.OptionType { - return []options.OptionType{ +func (a *AccessMethod) Options() []flagsets.ConfigOptionType { + return []flagsets.ConfigOptionType{ options.MediatypeOption, PathOption, } diff --git a/cmds/demoplugin/valuesets/check.go b/cmds/demoplugin/valuesets/check.go index 0e75372aff..729428ca6c 100644 --- a/cmds/demoplugin/valuesets/check.go +++ b/cmds/demoplugin/valuesets/check.go @@ -7,7 +7,6 @@ import ( "github.com/mandelsoft/goutils/errors" "github.com/mandelsoft/goutils/set" - "ocm.software/ocm/api/ocm/extensions/accessmethods/options" "ocm.software/ocm/api/ocm/plugin/descriptor" "ocm.software/ocm/api/ocm/plugin/ppi" "ocm.software/ocm/api/utils" @@ -36,8 +35,8 @@ const ( var status = set.New[string](STATUS_PASSED, STATUS_FAILED, STATUS_SKIPPED) var ( - StatusOption = options.NewStringMapOptionType("checkStatus", out.Sprintf("status value for check (%s)", strings.Join(utils.StringMapKeys(status), ", "))) - MessageOption = options.NewStringMapOptionType("checkMessage", "message for check") + StatusOption = flagsets.NewStringMapOptionType("checkStatus", out.Sprintf("status value for check (%s)", strings.Join(utils.StringMapKeys(status), ", "))) + MessageOption = flagsets.NewStringMapOptionType("checkMessage", "message for check") ) type ValueSet struct { @@ -56,8 +55,8 @@ The status entry has the following format: } } -func (v ValueSet) Options() []options.OptionType { - return []options.OptionType{ +func (v ValueSet) Options() []flagsets.ConfigOptionType { + return []flagsets.ConfigOptionType{ StatusOption, MessageOption, } diff --git a/cmds/ocm/commands/ocmcmds/common/inputs/cpi/helper.go b/cmds/ocm/commands/ocmcmds/common/inputs/cpi/helper.go index 2646ae99a7..0bf2e21f60 100644 --- a/cmds/ocm/commands/ocmcmds/common/inputs/cpi/helper.go +++ b/cmds/ocm/commands/ocmcmds/common/inputs/cpi/helper.go @@ -109,12 +109,12 @@ func (s *ProcessSpec) ProcessBlob(ctx inputs.Context, acc blobaccess.DataAccess, } func AddProcessSpecOptionTypes(set flagsets.ConfigOptionTypeSetHandler) { - set.AddOptionType(options.MediaTypeOption) + set.AddOptionType(options.MediatypeOption) set.AddOptionType(options.CompressOption) } func AddProcessSpecConfig(opts flagsets.ConfigOptions, config flagsets.Config) error { - flagsets.AddFieldByOptionP(opts, options.MediaTypeOption, config, "mediaType") + flagsets.AddFieldByOptionP(opts, options.MediatypeOption, config, "mediaType") flagsets.AddFieldByOptionP(opts, options.CompressOption, config, "compress") return nil } diff --git a/cmds/ocm/commands/ocmcmds/common/inputs/options/init.go b/cmds/ocm/commands/ocmcmds/common/inputs/options/init.go new file mode 100644 index 0000000000..387ff5c1f3 --- /dev/null +++ b/cmds/ocm/commands/ocmcmds/common/inputs/options/init.go @@ -0,0 +1,12 @@ +package options + +import ( + "ocm.software/ocm/api/utils/cobrautils/flagsets" +) + +var DefaultRegistry = flagsets.SetBaseTypes(flagsets.NewConfigOptionTypeRegistry()) + +func RegisterOption(o flagsets.ConfigOptionType) flagsets.ConfigOptionType { + DefaultRegistry.RegisterOptionType(o) + return o +} diff --git a/cmds/ocm/commands/ocmcmds/common/inputs/options/standard.go b/cmds/ocm/commands/ocmcmds/common/inputs/options/standard.go index 7ed29a25f3..5fcc6e6315 100644 --- a/cmds/ocm/commands/ocmcmds/common/inputs/options/standard.go +++ b/cmds/ocm/commands/ocmcmds/common/inputs/options/standard.go @@ -6,73 +6,73 @@ import ( ) var ( - HintOption = options.HintOption - MediaTypeOption = options.MediatypeOption + HintOption = RegisterOption(options.HintOption) + MediatypeOption = RegisterOption(options.MediatypeOption) - URLOption = options.URLOption - HTTPHeaderOption = options.HTTPHeaderOption - HTTPVerbOption = options.HTTPVerbOption - HTTPBodyOption = options.HTTPBodyOption - HTTPRedirectOption = options.HTTPRedirectOption + URLOption = RegisterOption(options.URLOption) + HTTPHeaderOption = RegisterOption(options.HTTPHeaderOption) + HTTPVerbOption = RegisterOption(options.HTTPVerbOption) + HTTPBodyOption = RegisterOption(options.HTTPBodyOption) + HTTPRedirectOption = RegisterOption(options.HTTPRedirectOption) - GroupOption = options.GroupOption - ArtifactOption = options.ArtifactOption - ClassifierOption = options.ClassifierOption - ExtensionOption = options.ExtensionOption + GroupOption = RegisterOption(options.GroupOption) + ArtifactOption = RegisterOption(options.ArtifactOption) + ClassifierOption = RegisterOption(options.ClassifierOption) + ExtensionOption = RegisterOption(options.ExtensionOption) - RegistryOption = options.NPMRegistryOption - PackageOption = options.NPMPackageOption - PackageVersionOption = options.NPMVersionOption + RegistryOption = RegisterOption(options.NPMRegistryOption) + PackageOption = RegisterOption(options.NPMPackageOption) + PackageVersionOption = RegisterOption(options.NPMVersionOption) - IdentityPathOption = options.IdentityPathOption + IdentityPathOption = RegisterOption(options.IdentityPathOption) ) // string options. var ( - VersionOption = flagsets.NewStringOptionType("inputVersion", "version info for inputs") - TextOption = flagsets.NewStringOptionType("inputText", "utf8 text") - HelmRepositoryOption = flagsets.NewStringOptionType("inputHelmRepository", "helm repository base URL") + VersionOption = RegisterOption(flagsets.NewStringOptionType("inputVersion", "version info for inputs")) + TextOption = RegisterOption(flagsets.NewStringOptionType("inputText", "utf8 text")) + HelmRepositoryOption = RegisterOption(flagsets.NewStringOptionType("inputHelmRepository", "helm repository base URL")) ) var ( - VariantsOption = flagsets.NewStringArrayOptionType("inputVariants", "(platform) variants for inputs") - PlatformsOption = flagsets.NewStringArrayOptionType("inputPlatforms", "input filter for image platforms ([os]/[architecture])") + VariantsOption = RegisterOption(flagsets.NewStringArrayOptionType("inputVariants", "(platform) variants for inputs")) + PlatformsOption = RegisterOption(flagsets.NewStringArrayOptionType("inputPlatforms", "input filter for image platforms ([os]/[architecture])")) ) // path options. var ( - PathOption = flagsets.NewPathOptionType("inputPath", "path field for input") + PathOption = RegisterOption(flagsets.NewStringOptionType("inputPath", "path field for input")) ) var ( - IncludeOption = flagsets.NewPathArrayOptionType("inputIncludes", "includes (path) for inputs") - ExcludeOption = flagsets.NewPathArrayOptionType("inputExcludes", "excludes (path) for inputs") - LibrariesOption = flagsets.NewPathArrayOptionType("inputLibraries", "library path for inputs") + IncludeOption = RegisterOption(flagsets.NewStringArrayOptionType("inputIncludes", "includes (path) for inputs")) + ExcludeOption = RegisterOption(flagsets.NewStringArrayOptionType("inputExcludes", "excludes (path) for inputs")) + LibrariesOption = RegisterOption(flagsets.NewStringArrayOptionType("inputLibraries", "library path for inputs")) ) // boolean options. var ( - CompressOption = flagsets.NewBoolOptionType("inputCompress", "compress option for input") - PreserveDirOption = flagsets.NewBoolOptionType("inputPreserveDir", "preserve directory in archive for inputs") - FollowSymlinksOption = flagsets.NewBoolOptionType("inputFollowSymlinks", "follow symbolic links during archive creation for inputs") + CompressOption = RegisterOption(flagsets.NewBoolOptionType("inputCompress", "compress option for input")) + PreserveDirOption = RegisterOption(flagsets.NewBoolOptionType("inputPreserveDir", "preserve directory in archive for inputs")) + FollowSymlinksOption = RegisterOption(flagsets.NewBoolOptionType("inputFollowSymlinks", "follow symbolic links during archive creation for inputs")) ) // data options. var ( - DataOption = flagsets.NewBytesOptionType("inputData", "data (string, !!string or !") + DataOption = RegisterOption(flagsets.NewBytesOptionType("inputData", "data (string, !!string or !")) ) // yaml/json options. var ( - YAMLOption = flagsets.NewYAMLOptionType("inputYaml", "YAML formatted text") - JSONOption = flagsets.NewYAMLOptionType("inputJson", "JSON formatted text") - FormattedJSONOption = flagsets.NewYAMLOptionType("inputFormattedJson", "JSON formatted text") + YAMLOption = RegisterOption(flagsets.NewYAMLOptionType("inputYaml", "YAML formatted text")) + JSONOption = RegisterOption(flagsets.NewYAMLOptionType("inputJson", "JSON formatted text")) + FormattedJSONOption = RegisterOption(flagsets.NewYAMLOptionType("inputFormattedJson", "JSON formatted text")) ) var ( - ValuesOption = flagsets.NewValueMapYAMLOptionType("inputValues", "YAML based generic values for inputs") - ComponentOption = flagsets.NewStringOptionType("inputComponent", "component name") + ValuesOption = RegisterOption(flagsets.NewValueMapYAMLOptionType("inputValues", "YAML based generic values for inputs")) + ComponentOption = RegisterOption(flagsets.NewStringOptionType("inputComponent", "component name")) ) // RepositoryOption sets the repository or registry for an input. -var RepositoryOption = flagsets.NewStringOptionType("inputRepository", "repository or registry for inputs") +var RepositoryOption = RegisterOption(flagsets.NewStringOptionType("inputRepository", "repository or registry for inputs")) diff --git a/cmds/ocm/commands/ocmcmds/common/inputs/types/binary/inputtype_test.go b/cmds/ocm/commands/ocmcmds/common/inputs/types/binary/inputtype_test.go index eb381a2ded..0566289430 100644 --- a/cmds/ocm/commands/ocmcmds/common/inputs/types/binary/inputtype_test.go +++ b/cmds/ocm/commands/ocmcmds/common/inputs/types/binary/inputtype_test.go @@ -18,7 +18,7 @@ var _ = Describe("Input Type", func() { It("simple string decode", func() { env.Set(options.CompressOption, "true") - env.Set(options.MediaTypeOption, "media") + env.Set(options.MediatypeOption, "media") env.Set(options.DataOption, "!stringdata") env.Check(&Spec{ Data: runtime.Binary("stringdata"), @@ -28,7 +28,7 @@ var _ = Describe("Input Type", func() { It("binary decode", func() { env.Set(options.CompressOption, "true") - env.Set(options.MediaTypeOption, "media") + env.Set(options.MediatypeOption, "media") env.Set(options.DataOption, "IXN0cmluZ2RhdGE=") env.Check(&Spec{ Data: runtime.Binary("!stringdata"), diff --git a/cmds/ocm/commands/ocmcmds/common/inputs/types/directory/inputtype_test.go b/cmds/ocm/commands/ocmcmds/common/inputs/types/directory/inputtype_test.go index 6679c7905b..bbc2aa7065 100644 --- a/cmds/ocm/commands/ocmcmds/common/inputs/types/directory/inputtype_test.go +++ b/cmds/ocm/commands/ocmcmds/common/inputs/types/directory/inputtype_test.go @@ -21,7 +21,7 @@ var _ = Describe("Input Type", func() { It("simple decode", func() { env.Set(options.PathOption, "mypath") env.Set(options.CompressOption, "true") - env.Set(options.MediaTypeOption, "media") + env.Set(options.MediatypeOption, "media") env.Set(options.PreserveDirOption, "false") env.Set(options.FollowSymlinksOption, "true") env.Set(options.IncludeOption, "x") diff --git a/cmds/ocm/commands/ocmcmds/common/inputs/types/plugin/plugin_test.go b/cmds/ocm/commands/ocmcmds/common/inputs/types/plugin/plugin_test.go index 0149c2ee35..b237edbc86 100644 --- a/cmds/ocm/commands/ocmcmds/common/inputs/types/plugin/plugin_test.go +++ b/cmds/ocm/commands/ocmcmds/common/inputs/types/plugin/plugin_test.go @@ -123,7 +123,7 @@ mediaType: plain/text opts.AddFlags(fs) Expect("\n" + fs.FlagUsages()).To(Equal(` - --inputPath string path in temp file + --inputPath string path field for input --mediaType string media type for artifact blob representation `)) diff --git a/cmds/ocm/commands/ocmcmds/common/inputs/types/plugin/spec.go b/cmds/ocm/commands/ocmcmds/common/inputs/types/plugin/spec.go index 2eb8ffdc6f..4f62546214 100644 --- a/cmds/ocm/commands/ocmcmds/common/inputs/types/plugin/spec.go +++ b/cmds/ocm/commands/ocmcmds/common/inputs/types/plugin/spec.go @@ -38,7 +38,11 @@ func (s *Spec) GetBlob(ctx inputs.Context, info inputs.InputResourceInfo) (bloba if err != nil { return nil, "", err } - return acc.GetBlob() + dir, err := inputs.GetBaseDir(ctx.FileSystem(), info.InputFilePath) + if err != nil { + dir = "." + } + return acc.GetBlob(dir) } func (s *Spec) GetInputVersion(ctx inputs.Context) string { @@ -77,12 +81,12 @@ func (m *access) MimeType() string { return m.info.MediaType } -func (m *access) GetBlob() (blobaccess.BlobAccess, string, error) { +func (m *access) GetBlob(dir string) (blobaccess.BlobAccess, string, error) { spec, err := json.Marshal(m.spec) if err != nil { - return nil, "", errors.Wrapf(err, "cannot marshal access spec") + return nil, "", errors.Wrapf(err, "cannot marshal input spec") } - return accessobj.CachedBlobAccessForWriter(m.ctx, m.MimeType(), plugin.NewInputDataWriter(m.handler.plug, m.creds, spec)), m.info.Hint, nil + return accessobj.CachedBlobAccessForWriter(m.ctx, m.MimeType(), plugin.NewInputDataWriter(m.handler.plug, dir, m.creds, spec)), m.info.Hint, nil } func (m *access) GetConsumerId(uctx ...credentials.UsageContext) credentials.ConsumerIdentity { diff --git a/cmds/ocm/commands/ocmcmds/common/inputs/types/plugin/testdata/plugin/inputhandlers/demo.go b/cmds/ocm/commands/ocmcmds/common/inputs/types/plugin/testdata/plugin/inputhandlers/demo.go index 84a6cb0753..083199dd35 100644 --- a/cmds/ocm/commands/ocmcmds/common/inputs/types/plugin/testdata/plugin/inputhandlers/demo.go +++ b/cmds/ocm/commands/ocmcmds/common/inputs/types/plugin/testdata/plugin/inputhandlers/demo.go @@ -11,12 +11,12 @@ import ( "ocm.software/ocm/api/credentials" "ocm.software/ocm/api/credentials/cpi" - "ocm.software/ocm/api/ocm/extensions/accessmethods/options" "ocm.software/ocm/api/ocm/plugin/ppi" "ocm.software/ocm/api/tech/oci/identity" "ocm.software/ocm/api/utils/cobrautils/flagsets" "ocm.software/ocm/api/utils/runtime" "ocm.software/ocm/cmds/demoplugin/common" + "ocm.software/ocm/cmds/ocm/commands/ocmcmds/common/inputs/options" ) const ( @@ -35,8 +35,6 @@ type InputType struct { ppi.InputTypeBase } -var PathOption = options.NewStringOptionType("inputPath", "path in temp file") - var _ ppi.InputType = (*InputType)(nil) func New() ppi.InputType { @@ -45,10 +43,10 @@ func New() ppi.InputType { } } -func (a *InputType) Options() []options.OptionType { - return []options.OptionType{ +func (a *InputType) Options() []flagsets.ConfigOptionType { + return []flagsets.ConfigOptionType{ options.MediatypeOption, - PathOption, + options.PathOption, } } @@ -64,7 +62,7 @@ func (a *InputType) Decode(data []byte, unmarshaler runtime.Unmarshaler) (runtim return &spec, nil } -func (a *InputType) ValidateSpecification(p ppi.Plugin, spec ppi.InputSpec) (*ppi.InputSpecInfo, error) { +func (a *InputType) ValidateSpecification(p ppi.Plugin, dir string, spec ppi.InputSpec) (*ppi.InputSpecInfo, error) { var info ppi.InputSpecInfo my := spec.(*InputSpec) @@ -92,12 +90,12 @@ func (a *InputType) ValidateSpecification(p ppi.Plugin, spec ppi.InputSpec) (*pp func (a *InputType) ComposeSpecification(p ppi.Plugin, opts ppi.Config, config ppi.Config) error { list := errors.ErrListf("configuring options") - list.Add(flagsets.AddFieldByOptionP(opts, PathOption, config, "path")) + list.Add(flagsets.AddFieldByOptionP(opts, options.PathOption, config, "path")) list.Add(flagsets.AddFieldByOptionP(opts, options.MediatypeOption, config, "mediaType")) return list.Result() } -func (a *InputType) Reader(p ppi.Plugin, spec ppi.InputSpec, creds credentials.Credentials) (io.ReadCloser, error) { +func (a *InputType) Reader(p ppi.Plugin, dir string, spec ppi.InputSpec, creds credentials.Credentials) (io.ReadCloser, error) { my := spec.(*InputSpec) root := os.TempDir() diff --git a/cmds/ocm/commands/ocmcmds/common/inputs/types/plugin/type.go b/cmds/ocm/commands/ocmcmds/common/inputs/types/plugin/type.go index 3ab9d1cfd9..732e057387 100644 --- a/cmds/ocm/commands/ocmcmds/common/inputs/types/plugin/type.go +++ b/cmds/ocm/commands/ocmcmds/common/inputs/types/plugin/type.go @@ -1,11 +1,11 @@ package plugin import ( - "ocm.software/ocm/api/ocm/extensions/accessmethods/options" "ocm.software/ocm/api/ocm/plugin" "ocm.software/ocm/api/utils/cobrautils/flagsets" "ocm.software/ocm/api/utils/runtime" "ocm.software/ocm/cmds/ocm/commands/ocmcmds/common/inputs" + "ocm.software/ocm/cmds/ocm/commands/ocmcmds/common/inputs/options" ) type inputType struct { diff --git a/cmds/ocm/commands/ocmcmds/common/inputs/types/utf8/inputtype_test.go b/cmds/ocm/commands/ocmcmds/common/inputs/types/utf8/inputtype_test.go index 1afad536f4..8feb3f38b9 100644 --- a/cmds/ocm/commands/ocmcmds/common/inputs/types/utf8/inputtype_test.go +++ b/cmds/ocm/commands/ocmcmds/common/inputs/types/utf8/inputtype_test.go @@ -22,7 +22,7 @@ var _ = Describe("Input Type", func() { It("simple string decode", func() { env.Set(options.CompressOption, "true") - env.Set(options.MediaTypeOption, "media") + env.Set(options.MediatypeOption, "media") env.Set(options.TextOption, "stringdata") env.Check(&Spec{ Text: "stringdata", @@ -32,7 +32,7 @@ var _ = Describe("Input Type", func() { It("simple json decode", func() { env.Set(options.CompressOption, "true") - env.Set(options.MediaTypeOption, "media") + env.Set(options.MediatypeOption, "media") env.Set(options.JSONOption, `field: value`) env.Check(&Spec{ Json: []byte(`{"field":"value"}`), @@ -42,7 +42,7 @@ var _ = Describe("Input Type", func() { It("simple formatted json decode", func() { env.Set(options.CompressOption, "true") - env.Set(options.MediaTypeOption, "media") + env.Set(options.MediatypeOption, "media") env.Set(options.FormattedJSONOption, `field: value`) env.Check(&Spec{ FormattedJson: []byte(`{"field":"value"}`), @@ -52,7 +52,7 @@ var _ = Describe("Input Type", func() { It("simple yaml decode", func() { env.Set(options.CompressOption, "true") - env.Set(options.MediaTypeOption, "media") + env.Set(options.MediatypeOption, "media") env.Set(options.YAMLOption, `field: value`) env.Check(&Spec{ Yaml: []byte(`{"field":"value"}`), diff --git a/cmds/ocm/commands/ocmcmds/common/inputs/types/wget/cli.go b/cmds/ocm/commands/ocmcmds/common/inputs/types/wget/cli.go index e8e16f098f..73cb7a1bc8 100644 --- a/cmds/ocm/commands/ocmcmds/common/inputs/types/wget/cli.go +++ b/cmds/ocm/commands/ocmcmds/common/inputs/types/wget/cli.go @@ -9,7 +9,7 @@ func ConfigHandler() flagsets.ConfigOptionTypeSetHandler { return flagsets.NewConfigOptionTypeSetHandler( TYPE, AddConfig, options.URLOption, - options.MediaTypeOption, + options.MediatypeOption, options.HTTPHeaderOption, options.HTTPVerbOption, options.HTTPBodyOption, @@ -19,7 +19,7 @@ func ConfigHandler() flagsets.ConfigOptionTypeSetHandler { func AddConfig(opts flagsets.ConfigOptions, config flagsets.Config) error { flagsets.AddFieldByOptionP(opts, options.URLOption, config, "url") - flagsets.AddFieldByOptionP(opts, options.MediaTypeOption, config, "mediaType") + flagsets.AddFieldByOptionP(opts, options.MediatypeOption, config, "mediaType") flagsets.AddFieldByOptionP(opts, options.HTTPHeaderOption, config, "header") flagsets.AddFieldByOptionP(opts, options.HTTPVerbOption, config, "verb") flagsets.AddFieldByOptionP(opts, options.HTTPBodyOption, config, "body") diff --git a/cmds/ocm/commands/ocmcmds/common/inputs/types/wget/input_test.go b/cmds/ocm/commands/ocmcmds/common/inputs/types/wget/input_test.go index 6c20995db8..17c1a2f415 100644 --- a/cmds/ocm/commands/ocmcmds/common/inputs/types/wget/input_test.go +++ b/cmds/ocm/commands/ocmcmds/common/inputs/types/wget/input_test.go @@ -21,7 +21,7 @@ var _ = Describe("Input Type", func() { It("simple decode", func() { env.Set(options.URLOption, "https://example.com/test") - env.Set(options.MediaTypeOption, mime.MIME_TEXT) + env.Set(options.MediatypeOption, mime.MIME_TEXT) env.Set(options.HTTPHeaderOption, "Host: developer.mozilla.org") env.Set(options.HTTPHeaderOption, "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:50.0) Gecko/20100101 Firefox/50.0") env.Set(options.HTTPHeaderOption, "Accept: text/html, application/xhtml+xml, application/xml;q=0.9, */*;q=0.8")