dockerconfig

package module
v0.0.0-...-70a4f80 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 18, 2015 License: Apache-2.0 Imports: 9 Imported by: 2

README

DockerConfig

This package is essentially a fork of github.com/docker/docker/cliconfig.

The main difference is the ability to manage both legacy .dockercfg and new config.json (Docker 1.7+) files.

Migrations between both formats can be easily done by changing the version number.

Usage

package foo

import (
	"fmt"

	"github.com/gigablah/dockerconfig"
)

func main() {
	// Try to locate a Docker config file
	// Looks for ~/.docker/config.json and falls back to ~/.dockercfg
	// Base directory can be changed or read from DOCKER_CONFIG
	if config, err := dockerconfig.Load(""); err != nil {
		panic(fmt.Errorf("%v", err))
	}

	fmt.Printf("Writing to Docker file %v...\n", config.Filename())

	auth, ok := config.AuthConfigs["example.com"]
	if !ok {
		auth = dockerconfig.AuthConfig{}
	}
	auth.Username = "Foo"
	auth.Password = "Bar"
	auth.Email = "foobar@example.com"
	auth.ServerAddress = "example.com"
	config.AuthConfigs["example.com"] = auth

	// Save Docker config back to the same file it was loaded from
	if err := config.Save(); err != nil {
		panic(fmt.Errorf("%v", err))
	}

	// Save Docker config in the new config.json location and format
	config.version = 2
	err := config.Save()
}

License

Released under the Apache License, Version 2.0.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeAuth

func DecodeAuth(authStr string) (string, string, error)

DecodeAuth decodes a base64 encoded string and returns username and password

func EncodeAuth

func EncodeAuth(a *AuthConfig) string

EncodeAuth creates a base64 encoded string to containing authorization information

func SetConfigDir

func SetConfigDir(dir string)

SetConfigDir sets the base directory the configuration file is stored in

Types

type AuthConfig

type AuthConfig struct {
	Username      string `json:"username,omitempty"`
	Password      string `json:"password,omitempty"`
	Auth          string `json:"auth"`
	Email         string `json:"email"`
	ServerAddress string `json:"serveraddress,omitempty"`
	RegistryToken string `json:"registrytoken,omitempty"`
}

AuthConfig contains authorization information for connecting to a Registry

type ConfigFile

type ConfigFile struct {
	AuthConfigs map[string]AuthConfig `json:"auths"`
	HTTPHeaders map[string]string     `json:"HttpHeaders,omitempty"`
	PsFormat    string                `json:"psFormat,omitempty"`
	// contains filtered or unexported fields
}

ConfigFile structure

func Load

func Load(dir string) (*ConfigFile, error)

Load is a convenience function that attempts to load a v2 config with v1 fallback

func NewConfigFile

func NewConfigFile(fn string) *ConfigFile

NewConfigFile initilizes an empty configuration

func (*ConfigFile) ConfigDir

func (c *ConfigFile) ConfigDir() string

ConfigDir returns the directory the config file is stored in

func (*ConfigFile) Filename

func (c *ConfigFile) Filename() string

Filename returns the current config file location

func (*ConfigFile) Load

func (c *ConfigFile) Load() error

Load reads the config file and decodes the authorization information

func (*ConfigFile) Save

func (c *ConfigFile) Save() error

Save encodes and writes out all the authorization information

type ConfigReadWriter

type ConfigReadWriter interface {
	LoadFromReader(r io.Reader, c *ConfigFile) error
	SaveToWriter(w io.Writer, c *ConfigFile) error
	ConfigDir(c *ConfigFile) string
	Filename(c *ConfigFile) string
}

ConfigReadWriter interface

func NewConfigReadWriter

func NewConfigReadWriter(version int) (ConfigReadWriter, error)

NewConfigReadWriter returns a ConfigReadWriter based on the version

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL