mirror of
https://github.com/containers/skopeo.git
synced 2025-07-16 07:47:38 +00:00
Migrate --*creds to imageOptions
This is one of the ugliest parts; we need an extra parameter to support the irregular screds/dcreds aliases. This was previously unsupported by (skopeo layers). Signed-off-by: Miloslav Trmač <mitr@redhat.com>
This commit is contained in:
parent
09a120a59b
commit
8b8afe0fda
@ -42,8 +42,8 @@ type copyOptions struct {
|
||||
}
|
||||
|
||||
func copyCmd(global *globalOptions) cli.Command {
|
||||
srcFlags, srcOpts := imageFlags(global, "src-")
|
||||
destFlags, destOpts := imageFlags(global, "dest-")
|
||||
srcFlags, srcOpts := imageFlags(global, "src-", "screds")
|
||||
destFlags, destOpts := imageFlags(global, "dest-", "dcreds")
|
||||
opts := copyOptions{global: global,
|
||||
srcImage: srcOpts,
|
||||
destImage: destOpts,
|
||||
@ -84,16 +84,6 @@ func copyCmd(global *globalOptions) cli.Command {
|
||||
Usage: "Sign the image using a GPG key with the specified `FINGERPRINT`",
|
||||
Destination: &opts.signByFingerprint,
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "src-creds, screds",
|
||||
Value: "",
|
||||
Usage: "Use `USERNAME[:PASSWORD]` for accessing the source registry",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "dest-creds, dcreds",
|
||||
Value: "",
|
||||
Usage: "Use `USERNAME[:PASSWORD]` for accessing the destination registry",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "src-cert-dir",
|
||||
Value: "",
|
||||
|
@ -16,7 +16,7 @@ type deleteOptions struct {
|
||||
}
|
||||
|
||||
func deleteCmd(global *globalOptions) cli.Command {
|
||||
imageFlags, imageOpts := imageFlags(global, "")
|
||||
imageFlags, imageOpts := imageFlags(global, "", "")
|
||||
opts := deleteOptions{
|
||||
global: global,
|
||||
image: imageOpts,
|
||||
@ -39,11 +39,6 @@ func deleteCmd(global *globalOptions) cli.Command {
|
||||
Name: "authfile",
|
||||
Usage: "path of the authentication file. Default is ${XDG_RUNTIME_DIR}/containers/auth.json",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "creds",
|
||||
Value: "",
|
||||
Usage: "Use `USERNAME[:PASSWORD]` for accessing the registry",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "cert-dir",
|
||||
Value: "",
|
||||
|
@ -36,7 +36,7 @@ type inspectOptions struct {
|
||||
}
|
||||
|
||||
func inspectCmd(global *globalOptions) cli.Command {
|
||||
imageFlags, imageOpts := imageFlags(global, "")
|
||||
imageFlags, imageOpts := imageFlags(global, "", "")
|
||||
opts := inspectOptions{
|
||||
global: global,
|
||||
image: imageOpts,
|
||||
@ -72,11 +72,6 @@ func inspectCmd(global *globalOptions) cli.Command {
|
||||
Usage: "output raw manifest",
|
||||
Destination: &opts.raw,
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "creds",
|
||||
Value: "",
|
||||
Usage: "Use `USERNAME[:PASSWORD]` for accessing the registry",
|
||||
},
|
||||
}, imageFlags...),
|
||||
Action: opts.run,
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ type layersOptions struct {
|
||||
}
|
||||
|
||||
func layersCmd(global *globalOptions) cli.Command {
|
||||
imageFlags, imageOpts := imageFlags(global, "")
|
||||
imageFlags, imageOpts := imageFlags(global, "", "")
|
||||
opts := layersOptions{
|
||||
global: global,
|
||||
image: imageOpts,
|
||||
|
@ -13,17 +13,32 @@ import (
|
||||
// imageOptions collects CLI flags which are the same across subcommands, but may be different for each image
|
||||
// (e.g. may differ between the source and destination of a copy)
|
||||
type imageOptions struct {
|
||||
global *globalOptions // May be shared across several imageOptions instances.
|
||||
flagPrefix string // FIXME: Drop this eventually.
|
||||
global *globalOptions // May be shared across several imageOptions instances.
|
||||
flagPrefix string // FIXME: Drop this eventually.
|
||||
credsOption optionalString // username[:password] for accessing a registry
|
||||
}
|
||||
|
||||
// imageFlags prepares a collection of CLI flags writing into imageOptions, and the managed imageOptions structure.
|
||||
func imageFlags(global *globalOptions, flagPrefix string) ([]cli.Flag, *imageOptions) {
|
||||
func imageFlags(global *globalOptions, flagPrefix, credsOptionAlias string) ([]cli.Flag, *imageOptions) {
|
||||
opts := imageOptions{
|
||||
global: global,
|
||||
flagPrefix: flagPrefix,
|
||||
}
|
||||
return []cli.Flag{}, &opts
|
||||
|
||||
// This is horribly ugly, but we need to support the old option forms of (skopeo copy) for compatibility.
|
||||
// Don't add any more cases like this.
|
||||
credsOptionExtra := ""
|
||||
if credsOptionAlias != "" {
|
||||
credsOptionExtra += "," + credsOptionAlias
|
||||
}
|
||||
|
||||
return []cli.Flag{
|
||||
cli.GenericFlag{
|
||||
Name: flagPrefix + "creds" + credsOptionExtra,
|
||||
Usage: "Use `USERNAME[:PASSWORD]` for accessing the registry",
|
||||
Value: newOptionalStringValue(&opts.credsOption),
|
||||
},
|
||||
}, &opts
|
||||
}
|
||||
|
||||
func contextFromImageOptions(c *cli.Context, opts *imageOptions) (*types.SystemContext, error) {
|
||||
@ -47,9 +62,9 @@ func contextFromImageOptions(c *cli.Context, opts *imageOptions) (*types.SystemC
|
||||
if c.IsSet(opts.flagPrefix + "tls-verify") {
|
||||
ctx.DockerInsecureSkipTLSVerify = types.NewOptionalBool(!c.BoolT(opts.flagPrefix + "tls-verify"))
|
||||
}
|
||||
if c.IsSet(opts.flagPrefix + "creds") {
|
||||
if opts.credsOption.present {
|
||||
var err error
|
||||
ctx.DockerAuthConfig, err = getDockerAuth(c.String(opts.flagPrefix + "creds"))
|
||||
ctx.DockerAuthConfig, err = getDockerAuth(opts.credsOption.value)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ func fakeContext(t *testing.T, cmdName string, flagPrefix string, globalFlags []
|
||||
cmd := app.Command(cmdName)
|
||||
require.NotNil(t, cmd)
|
||||
|
||||
imageFlags, imageOpts := imageFlags(globalOpts, flagPrefix)
|
||||
imageFlags, imageOpts := imageFlags(globalOpts, flagPrefix, "")
|
||||
appliedFlags := map[string]struct{}{}
|
||||
// Ugly: cmd.Flags includes imageFlags as well. For now, we need cmd.Flags to apply here
|
||||
// to be able to test the non-Destination: flags, but we must not apply the same flag name twice.
|
||||
|
Loading…
Reference in New Issue
Block a user