2015-05-22 18:37:40 +00:00
|
|
|
package dockerclient
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"encoding/base64"
|
|
|
|
"encoding/json"
|
|
|
|
)
|
|
|
|
|
|
|
|
// AuthConfig hold parameters for authenticating with the docker registry
|
|
|
|
type AuthConfig struct {
|
2016-03-07 19:23:49 +00:00
|
|
|
Username string `json:"username,omitempty"`
|
|
|
|
Password string `json:"password,omitempty"`
|
|
|
|
Email string `json:"email,omitempty"`
|
|
|
|
RegistryToken string `json:"registrytoken,omitempty"`
|
2015-05-22 18:37:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// encode the auth configuration struct into base64 for the X-Registry-Auth header
|
2015-09-30 01:21:17 +00:00
|
|
|
func (c *AuthConfig) encode() (string, error) {
|
2015-05-22 18:37:40 +00:00
|
|
|
var buf bytes.Buffer
|
2015-09-30 01:21:17 +00:00
|
|
|
if err := json.NewEncoder(&buf).Encode(c); err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
return base64.URLEncoding.EncodeToString(buf.Bytes()), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// ConfigFile holds parameters for authenticating during a BuildImage request
|
|
|
|
type ConfigFile struct {
|
|
|
|
Configs map[string]AuthConfig `json:"configs,omitempty"`
|
|
|
|
rootPath string
|
|
|
|
}
|
|
|
|
|
|
|
|
// encode the configuration struct into base64 for the X-Registry-Config header
|
|
|
|
func (c *ConfigFile) encode() (string, error) {
|
|
|
|
var buf bytes.Buffer
|
|
|
|
if err := json.NewEncoder(&buf).Encode(c); err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
return base64.URLEncoding.EncodeToString(buf.Bytes()), nil
|
2015-05-22 18:37:40 +00:00
|
|
|
}
|