From 5979d6e7e3ed76e4c85121fffe673426cc00fb3d Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 7 Mar 2022 11:50:22 +0100 Subject: client: add const for environment variables, and document them This adds consts for the environment variables that are supported by the client. These environment variables are unlikely to change, or at least, unlikely to be removed, but having consts allows for them to be documented. I did not change all occurrences of these variables to use the const, as they're used in various tests, and it's ok to use a fixture for those, but it's nice to have a const available for (external) consumers of the client package, and to have their purpose (and caveats) documented in the code. Signed-off-by: Sebastiaan van Stijn --- client/options.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'client/options.go') diff --git a/client/options.go b/client/options.go index 028f61c00a..98d96f792e 100644 --- a/client/options.go +++ b/client/options.go @@ -20,15 +20,15 @@ type Opt func(*Client) error // // FromEnv uses the following environment variables: // -// DOCKER_HOST to set the URL to the docker server. +// DOCKER_HOST (EnvOverrideHost) to set the URL to the docker server. // -// DOCKER_API_VERSION to set the version of the API to +// DOCKER_API_VERSION (EnvOverrideAPIVersion) to set the version of the API to // use, leave empty for latest. // -// DOCKER_CERT_PATH to specify the directory from which to +// DOCKER_CERT_PATH (EnvOverrideCertPath) to specify the directory from which to // load the TLS certificates (ca.pem, cert.pem, key.pem). // -// DOCKER_TLS_VERIFY to enable or disable TLS verification (off by +// DOCKER_TLS_VERIFY (EnvTLSVerify) to enable or disable TLS verification (off by // default). func FromEnv(c *Client) error { ops := []Opt{ @@ -82,11 +82,11 @@ func WithHost(host string) Opt { } // WithHostFromEnv overrides the client host with the host specified in the -// DOCKER_HOST environment variable. If DOCKER_HOST is not set, +// DOCKER_HOST (EnvOverrideHost) environment variable. If DOCKER_HOST is not set, // or set to an empty value, the host is not modified. func WithHostFromEnv() Opt { return func(c *Client) error { - if host := os.Getenv("DOCKER_HOST"); host != "" { + if host := os.Getenv(EnvOverrideHost); host != "" { return WithHost(host)(c) } return nil @@ -154,14 +154,14 @@ func WithTLSClientConfig(cacertPath, certPath, keyPath string) Opt { // // WithTLSClientConfigFromEnv uses the following environment variables: // -// DOCKER_CERT_PATH to specify the directory from which to +// DOCKER_CERT_PATH (EnvOverrideCertPath) to specify the directory from which to // load the TLS certificates (ca.pem, cert.pem, key.pem). // -// DOCKER_TLS_VERIFY to enable or disable TLS verification (off by +// DOCKER_TLS_VERIFY (EnvTLSVerify) to enable or disable TLS verification (off by // default). func WithTLSClientConfigFromEnv() Opt { return func(c *Client) error { - dockerCertPath := os.Getenv("DOCKER_CERT_PATH") + dockerCertPath := os.Getenv(EnvOverrideCertPath) if dockerCertPath == "" { return nil } @@ -169,7 +169,7 @@ func WithTLSClientConfigFromEnv() Opt { CAFile: filepath.Join(dockerCertPath, "ca.pem"), CertFile: filepath.Join(dockerCertPath, "cert.pem"), KeyFile: filepath.Join(dockerCertPath, "key.pem"), - InsecureSkipVerify: os.Getenv("DOCKER_TLS_VERIFY") == "", + InsecureSkipVerify: os.Getenv(EnvTLSVerify) == "", } tlsc, err := tlsconfig.Client(options) if err != nil { @@ -201,7 +201,7 @@ func WithVersion(version string) Opt { // the version is not modified. func WithVersionFromEnv() Opt { return func(c *Client) error { - return WithVersion(os.Getenv("DOCKER_API_VERSION"))(c) + return WithVersion(os.Getenv(EnvOverrideAPIVersion))(c) } } -- cgit v1.2.1