Documentation
¶
Index ¶
- Constants
- Variables
- func AuthConfigForHostname(hostname string) (registry.AuthConfig, error)
- func AuthConfigs(images ...string) (map[string]registry.AuthConfig, error)
- func Dir() (string, error)
- func EncodeBase64(authConfig registry.AuthConfig) (string, error)
- func Filepath() (string, error)
- func Version() string
- type AuthConfig
- type Config
- func (c *Config) AuthConfigForHostname(hostname string) (registry.AuthConfig, error)
- func (c *Config) AuthConfigForImage(image string) (string, registry.AuthConfig, error)
- func (c *Config) AuthConfigsForImages(images []string) (map[string]registry.AuthConfig, error)
- func (c *Config) ParseProxyConfig(host string, runOpts map[string]*string) map[string]*string
- func (c *Config) Save() error
- type KubernetesConfig
- type ProxyConfig
Examples ¶
Constants ¶
const ( // EnvOverrideDir is the name of the environment variable that can be // used to override the location of the client configuration files (~/.docker). // // It takes priority over the default. EnvOverrideDir = "DOCKER_CONFIG" // configFileName is the name of the client configuration file inside the // config-directory. FileName = "config.json" )
Variables ¶
var ( ErrCredentialsNotFound = errors.New("credentials not found in native keychain") ErrCredentialsMissingServerURL = errors.New("no credentials server URL") )
Errors from credential helpers.
Functions ¶
func AuthConfigForHostname ¶
func AuthConfigForHostname(hostname string) (registry.AuthConfig, error)
AuthConfigForHostname gets registry credentials for the passed in registry host.
This will use Load to read registry auth details from the config. If the config doesn't exist, it will attempt to load registry credentials using the default credential helper for the platform.
Example ¶
package main
import (
"fmt"
"github.com/docker/go-sdk/config"
"github.com/docker/go-sdk/config/auth"
)
func main() {
authConfig, err := config.AuthConfigForHostname(auth.IndexDockerIO)
fmt.Println(err)
fmt.Println(authConfig.Username != "")
}
Output: <nil> true
func AuthConfigs ¶
func AuthConfigs(images ...string) (map[string]registry.AuthConfig, error)
AuthConfigs returns the auth configs for the given images. The images slice must contain images that are used in a Dockerfile. The returned map is keyed by the registry registry hostname for each image.
Example ¶
package main
import (
"fmt"
"github.com/docker/go-sdk/config"
"github.com/docker/go-sdk/config/auth"
)
func main() {
authConfigs, err := config.AuthConfigs("nginx:latest")
fmt.Println(err)
fmt.Println(len(authConfigs))
fmt.Println(authConfigs[auth.DockerRegistry].ServerAddress)
}
Output: <nil> 1 docker.io
func Dir ¶
Dir returns the directory the configuration file is stored in, checking if the directory exists.
Example ¶
package main
import (
"fmt"
"strings"
"github.com/docker/go-sdk/config"
)
func main() {
dir, err := config.Dir()
fmt.Println(err)
fmt.Println(strings.HasSuffix(dir, ".docker"))
}
Output: <nil> true
func EncodeBase64 ¶
func EncodeBase64(authConfig registry.AuthConfig) (string, error)
EncodeBase64 encodes an AuthConfig into base64.
func Filepath ¶
Filepath returns the path to the docker cli config file, checking if the file exists.
Example ¶
package main
import (
"fmt"
"log"
"strings"
"github.com/docker/go-sdk/config"
)
func main() {
filepath, err := config.Filepath()
if err != nil {
log.Printf("error getting config filepath: %s", err)
return
}
fmt.Println(strings.HasSuffix(filepath, "config.json"))
}
Output: true
Types ¶
type AuthConfig ¶
type AuthConfig registry.AuthConfig
AuthConfig contains authorization information for connecting to a Registry. Deprecated: prefer use of registry.AuthConfig
type Config ¶
type Config struct {
AuthConfigs map[string]registry.AuthConfig `json:"auths"`
HTTPHeaders map[string]string `json:"HttpHeaders,omitempty"`
PsFormat string `json:"psFormat,omitempty"`
ImagesFormat string `json:"imagesFormat,omitempty"`
NetworksFormat string `json:"networksFormat,omitempty"`
PluginsFormat string `json:"pluginsFormat,omitempty"`
VolumesFormat string `json:"volumesFormat,omitempty"`
StatsFormat string `json:"statsFormat,omitempty"`
DetachKeys string `json:"detachKeys,omitempty"`
CredentialsStore string `json:"credsStore,omitempty"`
CredentialHelpers map[string]string `json:"credHelpers,omitempty"`
Filename string `json:"-"` // Note: for internal use only.
ServiceInspectFormat string `json:"serviceInspectFormat,omitempty"`
ServicesFormat string `json:"servicesFormat,omitempty"`
TasksFormat string `json:"tasksFormat,omitempty"`
SecretFormat string `json:"secretFormat,omitempty"`
ConfigFormat string `json:"configFormat,omitempty"`
NodesFormat string `json:"nodesFormat,omitempty"`
PruneFilters []string `json:"pruneFilters,omitempty"`
Proxies map[string]ProxyConfig `json:"proxies,omitempty"`
Experimental string `json:"experimental,omitempty"`
StackOrchestrator string `json:"stackOrchestrator,omitempty"`
Kubernetes *KubernetesConfig `json:"kubernetes,omitempty"`
CurrentContext string `json:"currentContext,omitempty"`
CLIPluginsExtraDirs []string `json:"cliPluginsExtraDirs,omitempty"`
Aliases map[string]string `json:"aliases,omitempty"`
// contains filtered or unexported fields
}
Config represents the on disk format of the docker CLI's config file.
func Load ¶
Load returns the docker config file. It will internally check, in this particular order: 1. the DOCKER_AUTH_CONFIG environment variable, unmarshalling it into a Config 2. the DOCKER_CONFIG environment variable, as the path to the config file 3. else it will load the default config file, which is ~/.docker/config.json
Example ¶
package main
import (
"fmt"
"github.com/docker/go-sdk/config"
)
func main() {
cfg, err := config.Load()
fmt.Println(err)
fmt.Println(len(cfg.AuthConfigs) > 0)
}
Output: <nil> true
func (*Config) AuthConfigForHostname ¶
func (c *Config) AuthConfigForHostname(hostname string) (registry.AuthConfig, error)
AuthConfigForHostname returns the auth config for the given hostname with caching
func (*Config) AuthConfigForImage ¶
AuthConfigForImage returns the auth config for a single image
func (*Config) AuthConfigsForImages ¶
AuthConfigsForImages returns auth configs for multiple images with caching
func (*Config) ParseProxyConfig ¶
ParseProxyConfig computes proxy configuration by retrieving the config for the provided host and then checking this against any environment variables provided to the container
type KubernetesConfig ¶
type KubernetesConfig struct {
AllNamespaces string `json:"allNamespaces,omitempty"`
}
KubernetesConfig contains Kubernetes orchestrator settings.
type ProxyConfig ¶
type ProxyConfig struct {
HTTPProxy string `json:"httpProxy,omitempty"`
HTTPSProxy string `json:"httpsProxy,omitempty"`
NoProxy string `json:"noProxy,omitempty"`
FTPProxy string `json:"ftpProxy,omitempty"`
AllProxy string `json:"allProxy,omitempty"`
}
ProxyConfig contains proxy configuration settings.