From 86a3ea91b817ef42d22748ee01ddfc9f2b881fe9 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 --- docs/config.go | 20 ++++++++++++++++++++ docs/config_unix.go | 19 +++++++++++++++++++ docs/config_windows.go | 25 +++++++++++++++++++++++++ docs/consts.go | 24 ------------------------ docs/consts_unix.go | 6 ------ docs/consts_windows.go | 10 ---------- docs/registry.go | 2 +- 7 files changed, 65 insertions(+), 41 deletions(-) create mode 100644 docs/config_unix.go create mode 100644 docs/config_windows.go delete mode 100644 docs/consts.go delete mode 100644 docs/consts_unix.go delete mode 100644 docs/consts_windows.go diff --git a/docs/config.go b/docs/config.go index dc1ee899..678a330e 100644 --- a/docs/config.go +++ b/docs/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/docs/config_unix.go b/docs/config_unix.go new file mode 100644 index 00000000..908ca2f6 --- /dev/null +++ b/docs/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/docs/config_windows.go b/docs/config_windows.go new file mode 100644 index 00000000..3ebc0448 --- /dev/null +++ b/docs/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/docs/consts.go b/docs/consts.go deleted file mode 100644 index 19471e06..00000000 --- a/docs/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/docs/consts_unix.go b/docs/consts_unix.go deleted file mode 100644 index b02e579a..00000000 --- a/docs/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/docs/consts_windows.go b/docs/consts_windows.go deleted file mode 100644 index b62c5faf..00000000 --- a/docs/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/docs/registry.go b/docs/registry.go index a3123b96..408bc8e1 100644 --- a/docs/registry.go +++ b/docs/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