mirror of
https://github.com/containers/skopeo.git
synced 2025-08-10 10:52:30 +00:00
Temporarily add flagPrefix to imageOptions
We don't want to worry about mismatch of the flagPrefix value between imageFlags() and contextFromImageOptions(). For now, record it in imageOptions; eventually we will stop using it in contextFromImageOptions and remove it again. Signed-off-by: Miloslav Trmač <mitr@redhat.com>
This commit is contained in:
parent
c769c7789e
commit
09a120a59b
@ -18,12 +18,12 @@ import (
|
|||||||
|
|
||||||
// contextsFromCopyOptions returns source and destionation types.SystemContext depending on c.
|
// contextsFromCopyOptions returns source and destionation types.SystemContext depending on c.
|
||||||
func contextsFromCopyOptions(c *cli.Context, opts *copyOptions) (*types.SystemContext, *types.SystemContext, error) {
|
func contextsFromCopyOptions(c *cli.Context, opts *copyOptions) (*types.SystemContext, *types.SystemContext, error) {
|
||||||
sourceCtx, err := contextFromImageOptions(c, opts.srcImage, "src-")
|
sourceCtx, err := contextFromImageOptions(c, opts.srcImage)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
destinationCtx, err := contextFromImageOptions(c, opts.destImage, "dest-")
|
destinationCtx, err := contextFromImageOptions(c, opts.destImage)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,7 @@ func (opts *deleteOptions) run(c *cli.Context) error {
|
|||||||
return fmt.Errorf("Invalid source name %s: %v", c.Args()[0], err)
|
return fmt.Errorf("Invalid source name %s: %v", c.Args()[0], err)
|
||||||
}
|
}
|
||||||
|
|
||||||
sys, err := contextFromImageOptions(c, opts.image, "")
|
sys, err := contextFromImageOptions(c, opts.image)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -132,7 +132,7 @@ func (opts *inspectOptions) run(c *cli.Context) (retErr error) {
|
|||||||
outputData.Name = dockerRef.Name()
|
outputData.Name = dockerRef.Name()
|
||||||
}
|
}
|
||||||
if img.Reference().Transport() == docker.Transport {
|
if img.Reference().Transport() == docker.Transport {
|
||||||
sys, err := contextFromImageOptions(c, opts.image, "")
|
sys, err := contextFromImageOptions(c, opts.image)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ func (opts *layersOptions) run(c *cli.Context) (retErr error) {
|
|||||||
ctx, cancel := opts.global.commandTimeoutContext()
|
ctx, cancel := opts.global.commandTimeoutContext()
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
sys, err := contextFromImageOptions(c, opts.image, "")
|
sys, err := contextFromImageOptions(c, opts.image)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -13,39 +13,43 @@ 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.
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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 string) ([]cli.Flag, *imageOptions) {
|
||||||
opts := imageOptions{global: global}
|
opts := imageOptions{
|
||||||
|
global: global,
|
||||||
|
flagPrefix: flagPrefix,
|
||||||
|
}
|
||||||
return []cli.Flag{}, &opts
|
return []cli.Flag{}, &opts
|
||||||
}
|
}
|
||||||
|
|
||||||
func contextFromImageOptions(c *cli.Context, opts *imageOptions, flagPrefix string) (*types.SystemContext, error) {
|
func contextFromImageOptions(c *cli.Context, opts *imageOptions) (*types.SystemContext, error) {
|
||||||
ctx := &types.SystemContext{
|
ctx := &types.SystemContext{
|
||||||
RegistriesDirPath: opts.global.registriesDirPath,
|
RegistriesDirPath: opts.global.registriesDirPath,
|
||||||
ArchitectureChoice: opts.global.overrideArch,
|
ArchitectureChoice: opts.global.overrideArch,
|
||||||
OSChoice: opts.global.overrideOS,
|
OSChoice: opts.global.overrideOS,
|
||||||
DockerCertPath: c.String(flagPrefix + "cert-dir"),
|
DockerCertPath: c.String(opts.flagPrefix + "cert-dir"),
|
||||||
OSTreeTmpDirPath: c.String(flagPrefix + "ostree-tmp-dir"),
|
OSTreeTmpDirPath: c.String(opts.flagPrefix + "ostree-tmp-dir"),
|
||||||
OCISharedBlobDirPath: c.String(flagPrefix + "shared-blob-dir"),
|
OCISharedBlobDirPath: c.String(opts.flagPrefix + "shared-blob-dir"),
|
||||||
DirForceCompress: c.Bool(flagPrefix + "compress"),
|
DirForceCompress: c.Bool(opts.flagPrefix + "compress"),
|
||||||
AuthFilePath: c.String("authfile"),
|
AuthFilePath: c.String("authfile"),
|
||||||
DockerDaemonHost: c.String(flagPrefix + "daemon-host"),
|
DockerDaemonHost: c.String(opts.flagPrefix + "daemon-host"),
|
||||||
DockerDaemonCertPath: c.String(flagPrefix + "cert-dir"),
|
DockerDaemonCertPath: c.String(opts.flagPrefix + "cert-dir"),
|
||||||
DockerDaemonInsecureSkipTLSVerify: !c.BoolT(flagPrefix + "tls-verify"),
|
DockerDaemonInsecureSkipTLSVerify: !c.BoolT(opts.flagPrefix + "tls-verify"),
|
||||||
}
|
}
|
||||||
// DEPRECATED: We support this for backward compatibility, but override it if a per-image flag is provided.
|
// DEPRECATED: We support this for backward compatibility, but override it if a per-image flag is provided.
|
||||||
if opts.global.tlsVerify.present {
|
if opts.global.tlsVerify.present {
|
||||||
ctx.DockerInsecureSkipTLSVerify = types.NewOptionalBool(!opts.global.tlsVerify.value)
|
ctx.DockerInsecureSkipTLSVerify = types.NewOptionalBool(!opts.global.tlsVerify.value)
|
||||||
}
|
}
|
||||||
if c.IsSet(flagPrefix + "tls-verify") {
|
if c.IsSet(opts.flagPrefix + "tls-verify") {
|
||||||
ctx.DockerInsecureSkipTLSVerify = types.NewOptionalBool(!c.BoolT(flagPrefix + "tls-verify"))
|
ctx.DockerInsecureSkipTLSVerify = types.NewOptionalBool(!c.BoolT(opts.flagPrefix + "tls-verify"))
|
||||||
}
|
}
|
||||||
if c.IsSet(flagPrefix + "creds") {
|
if c.IsSet(opts.flagPrefix + "creds") {
|
||||||
var err error
|
var err error
|
||||||
ctx.DockerAuthConfig, err = getDockerAuth(c.String(flagPrefix + "creds"))
|
ctx.DockerAuthConfig, err = getDockerAuth(c.String(opts.flagPrefix + "creds"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -86,7 +90,7 @@ func parseImage(ctx context.Context, c *cli.Context, opts *imageOptions) (types.
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
sys, err := contextFromImageOptions(c, opts, "")
|
sys, err := contextFromImageOptions(c, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -100,7 +104,7 @@ func parseImageSource(ctx context.Context, c *cli.Context, opts *imageOptions, n
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
sys, err := contextFromImageOptions(c, opts, "")
|
sys, err := contextFromImageOptions(c, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ func TestContextFromImageOptions(t *testing.T) {
|
|||||||
|
|
||||||
// Default state
|
// Default state
|
||||||
c, opts := fakeContext(t, "copy", "dest-", []string{}, []string{})
|
c, opts := fakeContext(t, "copy", "dest-", []string{}, []string{})
|
||||||
res, err := contextFromImageOptions(c, opts, "dest-")
|
res, err := contextFromImageOptions(c, opts)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, &types.SystemContext{}, res)
|
assert.Equal(t, &types.SystemContext{}, res)
|
||||||
|
|
||||||
@ -68,7 +68,7 @@ func TestContextFromImageOptions(t *testing.T) {
|
|||||||
c, opts = fakeContext(t, "copy", "dest-", []string{}, []string{
|
c, opts = fakeContext(t, "copy", "dest-", []string{}, []string{
|
||||||
"--dest-compress=false",
|
"--dest-compress=false",
|
||||||
})
|
})
|
||||||
res, err = contextFromImageOptions(c, opts, "dest-")
|
res, err = contextFromImageOptions(c, opts)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, &types.SystemContext{}, res)
|
assert.Equal(t, &types.SystemContext{}, res)
|
||||||
|
|
||||||
@ -87,7 +87,7 @@ func TestContextFromImageOptions(t *testing.T) {
|
|||||||
"--dest-tls-verify=false",
|
"--dest-tls-verify=false",
|
||||||
"--dest-creds", "creds-user:creds-password",
|
"--dest-creds", "creds-user:creds-password",
|
||||||
})
|
})
|
||||||
res, err = contextFromImageOptions(c, opts, "dest-")
|
res, err = contextFromImageOptions(c, opts)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, &types.SystemContext{
|
assert.Equal(t, &types.SystemContext{
|
||||||
RegistriesDirPath: "/srv/registries.d",
|
RegistriesDirPath: "/srv/registries.d",
|
||||||
@ -130,7 +130,7 @@ func TestContextFromImageOptions(t *testing.T) {
|
|||||||
cmdFlags = append(cmdFlags, "--dest-tls-verify="+c.cmd)
|
cmdFlags = append(cmdFlags, "--dest-tls-verify="+c.cmd)
|
||||||
}
|
}
|
||||||
ctx, opts := fakeContext(t, "copy", "dest-", globalFlags, cmdFlags)
|
ctx, opts := fakeContext(t, "copy", "dest-", globalFlags, cmdFlags)
|
||||||
res, err = contextFromImageOptions(ctx, opts, "dest-")
|
res, err = contextFromImageOptions(ctx, opts)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, c.expectedDocker, res.DockerInsecureSkipTLSVerify, "%#v", c)
|
assert.Equal(t, c.expectedDocker, res.DockerInsecureSkipTLSVerify, "%#v", c)
|
||||||
assert.Equal(t, c.expectedDockerDaemon, res.DockerDaemonInsecureSkipTLSVerify, "%#v", c)
|
assert.Equal(t, c.expectedDockerDaemon, res.DockerDaemonInsecureSkipTLSVerify, "%#v", c)
|
||||||
@ -138,6 +138,6 @@ func TestContextFromImageOptions(t *testing.T) {
|
|||||||
|
|
||||||
// Invalid option values
|
// Invalid option values
|
||||||
c, opts = fakeContext(t, "copy", "dest-", []string{}, []string{"--dest-creds", ""})
|
c, opts = fakeContext(t, "copy", "dest-", []string{}, []string{"--dest-creds", ""})
|
||||||
_, err = contextFromImageOptions(c, opts, "dest-")
|
_, err = contextFromImageOptions(c, opts)
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user