github.com/containers/libpod@v1.9.4-0.20220419124438-4284fd425507/libpod/image/docker_registry_options.go (about) 1 package image 2 3 import ( 4 "fmt" 5 6 "github.com/containers/image/v5/docker/reference" 7 "github.com/containers/image/v5/types" 8 9 podmanVersion "github.com/containers/libpod/version" 10 ) 11 12 // DockerRegistryOptions encapsulates settings that affect how we connect or 13 // authenticate to a remote registry. 14 type DockerRegistryOptions struct { 15 // DockerRegistryCreds is the user name and password to supply in case 16 // we need to pull an image from a registry, and it requires us to 17 // authenticate. 18 DockerRegistryCreds *types.DockerAuthConfig 19 // DockerCertPath is the location of a directory containing CA 20 // certificates which will be used to verify the registry's certificate 21 // (all files with names ending in ".crt"), and possibly client 22 // certificates and private keys (pairs of files with the same name, 23 // except for ".cert" and ".key" suffixes). 24 DockerCertPath string 25 // DockerInsecureSkipTLSVerify turns off verification of TLS 26 // certificates and allows connecting to registries without encryption 27 // - or forces it on even if registries.conf has the registry configured as insecure. 28 DockerInsecureSkipTLSVerify types.OptionalBool 29 // If not "", overrides the use of platform.GOOS when choosing an image or verifying OS match. 30 OSChoice string 31 // If not "", overrides the use of platform.GOARCH when choosing an image or verifying architecture match. 32 ArchitectureChoice string 33 } 34 35 // GetSystemContext constructs a new system context from a parent context. the values in the DockerRegistryOptions, and other parameters. 36 func (o DockerRegistryOptions) GetSystemContext(parent *types.SystemContext, additionalDockerArchiveTags []reference.NamedTagged) *types.SystemContext { 37 sc := &types.SystemContext{ 38 DockerAuthConfig: o.DockerRegistryCreds, 39 DockerCertPath: o.DockerCertPath, 40 DockerInsecureSkipTLSVerify: o.DockerInsecureSkipTLSVerify, 41 DockerArchiveAdditionalTags: additionalDockerArchiveTags, 42 OSChoice: o.OSChoice, 43 ArchitectureChoice: o.ArchitectureChoice, 44 } 45 if parent != nil { 46 sc.SignaturePolicyPath = parent.SignaturePolicyPath 47 sc.AuthFilePath = parent.AuthFilePath 48 sc.DirForceCompress = parent.DirForceCompress 49 sc.DockerRegistryUserAgent = parent.DockerRegistryUserAgent 50 sc.OSChoice = parent.OSChoice 51 sc.ArchitectureChoice = parent.ArchitectureChoice 52 } 53 return sc 54 } 55 56 // GetSystemContext Constructs a new containers/image/types.SystemContext{} struct from the given signaturePolicy path 57 func GetSystemContext(signaturePolicyPath, authFilePath string, forceCompress bool) *types.SystemContext { 58 sc := &types.SystemContext{} 59 if signaturePolicyPath != "" { 60 sc.SignaturePolicyPath = signaturePolicyPath 61 } 62 sc.AuthFilePath = authFilePath 63 sc.DirForceCompress = forceCompress 64 sc.DockerRegistryUserAgent = fmt.Sprintf("libpod/%s", podmanVersion.Version) 65 66 return sc 67 }