Add a *types.SystemContext parameter to getCopyOptions and DRO.GetSystemContext

All callers of getCopyOptions also call GetSystemContext with the same three parameters;
we will want to simplify this by passing the first SystemContext to getCopyOptions,
which can then inherit this data instead of so many parameters everywhere.

For now, just add a *types.SystemContext parameter without using it.

Should not change behavior (but does not add unit tests).

Signed-off-by: Miloslav Trmač <mitr@redhat.com>

Closes: #1176
Approved by: rhatdan
This commit is contained in:
Miloslav Trmač
2018-07-28 07:22:12 +02:00
committed by Atomic Bot
parent 2d5410d349
commit 1054b8d2c5
4 changed files with 9 additions and 9 deletions

View File

@ -23,9 +23,9 @@ type DockerRegistryOptions struct {
DockerInsecureSkipTLSVerify bool
}
// GetSystemContext constructs a new system context from the given signaturePolicy path and the
// GetSystemContext constructs a new system context from a parent context, the given signaturePolicy path, and the
// values in the DockerRegistryOptions
func (o DockerRegistryOptions) GetSystemContext(signaturePolicyPath, authFile string, forceCompress bool, additionalDockerArchiveTags []reference.NamedTagged) *types.SystemContext {
func (o DockerRegistryOptions) GetSystemContext(parent *types.SystemContext, signaturePolicyPath, authFile string, forceCompress bool, additionalDockerArchiveTags []reference.NamedTagged) *types.SystemContext {
sc := &types.SystemContext{
SignaturePolicyPath: signaturePolicyPath,
DockerAuthConfig: o.DockerRegistryCreds,

View File

@ -551,7 +551,7 @@ func (i *Image) PushImageToReference(ctx context.Context, dest types.ImageRefere
if err != nil {
return err
}
copyOptions := getCopyOptions(writer, signaturePolicyPath, nil, dockerRegistryOptions, signingOptions, authFile, manifestMIMEType, forceCompress, additionalDockerArchiveTags)
copyOptions := getCopyOptions(sc, writer, signaturePolicyPath, nil, dockerRegistryOptions, signingOptions, authFile, manifestMIMEType, forceCompress, additionalDockerArchiveTags)
if dest.Transport().Name() == DockerTransport {
imgRef := dest.DockerReference()
if imgRef == nil { // This should never happen; such references cant be created.
@ -906,7 +906,7 @@ func (ir *Runtime) Import(ctx context.Context, path, reference string, writer io
return nil, err
}
defer policyContext.Destroy()
copyOptions := getCopyOptions(writer, "", nil, nil, signingOptions, "", "", false, nil)
copyOptions := getCopyOptions(sc, writer, "", nil, nil, signingOptions, "", "", false, nil)
dest, err := is.Transport.ParseStoreReference(ir.store, reference)
if err != nil {
errors.Wrapf(err, "error getting image reference for %q", reference)

View File

@ -232,7 +232,7 @@ func (ir *Runtime) pullImage(ctx context.Context, inputName string, writer io.Wr
}
var images []string
for _, imageInfo := range goal.refPairs {
copyOptions := getCopyOptions(writer, signaturePolicyPath, dockerOptions, nil, signingOptions, authfile, "", false, nil)
copyOptions := getCopyOptions(sc, writer, signaturePolicyPath, dockerOptions, nil, signingOptions, authfile, "", false, nil)
if imageInfo.srcRef.Transport().Name() == DockerTransport {
imgRef := imageInfo.srcRef.DockerReference()
if imgRef == nil { // This should never happen; such references cant be created.

View File

@ -42,16 +42,16 @@ func findImageInRepotags(search imageParts, images []*Image) (*storage.Image, er
return results[0], nil
}
// getCopyOptions constructs a new containers/image/copy.Options{} struct from the given parameters
func getCopyOptions(reportWriter io.Writer, signaturePolicyPath string, srcDockerRegistry, destDockerRegistry *DockerRegistryOptions, signing SigningOptions, authFile, manifestType string, forceCompress bool, additionalDockerArchiveTags []reference.NamedTagged) *cp.Options {
// getCopyOptions constructs a new containers/image/copy.Options{} struct from the given parameters, inheriting some from sc.
func getCopyOptions(sc *types.SystemContext, reportWriter io.Writer, signaturePolicyPath string, srcDockerRegistry, destDockerRegistry *DockerRegistryOptions, signing SigningOptions, authFile, manifestType string, forceCompress bool, additionalDockerArchiveTags []reference.NamedTagged) *cp.Options {
if srcDockerRegistry == nil {
srcDockerRegistry = &DockerRegistryOptions{}
}
if destDockerRegistry == nil {
destDockerRegistry = &DockerRegistryOptions{}
}
srcContext := srcDockerRegistry.GetSystemContext(signaturePolicyPath, authFile, forceCompress, additionalDockerArchiveTags)
destContext := destDockerRegistry.GetSystemContext(signaturePolicyPath, authFile, forceCompress, additionalDockerArchiveTags)
srcContext := srcDockerRegistry.GetSystemContext(sc, signaturePolicyPath, authFile, forceCompress, additionalDockerArchiveTags)
destContext := destDockerRegistry.GetSystemContext(sc, signaturePolicyPath, authFile, forceCompress, additionalDockerArchiveTags)
return &cp.Options{
RemoveSignatures: signing.RemoveSignatures,
SignBy: signing.SignBy,