dockerCertDir returns a path to a directory to be consumed by tlsclientconfig.SetupCertificates() depending on ctx and hostPort.
(sys *types.SystemContext, hostPort string)
| 147 | |
| 148 | // dockerCertDir returns a path to a directory to be consumed by tlsclientconfig.SetupCertificates() depending on ctx and hostPort. |
| 149 | func dockerCertDir(sys *types.SystemContext, hostPort string) (string, error) { |
| 150 | if sys != nil && sys.DockerCertPath != "" { |
| 151 | return sys.DockerCertPath, nil |
| 152 | } |
| 153 | if sys != nil && sys.DockerPerHostCertDirPath != "" { |
| 154 | return filepath.Join(sys.DockerPerHostCertDirPath, hostPort), nil |
| 155 | } |
| 156 | |
| 157 | var ( |
| 158 | hostCertDir string |
| 159 | fullCertDirPath string |
| 160 | ) |
| 161 | |
| 162 | for _, perHostCertDir := range append([]certPath{{path: filepath.Join(homedir.Get(), homeCertDir), absolute: false}}, perHostCertDirs...) { |
| 163 | if sys != nil && sys.RootForImplicitAbsolutePaths != "" && perHostCertDir.absolute { |
| 164 | hostCertDir = filepath.Join(sys.RootForImplicitAbsolutePaths, perHostCertDir.path) |
| 165 | } else { |
| 166 | hostCertDir = perHostCertDir.path |
| 167 | } |
| 168 | |
| 169 | fullCertDirPath = filepath.Join(hostCertDir, hostPort) |
| 170 | err := fileutils.Exists(fullCertDirPath) |
| 171 | if err == nil { |
| 172 | break |
| 173 | } |
| 174 | if os.IsNotExist(err) { |
| 175 | continue |
| 176 | } |
| 177 | if os.IsPermission(err) { |
| 178 | logrus.Debugf("error accessing certs directory due to permissions: %v", err) |
| 179 | continue |
| 180 | } |
| 181 | return "", err |
| 182 | } |
| 183 | return fullCertDirPath, nil |
| 184 | } |
| 185 | |
| 186 | // newDockerClientFromRef returns a new dockerClient instance for refHostname (a host a specified in the Docker image reference, not canonicalized to dockerRegistry) |
| 187 | // “write” specifies whether the client will be used for "write" access (in particular passed to lookaside.go:toplevelFromSection) |
searching dependent graphs…