mirror of
https://github.com/containers/skopeo.git
synced 2025-07-17 08:11:50 +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 {
|
func copyCmd(global *globalOptions) cli.Command {
|
||||||
srcFlags, srcOpts := imageFlags(global, "src-")
|
srcFlags, srcOpts := imageFlags(global, "src-", "screds")
|
||||||
destFlags, destOpts := imageFlags(global, "dest-")
|
destFlags, destOpts := imageFlags(global, "dest-", "dcreds")
|
||||||
opts := copyOptions{global: global,
|
opts := copyOptions{global: global,
|
||||||
srcImage: srcOpts,
|
srcImage: srcOpts,
|
||||||
destImage: destOpts,
|
destImage: destOpts,
|
||||||
@ -84,16 +84,6 @@ func copyCmd(global *globalOptions) cli.Command {
|
|||||||
Usage: "Sign the image using a GPG key with the specified `FINGERPRINT`",
|
Usage: "Sign the image using a GPG key with the specified `FINGERPRINT`",
|
||||||
Destination: &opts.signByFingerprint,
|
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{
|
cli.StringFlag{
|
||||||
Name: "src-cert-dir",
|
Name: "src-cert-dir",
|
||||||
Value: "",
|
Value: "",
|
||||||
|
@ -16,7 +16,7 @@ type deleteOptions struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func deleteCmd(global *globalOptions) cli.Command {
|
func deleteCmd(global *globalOptions) cli.Command {
|
||||||
imageFlags, imageOpts := imageFlags(global, "")
|
imageFlags, imageOpts := imageFlags(global, "", "")
|
||||||
opts := deleteOptions{
|
opts := deleteOptions{
|
||||||
global: global,
|
global: global,
|
||||||
image: imageOpts,
|
image: imageOpts,
|
||||||
@ -39,11 +39,6 @@ func deleteCmd(global *globalOptions) cli.Command {
|
|||||||
Name: "authfile",
|
Name: "authfile",
|
||||||
Usage: "path of the authentication file. Default is ${XDG_RUNTIME_DIR}/containers/auth.json",
|
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{
|
cli.StringFlag{
|
||||||
Name: "cert-dir",
|
Name: "cert-dir",
|
||||||
Value: "",
|
Value: "",
|
||||||
|
@ -36,7 +36,7 @@ type inspectOptions struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func inspectCmd(global *globalOptions) cli.Command {
|
func inspectCmd(global *globalOptions) cli.Command {
|
||||||
imageFlags, imageOpts := imageFlags(global, "")
|
imageFlags, imageOpts := imageFlags(global, "", "")
|
||||||
opts := inspectOptions{
|
opts := inspectOptions{
|
||||||
global: global,
|
global: global,
|
||||||
image: imageOpts,
|
image: imageOpts,
|
||||||
@ -72,11 +72,6 @@ func inspectCmd(global *globalOptions) cli.Command {
|
|||||||
Usage: "output raw manifest",
|
Usage: "output raw manifest",
|
||||||
Destination: &opts.raw,
|
Destination: &opts.raw,
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
|
||||||
Name: "creds",
|
|
||||||
Value: "",
|
|
||||||
Usage: "Use `USERNAME[:PASSWORD]` for accessing the registry",
|
|
||||||
},
|
|
||||||
}, imageFlags...),
|
}, imageFlags...),
|
||||||
Action: opts.run,
|
Action: opts.run,
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ type layersOptions struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func layersCmd(global *globalOptions) cli.Command {
|
func layersCmd(global *globalOptions) cli.Command {
|
||||||
imageFlags, imageOpts := imageFlags(global, "")
|
imageFlags, imageOpts := imageFlags(global, "", "")
|
||||||
opts := layersOptions{
|
opts := layersOptions{
|
||||||
global: global,
|
global: global,
|
||||||
image: imageOpts,
|
image: imageOpts,
|
||||||
|
@ -13,17 +13,32 @@ import (
|
|||||||
// imageOptions collects CLI flags which are the same across subcommands, but may be different for each image
|
// 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)
|
// (e.g. may differ between the source and destination of a copy)
|
||||||
type imageOptions struct {
|
type imageOptions struct {
|
||||||
global *globalOptions // May be shared across several imageOptions instances.
|
global *globalOptions // May be shared across several imageOptions instances.
|
||||||
flagPrefix string // FIXME: Drop this eventually.
|
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.
|
// 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{
|
opts := imageOptions{
|
||||||
global: global,
|
global: global,
|
||||||
flagPrefix: flagPrefix,
|
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) {
|
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") {
|
if c.IsSet(opts.flagPrefix + "tls-verify") {
|
||||||
ctx.DockerInsecureSkipTLSVerify = types.NewOptionalBool(!c.BoolT(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
|
var err error
|
||||||
ctx.DockerAuthConfig, err = getDockerAuth(c.String(opts.flagPrefix + "creds"))
|
ctx.DockerAuthConfig, err = getDockerAuth(opts.credsOption.value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ func fakeContext(t *testing.T, cmdName string, flagPrefix string, globalFlags []
|
|||||||
cmd := app.Command(cmdName)
|
cmd := app.Command(cmdName)
|
||||||
require.NotNil(t, cmd)
|
require.NotNil(t, cmd)
|
||||||
|
|
||||||
imageFlags, imageOpts := imageFlags(globalOpts, flagPrefix)
|
imageFlags, imageOpts := imageFlags(globalOpts, flagPrefix, "")
|
||||||
appliedFlags := map[string]struct{}{}
|
appliedFlags := map[string]struct{}{}
|
||||||
// Ugly: cmd.Flags includes imageFlags as well. For now, we need cmd.Flags to apply here
|
// 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.
|
// 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