From e7266cf9a3a8a4898abf7830c269adf1131d04bc Mon Sep 17 00:00:00 2001 From: Johannes Neisener Date: Tue, 29 Sep 2026 08:05:33 +0200 Subject: [PATCH] chore: Add `HTTP` alias for `Wget` input type Signed-off-by: Johannes Neisener On-behalf-of: @SAP --- .../common/inputs/types/wget/alias_test.go | 52 +++++++++++++++++++ .../ocmcmds/common/inputs/types/wget/cli.go | 10 +++- .../ocmcmds/common/inputs/types/wget/type.go | 15 +++++- .../ocm_add_resource-configuration.md | 2 +- docs/reference/ocm_add_resources.md | 2 +- .../reference/ocm_add_source-configuration.md | 2 +- docs/reference/ocm_add_sources.md | 2 +- 7 files changed, 79 insertions(+), 6 deletions(-) create mode 100644 cmds/ocm/commands/ocmcmds/common/inputs/types/wget/alias_test.go diff --git a/cmds/ocm/commands/ocmcmds/common/inputs/types/wget/alias_test.go b/cmds/ocm/commands/ocmcmds/common/inputs/types/wget/alias_test.go new file mode 100644 index 0000000000..98f20605fa --- /dev/null +++ b/cmds/ocm/commands/ocmcmds/common/inputs/types/wget/alias_test.go @@ -0,0 +1,52 @@ +package wget_test + +import ( + "encoding/json" + "fmt" + + . "github.com/mandelsoft/goutils/testutils" + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + + "ocm.software/ocm/api/utils/runtime" + "ocm.software/ocm/cmds/ocm/commands/ocmcmds/common/inputs" + "ocm.software/ocm/cmds/ocm/commands/ocmcmds/common/inputs/types/wget" +) + +const aliasURL = "https://example.com/file" + +var _ = Describe("wget input type spellings", func() { + mkData := func(typ string) []byte { + return []byte(fmt.Sprintf(`{"type":%q,"url":%q}`, typ, aliasURL)) + } + + DescribeTable("decode and round-trip every accepted type spelling", + func(typ string) { + in := mkData(typ) + + By("decoding via the default input type scheme") + spec := Must(inputs.DefaultInputTypeScheme.DecodeInputSpec(in, runtime.DefaultJSONEncoding)) + Expect(spec).To(BeAssignableToTypeOf(&wget.Spec{})) + Expect(spec.GetType()).To(Equal(typ)) + Expect(spec.(*wget.Spec).URL).To(Equal(aliasURL)) + + By("marshalling preserving the type token") + out := Must(json.Marshal(spec)) + Expect(string(out)).To(ContainSubstring(fmt.Sprintf(`"type":%q`, typ))) + + By("decoding the marshalled form again") + redecoded := Must(inputs.DefaultInputTypeScheme.DecodeInputSpec(out, runtime.DefaultJSONEncoding)) + Expect(redecoded).To(BeAssignableToTypeOf(&wget.Spec{})) + Expect(redecoded.GetType()).To(Equal(typ)) + Expect(redecoded.(*wget.Spec).URL).To(Equal(aliasURL)) + }, + Entry("wget", "wget"), + Entry("wget/v1", "wget/v1"), + Entry("Wget", "Wget"), + Entry("Wget/v1", "Wget/v1"), + Entry("http", "http"), + Entry("http/v1", "http/v1"), + Entry("HTTP", "HTTP"), + Entry("HTTP/v1", "HTTP/v1"), + ) +}) 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..179779314c 100644 --- a/cmds/ocm/commands/ocmcmds/common/inputs/types/wget/cli.go +++ b/cmds/ocm/commands/ocmcmds/common/inputs/types/wget/cli.go @@ -6,8 +6,16 @@ import ( ) func ConfigHandler() flagsets.ConfigOptionTypeSetHandler { + return configHandler(TYPE) +} + +func HTTPConfigHandler() flagsets.ConfigOptionTypeSetHandler { + return configHandler(HTTP_TYPE) +} + +func configHandler(name string) flagsets.ConfigOptionTypeSetHandler { return flagsets.NewConfigOptionTypeSetHandler( - TYPE, AddConfig, + name, AddConfig, options.URLOption, options.MediaTypeOption, options.HTTPHeaderOption, diff --git a/cmds/ocm/commands/ocmcmds/common/inputs/types/wget/type.go b/cmds/ocm/commands/ocmcmds/common/inputs/types/wget/type.go index 6195b245c7..0ab7387009 100644 --- a/cmds/ocm/commands/ocmcmds/common/inputs/types/wget/type.go +++ b/cmds/ocm/commands/ocmcmds/common/inputs/types/wget/type.go @@ -13,17 +13,30 @@ const ( UPPER_TYPE_V1 = UPPER_TYPE + runtime.VersionSeparator + "v1" ) +// Alias type names for the wget input type. +const ( + HTTP_TYPE = "http" + HTTP_TYPE_V1 = HTTP_TYPE + runtime.VersionSeparator + "v1" + UPPER_HTTP_TYPE = "HTTP" + UPPER_HTTP_TYPE_V1 = UPPER_HTTP_TYPE + runtime.VersionSeparator + "v1" +) + func init() { inputs.DefaultInputTypeScheme.Register(inputs.NewInputType(TYPE, &Spec{}, usage, ConfigHandler())) inputs.DefaultInputTypeScheme.Register(inputs.NewInputType(TypeV1, &Spec{}, "", ConfigHandler())) inputs.DefaultInputTypeScheme.Register(inputs.NewInputType(UPPER_TYPE, &Spec{}, "", ConfigHandler())) inputs.DefaultInputTypeScheme.Register(inputs.NewInputType(UPPER_TYPE_V1, &Spec{}, "", ConfigHandler())) + + inputs.DefaultInputTypeScheme.Register(inputs.NewInputType(HTTP_TYPE, &Spec{}, "", HTTPConfigHandler())) + inputs.DefaultInputTypeScheme.Register(inputs.NewInputType(HTTP_TYPE_V1, &Spec{}, "", HTTPConfigHandler())) + inputs.DefaultInputTypeScheme.Register(inputs.NewInputType(UPPER_HTTP_TYPE, &Spec{}, "", HTTPConfigHandler())) + inputs.DefaultInputTypeScheme.Register(inputs.NewInputType(UPPER_HTTP_TYPE_V1, &Spec{}, "", HTTPConfigHandler())) } const usage = ` The url is the url pointing to the http endpoint from which a resource is downloaded. The mimeType can be used to specify the MIME type of the -resource. +resource. The input type can also be declared as http or HTTP. This blob type specification supports the following fields: - **url** *string* diff --git a/docs/reference/ocm_add_resource-configuration.md b/docs/reference/ocm_add_resource-configuration.md index df3b731be8..f9962f775d 100644 --- a/docs/reference/ocm_add_resource-configuration.md +++ b/docs/reference/ocm_add_resource-configuration.md @@ -590,7 +590,7 @@ lowercase types (e.g. helm). See the lowercase entry for full docum The url is the url pointing to the http endpoint from which a resource is downloaded. The mimeType can be used to specify the MIME type of the - resource. + resource. The input type can also be declared as http or HTTP. This blob type specification supports the following fields: - **url** *string* diff --git a/docs/reference/ocm_add_resources.md b/docs/reference/ocm_add_resources.md index 5ed27756b3..6881490e5e 100644 --- a/docs/reference/ocm_add_resources.md +++ b/docs/reference/ocm_add_resources.md @@ -602,7 +602,7 @@ lowercase types (e.g. helm). See the lowercase entry for full docum The url is the url pointing to the http endpoint from which a resource is downloaded. The mimeType can be used to specify the MIME type of the - resource. + resource. The input type can also be declared as http or HTTP. This blob type specification supports the following fields: - **url** *string* diff --git a/docs/reference/ocm_add_source-configuration.md b/docs/reference/ocm_add_source-configuration.md index 83639a08e5..55f4e5b091 100644 --- a/docs/reference/ocm_add_source-configuration.md +++ b/docs/reference/ocm_add_source-configuration.md @@ -590,7 +590,7 @@ lowercase types (e.g. helm). See the lowercase entry for full docum The url is the url pointing to the http endpoint from which a resource is downloaded. The mimeType can be used to specify the MIME type of the - resource. + resource. The input type can also be declared as http or HTTP. This blob type specification supports the following fields: - **url** *string* diff --git a/docs/reference/ocm_add_sources.md b/docs/reference/ocm_add_sources.md index 0996323c95..0d06e8f0ea 100644 --- a/docs/reference/ocm_add_sources.md +++ b/docs/reference/ocm_add_sources.md @@ -600,7 +600,7 @@ lowercase types (e.g. helm). See the lowercase entry for full docum The url is the url pointing to the http endpoint from which a resource is downloaded. The mimeType can be used to specify the MIME type of the - resource. + resource. The input type can also be declared as http or HTTP. This blob type specification supports the following fields: - **url** *string*