mirror of
https://github.com/containers/podman.git
synced 2025-06-25 03:52:15 +08:00
Merge pull request #15491 from marshall-lee/bindings-schema-ignore
Mark some of the option fields as ignored in pkg/bindings
This commit is contained in:
@ -282,9 +282,9 @@ func Search(ctx context.Context, term string, options *SearchOptions) ([]entitie
|
|||||||
}
|
}
|
||||||
params.Set("term", term)
|
params.Set("term", term)
|
||||||
|
|
||||||
// Note: we have to verify if skipped is false.
|
// SkipTLSVerify is special. It's not being serialized by ToParams()
|
||||||
|
// because we need to flip the boolean.
|
||||||
if options.SkipTLSVerify != nil {
|
if options.SkipTLSVerify != nil {
|
||||||
params.Del("SkipTLSVerify")
|
|
||||||
params.Set("tlsVerify", strconv.FormatBool(!options.GetSkipTLSVerify()))
|
params.Set("tlsVerify", strconv.FormatBool(!options.GetSkipTLSVerify()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,9 +35,9 @@ func Pull(ctx context.Context, rawImage string, options *PullOptions) ([]string,
|
|||||||
}
|
}
|
||||||
params.Set("reference", rawImage)
|
params.Set("reference", rawImage)
|
||||||
|
|
||||||
|
// SkipTLSVerify is special. It's not being serialized by ToParams()
|
||||||
|
// because we need to flip the boolean.
|
||||||
if options.SkipTLSVerify != nil {
|
if options.SkipTLSVerify != nil {
|
||||||
params.Del("SkipTLSVerify")
|
|
||||||
// Note: we have to verify if skipped is false.
|
|
||||||
params.Set("tlsVerify", strconv.FormatBool(!options.GetSkipTLSVerify()))
|
params.Set("tlsVerify", strconv.FormatBool(!options.GetSkipTLSVerify()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,10 +38,9 @@ func Push(ctx context.Context, source string, destination string, options *PushO
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// SkipTLSVerify is special. We need to delete the param added by
|
// SkipTLSVerify is special. It's not being serialized by ToParams()
|
||||||
// toparams and change the key and flip the bool
|
// because we need to flip the boolean.
|
||||||
if options.SkipTLSVerify != nil {
|
if options.SkipTLSVerify != nil {
|
||||||
params.Del("SkipTLSVerify")
|
|
||||||
params.Set("tlsVerify", strconv.FormatBool(!options.GetSkipTLSVerify()))
|
params.Set("tlsVerify", strconv.FormatBool(!options.GetSkipTLSVerify()))
|
||||||
}
|
}
|
||||||
params.Set("destination", destination)
|
params.Set("destination", destination)
|
||||||
|
@ -136,9 +136,9 @@ type PushOptions struct {
|
|||||||
// ProgressWriter is a writer where push progress are sent.
|
// ProgressWriter is a writer where push progress are sent.
|
||||||
// Since API handler for image push is quiet by default, WithQuiet(false) is necessary for
|
// Since API handler for image push is quiet by default, WithQuiet(false) is necessary for
|
||||||
// the writer to receive progress messages.
|
// the writer to receive progress messages.
|
||||||
ProgressWriter *io.Writer
|
ProgressWriter *io.Writer `schema:"-"`
|
||||||
// SkipTLSVerify to skip HTTPS and certificate verification.
|
// SkipTLSVerify to skip HTTPS and certificate verification.
|
||||||
SkipTLSVerify *bool
|
SkipTLSVerify *bool `schema:"-"`
|
||||||
// RemoveSignatures Discard any pre-existing signatures in the image.
|
// RemoveSignatures Discard any pre-existing signatures in the image.
|
||||||
RemoveSignatures *bool
|
RemoveSignatures *bool
|
||||||
// Username for authenticating against the registry.
|
// Username for authenticating against the registry.
|
||||||
@ -158,7 +158,7 @@ type SearchOptions struct {
|
|||||||
// Limit the number of results.
|
// Limit the number of results.
|
||||||
Limit *int
|
Limit *int
|
||||||
// SkipTLSVerify to skip HTTPS and certificate verification.
|
// SkipTLSVerify to skip HTTPS and certificate verification.
|
||||||
SkipTLSVerify *bool
|
SkipTLSVerify *bool `schema:"-"`
|
||||||
// ListTags search the available tags of the repository
|
// ListTags search the available tags of the repository
|
||||||
ListTags *bool
|
ListTags *bool
|
||||||
}
|
}
|
||||||
@ -183,12 +183,12 @@ type PullOptions struct {
|
|||||||
// Password for authenticating against the registry.
|
// Password for authenticating against the registry.
|
||||||
Password *string
|
Password *string
|
||||||
// ProgressWriter is a writer where pull progress are sent.
|
// ProgressWriter is a writer where pull progress are sent.
|
||||||
ProgressWriter *io.Writer
|
ProgressWriter *io.Writer `schema:"-"`
|
||||||
// Quiet can be specified to suppress pull progress when pulling. Ignored
|
// Quiet can be specified to suppress pull progress when pulling. Ignored
|
||||||
// for remote calls.
|
// for remote calls.
|
||||||
Quiet *bool
|
Quiet *bool
|
||||||
// SkipTLSVerify to skip HTTPS and certificate verification.
|
// SkipTLSVerify to skip HTTPS and certificate verification.
|
||||||
SkipTLSVerify *bool
|
SkipTLSVerify *bool `schema:"-"`
|
||||||
// Username for authenticating against the registry.
|
// Username for authenticating against the registry.
|
||||||
Username *string
|
Username *string
|
||||||
// Variant will overwrite the local variant for image pulls.
|
// Variant will overwrite the local variant for image pulls.
|
||||||
|
@ -74,6 +74,9 @@ func ToParams(o interface{}) (url.Values, error) {
|
|||||||
}
|
}
|
||||||
paramName := fieldName
|
paramName := fieldName
|
||||||
if pn, ok := sType.Field(i).Tag.Lookup("schema"); ok {
|
if pn, ok := sType.Field(i).Tag.Lookup("schema"); ok {
|
||||||
|
if pn == "-" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
paramName = pn
|
paramName = pn
|
||||||
}
|
}
|
||||||
switch {
|
switch {
|
||||||
|
@ -40,8 +40,10 @@ func PlayWithBody(ctx context.Context, body io.Reader, options *PlayOptions) (*e
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
// SkipTLSVerify is special. It's not being serialized by ToParams()
|
||||||
|
// because we need to flip the boolean.
|
||||||
if options.SkipTLSVerify != nil {
|
if options.SkipTLSVerify != nil {
|
||||||
params.Set("tlsVerify", strconv.FormatBool(options.GetSkipTLSVerify()))
|
params.Set("tlsVerify", strconv.FormatBool(!options.GetSkipTLSVerify()))
|
||||||
}
|
}
|
||||||
if options.Start != nil {
|
if options.Start != nil {
|
||||||
params.Set("start", strconv.FormatBool(options.GetStart()))
|
params.Set("start", strconv.FormatBool(options.GetStart()))
|
||||||
|
@ -27,7 +27,7 @@ type PlayOptions struct {
|
|||||||
SignaturePolicy *string
|
SignaturePolicy *string
|
||||||
// SkipTLSVerify - skip https and certificate validation when
|
// SkipTLSVerify - skip https and certificate validation when
|
||||||
// contacting container registries.
|
// contacting container registries.
|
||||||
SkipTLSVerify *bool
|
SkipTLSVerify *bool `schema:"-"`
|
||||||
// SeccompProfileRoot - path to a directory containing seccomp
|
// SeccompProfileRoot - path to a directory containing seccomp
|
||||||
// profiles.
|
// profiles.
|
||||||
SeccompProfileRoot *string
|
SeccompProfileRoot *string
|
||||||
|
@ -165,10 +165,9 @@ func Push(ctx context.Context, name, destination string, options *images.PushOpt
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
// SkipTLSVerify is special. We need to delete the param added by
|
// SkipTLSVerify is special. It's not being serialized by ToParams()
|
||||||
// ToParams() and change the key and flip the bool
|
// because we need to flip the boolean.
|
||||||
if options.SkipTLSVerify != nil {
|
if options.SkipTLSVerify != nil {
|
||||||
params.Del("SkipTLSVerify")
|
|
||||||
params.Set("tlsVerify", strconv.FormatBool(!options.GetSkipTLSVerify()))
|
params.Set("tlsVerify", strconv.FormatBool(!options.GetSkipTLSVerify()))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -246,10 +245,9 @@ func Modify(ctx context.Context, name string, images []string, options *ModifyOp
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
// SkipTLSVerify is special. We need to delete the param added by
|
// SkipTLSVerify is special. It's not being serialized by ToParams()
|
||||||
// ToParams() and change the key and flip the bool
|
// because we need to flip the boolean.
|
||||||
if options.SkipTLSVerify != nil {
|
if options.SkipTLSVerify != nil {
|
||||||
params.Del("SkipTLSVerify")
|
|
||||||
params.Set("tlsVerify", strconv.FormatBool(!options.GetSkipTLSVerify()))
|
params.Set("tlsVerify", strconv.FormatBool(!options.GetSkipTLSVerify()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ type AddOptions struct {
|
|||||||
Authfile *string
|
Authfile *string
|
||||||
Password *string
|
Password *string
|
||||||
Username *string
|
Username *string
|
||||||
SkipTLSVerify *bool
|
SkipTLSVerify *bool `schema:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
//go:generate go run ../generator/generator.go RemoveOptions
|
//go:generate go run ../generator/generator.go RemoveOptions
|
||||||
@ -60,5 +60,5 @@ type ModifyOptions struct {
|
|||||||
Authfile *string
|
Authfile *string
|
||||||
Password *string
|
Password *string
|
||||||
Username *string
|
Username *string
|
||||||
SkipTLSVerify *bool
|
SkipTLSVerify *bool `schema:"-"`
|
||||||
}
|
}
|
||||||
|
66
pkg/bindings/test/types_test.go
Normal file
66
pkg/bindings/test/types_test.go
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
package bindings_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
|
||||||
|
"github.com/containers/podman/v4/pkg/bindings/images"
|
||||||
|
"github.com/containers/podman/v4/pkg/bindings/kube"
|
||||||
|
"github.com/containers/podman/v4/pkg/bindings/manifests"
|
||||||
|
. "github.com/onsi/ginkgo"
|
||||||
|
. "github.com/onsi/gomega"
|
||||||
|
)
|
||||||
|
|
||||||
|
var _ = Describe("Binding types", func() {
|
||||||
|
It("serialize image pull options", func() {
|
||||||
|
var writer bytes.Buffer
|
||||||
|
opts := new(images.PullOptions).WithOS("foo").WithProgressWriter(&writer).WithSkipTLSVerify(true)
|
||||||
|
params, err := opts.ToParams()
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
Expect(params.Get("os")).To(Equal("foo"))
|
||||||
|
Expect(params.Has("progresswriter")).To(BeFalse())
|
||||||
|
Expect(params.Has("skiptlsverify")).To(BeFalse())
|
||||||
|
})
|
||||||
|
|
||||||
|
It("serialize image push options", func() {
|
||||||
|
var writer bytes.Buffer
|
||||||
|
opts := new(images.PushOptions).WithAll(true).WithProgressWriter(&writer).WithSkipTLSVerify(true)
|
||||||
|
params, err := opts.ToParams()
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
Expect(params.Get("all")).To(Equal("true"))
|
||||||
|
Expect(params.Has("progresswriter")).To(BeFalse())
|
||||||
|
Expect(params.Has("skiptlsverify")).To(BeFalse())
|
||||||
|
})
|
||||||
|
|
||||||
|
It("serialize image search options", func() {
|
||||||
|
opts := new(images.SearchOptions).WithLimit(123).WithSkipTLSVerify(true)
|
||||||
|
params, err := opts.ToParams()
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
Expect(params.Get("limit")).To(Equal("123"))
|
||||||
|
Expect(params.Has("skiptlsverify")).To(BeFalse())
|
||||||
|
})
|
||||||
|
|
||||||
|
It("serialize manifest modify options", func() {
|
||||||
|
opts := new(manifests.ModifyOptions).WithOS("foo").WithSkipTLSVerify(true)
|
||||||
|
params, err := opts.ToParams()
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
Expect(params.Get("os")).To(Equal("foo"))
|
||||||
|
Expect(params.Has("skiptlsverify")).To(BeFalse())
|
||||||
|
})
|
||||||
|
|
||||||
|
It("serialize manifest add options", func() {
|
||||||
|
opts := new(manifests.AddOptions).WithAll(true).WithOS("foo").WithSkipTLSVerify(true)
|
||||||
|
params, err := opts.ToParams()
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
Expect(params.Get("all")).To(Equal("true"))
|
||||||
|
Expect(params.Get("os")).To(Equal("foo"))
|
||||||
|
Expect(params.Has("skiptlsverify")).To(BeFalse())
|
||||||
|
})
|
||||||
|
|
||||||
|
It("serialize kube play options", func() {
|
||||||
|
opts := new(kube.PlayOptions).WithQuiet(true).WithSkipTLSVerify(true)
|
||||||
|
params, err := opts.ToParams()
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
Expect(params.Get("quiet")).To(Equal("true"))
|
||||||
|
Expect(params.Has("skiptlsverify")).To(BeFalse())
|
||||||
|
})
|
||||||
|
})
|
Reference in New Issue
Block a user