From 831b00303f1979dda6ed66980fc32a65f9229768 Mon Sep 17 00:00:00 2001 From: John Howard Date: Tue, 4 Aug 2015 16:30:00 -0700 Subject: [PATCH] Windows: Fix certificate directory for registry Signed-off-by: John Howard --- registry/config.go | 20 ++++++++++++++++++++ registry/config_unix.go | 19 +++++++++++++++++++ registry/config_windows.go | 25 +++++++++++++++++++++++++ registry/consts.go | 24 ------------------------ registry/consts_unix.go | 6 ------ registry/consts_windows.go | 10 ---------- registry/registry.go | 2 +- 7 files changed, 65 insertions(+), 41 deletions(-) create mode 100644 registry/config_unix.go create mode 100644 registry/config_windows.go delete mode 100644 registry/consts.go delete mode 100644 registry/consts_unix.go delete mode 100644 registry/consts_windows.go diff --git a/registry/config.go b/registry/config.go index dc1ee899ba..678a330e88 100644 --- a/registry/config.go +++ b/registry/config.go @@ -20,6 +20,26 @@ type Options struct { InsecureRegistries opts.ListOpts } +const ( + // DefaultNamespace is the default namespace + DefaultNamespace = "docker.io" + // DefaultRegistryVersionHeader is the name of the default HTTP header + // that carries Registry version info + DefaultRegistryVersionHeader = "Docker-Distribution-Api-Version" + // DefaultV1Registry is the URI of the default v1 registry + DefaultV1Registry = "https://index.docker.io" + + // IndexServer is the v1 registry server used for user auth + account creation + IndexServer = DefaultV1Registry + "/v1/" + // IndexName is the name of the index + IndexName = "docker.io" + + // NotaryServer is the endpoint serving the Notary trust server + NotaryServer = "https://notary.docker.io" + + // IndexServer = "https://registry-stage.hub.docker.com/v1/" +) + var ( // ErrInvalidRepositoryName is an error returned if the repository name did // not have the correct form diff --git a/registry/config_unix.go b/registry/config_unix.go new file mode 100644 index 0000000000..908ca2f6f4 --- /dev/null +++ b/registry/config_unix.go @@ -0,0 +1,19 @@ +// +build !windows + +package registry + +const ( + // DefaultV2Registry is the URI of the default v2 registry + DefaultV2Registry = "https://registry-1.docker.io" + + // CertsDir is the directory where certificates are stored + CertsDir = "/etc/docker/certs.d" +) + +// cleanPath is used to ensure that a directory name is valid on the target +// platform. It will be passed in something *similar* to a URL such as +// https:/index.docker.io/v1. Not all platforms support directory names +// which contain those characters (such as : on Windows) +func cleanPath(s string) string { + return s +} diff --git a/registry/config_windows.go b/registry/config_windows.go new file mode 100644 index 0000000000..3ebc044842 --- /dev/null +++ b/registry/config_windows.go @@ -0,0 +1,25 @@ +package registry + +import ( + "os" + "path/filepath" + "strings" +) + +// DefaultV2Registry is the URI of the default (official) v2 registry. +// This is the windows-specific endpoint. +// +// Currently it is a TEMPORARY link that allows Microsoft to continue +// development of Docker Engine for Windows. +const DefaultV2Registry = "https://ms-tp3.registry-1.docker.io" + +// CertsDir is the directory where certificates are stored +var CertsDir = os.Getenv("programdata") + `\docker\certs.d` + +// cleanPath is used to ensure that a directory name is valid on the target +// platform. It will be passed in something *similar* to a URL such as +// https:\index.docker.io\v1. Not all platforms support directory names +// which contain those characters (such as : on Windows) +func cleanPath(s string) string { + return filepath.FromSlash(strings.Replace(s, ":", "", -1)) +} diff --git a/registry/consts.go b/registry/consts.go deleted file mode 100644 index 19471e0600..0000000000 --- a/registry/consts.go +++ /dev/null @@ -1,24 +0,0 @@ -package registry - -const ( - // DefaultNamespace is the default namespace - DefaultNamespace = "docker.io" - // DefaultRegistryVersionHeader is the name of the default HTTP header - // that carries Registry version info - DefaultRegistryVersionHeader = "Docker-Distribution-Api-Version" - // DefaultV1Registry is the URI of the default v1 registry - DefaultV1Registry = "https://index.docker.io" - - // CertsDir is the directory where certificates are stored - CertsDir = "/etc/docker/certs.d" - - // IndexServer is the v1 registry server used for user auth + account creation - IndexServer = DefaultV1Registry + "/v1/" - // IndexName is the name of the index - IndexName = "docker.io" - - // NotaryServer is the endpoint serving the Notary trust server - NotaryServer = "https://notary.docker.io" - - // IndexServer = "https://registry-stage.hub.docker.com/v1/" -) diff --git a/registry/consts_unix.go b/registry/consts_unix.go deleted file mode 100644 index b02e579a12..0000000000 --- a/registry/consts_unix.go +++ /dev/null @@ -1,6 +0,0 @@ -// +build !windows - -package registry - -// DefaultV2Registry is the URI of the default v2 registry -const DefaultV2Registry = "https://registry-1.docker.io" diff --git a/registry/consts_windows.go b/registry/consts_windows.go deleted file mode 100644 index b62c5faf14..0000000000 --- a/registry/consts_windows.go +++ /dev/null @@ -1,10 +0,0 @@ -// +build windows - -package registry - -// DefaultV2Registry is the URI of the default (official) v2 registry. -// This is the windows-specific endpoint. -// -// Currently it is a TEMPORARY link that allows Microsoft to continue -// development of Docker Engine for Windows. -const DefaultV2Registry = "https://ms-tp3.registry-1.docker.io" diff --git a/registry/registry.go b/registry/registry.go index a3123b965d..408bc8e1fd 100644 --- a/registry/registry.go +++ b/registry/registry.go @@ -58,7 +58,7 @@ func newTLSConfig(hostname string, isSecure bool) (*tls.Config, error) { tlsConfig.InsecureSkipVerify = !isSecure if isSecure { - hostDir := filepath.Join(CertsDir, hostname) + hostDir := filepath.Join(CertsDir, cleanPath(hostname)) logrus.Debugf("hostDir: %s", hostDir) if err := ReadCertsDirectory(&tlsConfig, hostDir); err != nil { return nil, err