Move IndexInfo and ServiceConfig types to api/types/registry/registry.go

Signed-off-by: Daniel Nephin <dnephin@gmail.com>
Upstream-commit: 96c10098ac32f700f37358e2adc36c94741772bb
Component: engine
This commit is contained in:
Daniel Nephin
2015-12-14 11:28:02 -05:00
committed by Daniel Nephin
parent 0d867da41c
commit 7f5dff04d0
25 changed files with 187 additions and 170 deletions
+1
View File
@@ -9,6 +9,7 @@ import (
"strings"
"github.com/docker/docker/api/client/lib"
"github.com/docker/docker/api/types"
Cli "github.com/docker/docker/cli"
flag "github.com/docker/docker/pkg/mflag"
"github.com/docker/docker/pkg/term"
+1 -2
View File
@@ -8,7 +8,6 @@ import (
"github.com/docker/docker/api/client/lib"
"github.com/docker/docker/api/types"
Cli "github.com/docker/docker/cli"
"github.com/docker/docker/cliconfig"
"github.com/docker/docker/pkg/jsonmessage"
flag "github.com/docker/docker/pkg/mflag"
"github.com/docker/docker/registry"
@@ -78,7 +77,7 @@ func (cli *DockerCli) CmdPull(args ...string) error {
func (cli *DockerCli) imagePullPrivileged(authConfig types.AuthConfig, imageID, tag string, requestPrivilege lib.RequestPrivilegeFunc) error {
encodedAuth, err := cliconfig.EncodeAuthToBase64(authConfig)
encodedAuth, err := encodeAuthToBase64(authConfig)
if err != nil {
return err
}
+1 -2
View File
@@ -9,7 +9,6 @@ import (
"github.com/docker/docker/api/client/lib"
"github.com/docker/docker/api/types"
Cli "github.com/docker/docker/cli"
"github.com/docker/docker/cliconfig"
"github.com/docker/docker/pkg/jsonmessage"
flag "github.com/docker/docker/pkg/mflag"
"github.com/docker/docker/registry"
@@ -66,7 +65,7 @@ func (cli *DockerCli) CmdPush(args ...string) error {
}
func (cli *DockerCli) imagePushPrivileged(authConfig types.AuthConfig, imageID, tag string, outputStream io.Writer, requestPrivilege lib.RequestPrivilegeFunc) error {
encodedAuth, err := cliconfig.EncodeAuthToBase64(authConfig)
encodedAuth, err := encodeAuthToBase64(authConfig)
if err != nil {
return err
}
+1 -2
View File
@@ -9,7 +9,6 @@ import (
"github.com/docker/docker/api/types"
Cli "github.com/docker/docker/cli"
"github.com/docker/docker/cliconfig"
flag "github.com/docker/docker/pkg/mflag"
"github.com/docker/docker/pkg/stringutils"
"github.com/docker/docker/registry"
@@ -39,7 +38,7 @@ func (cli *DockerCli) CmdSearch(args ...string) error {
authConfig := registry.ResolveAuthConfig(cli.configFile.AuthConfigs, indexInfo)
requestPrivilege := cli.registryAuthenticationPrivilegedFunc(indexInfo, "search")
encodedAuth, err := cliconfig.EncodeAuthToBase64(authConfig)
encodedAuth, err := encodeAuthToBase64(authConfig)
if err != nil {
return err
}
+2 -1
View File
@@ -24,6 +24,7 @@ import (
"github.com/docker/distribution/registry/client/transport"
"github.com/docker/docker/api/client/lib"
"github.com/docker/docker/api/types"
registrytypes "github.com/docker/docker/api/types/registry"
"github.com/docker/docker/cliconfig"
"github.com/docker/docker/pkg/ansiescape"
"github.com/docker/docker/pkg/ioutils"
@@ -81,7 +82,7 @@ func (cli *DockerCli) certificateDirectory(server string) (string, error) {
return filepath.Join(cliconfig.ConfigDir(), "tls", u.Host), nil
}
func trustServer(index *registry.IndexInfo) (string, error) {
func trustServer(index *registrytypes.IndexInfo) (string, error) {
if s := os.Getenv("DOCKER_CONTENT_TRUST_SERVER"); s != "" {
urlObj, err := url.Parse(s)
if err != nil || urlObj.Scheme != "https" {
+5 -4
View File
@@ -4,6 +4,7 @@ import (
"os"
"testing"
registrytypes "github.com/docker/docker/api/types/registry"
"github.com/docker/docker/registry"
)
@@ -14,7 +15,7 @@ func unsetENV() {
func TestENVTrustServer(t *testing.T) {
defer unsetENV()
indexInfo := &registry.IndexInfo{Name: "testserver"}
indexInfo := &registrytypes.IndexInfo{Name: "testserver"}
if err := os.Setenv("DOCKER_CONTENT_TRUST_SERVER", "https://notary-test.com:5000"); err != nil {
t.Fatal("Failed to set ENV variable")
}
@@ -27,7 +28,7 @@ func TestENVTrustServer(t *testing.T) {
func TestHTTPENVTrustServer(t *testing.T) {
defer unsetENV()
indexInfo := &registry.IndexInfo{Name: "testserver"}
indexInfo := &registrytypes.IndexInfo{Name: "testserver"}
if err := os.Setenv("DOCKER_CONTENT_TRUST_SERVER", "http://notary-test.com:5000"); err != nil {
t.Fatal("Failed to set ENV variable")
}
@@ -38,7 +39,7 @@ func TestHTTPENVTrustServer(t *testing.T) {
}
func TestOfficialTrustServer(t *testing.T) {
indexInfo := &registry.IndexInfo{Name: "testserver", Official: true}
indexInfo := &registrytypes.IndexInfo{Name: "testserver", Official: true}
output, err := trustServer(indexInfo)
if err != nil || output != registry.NotaryServer {
t.Fatalf("Expected server to be %s, got %s", registry.NotaryServer, output)
@@ -46,7 +47,7 @@ func TestOfficialTrustServer(t *testing.T) {
}
func TestNonOfficialTrustServer(t *testing.T) {
indexInfo := &registry.IndexInfo{Name: "testserver", Official: false}
indexInfo := &registrytypes.IndexInfo{Name: "testserver", Official: false}
output, err := trustServer(indexInfo)
expectedStr := "https://" + indexInfo.Name
if err != nil || output != expectedStr {
+6 -5
View File
@@ -12,13 +12,14 @@ import (
"github.com/Sirupsen/logrus"
"github.com/docker/docker/api/client/lib"
"github.com/docker/docker/api/types"
registrytypes "github.com/docker/docker/api/types/registry"
"github.com/docker/docker/pkg/signal"
"github.com/docker/docker/pkg/term"
"github.com/docker/docker/registry"
)
// encodeAuthToBase64 serializes the auth configuration as JSON base64 payload
func encodeAuthToBase64(authConfig AuthConfig) (string, error) {
func encodeAuthToBase64(authConfig types.AuthConfig) (string, error) {
buf, err := json.Marshal(authConfig)
if err != nil {
return "", err
@@ -26,15 +27,15 @@ func encodeAuthToBase64(authConfig AuthConfig) (string, error) {
return base64.URLEncoding.EncodeToString(buf), nil
}
func (cli *DockerCli) encodeRegistryAuth(index *registry.IndexInfo) (string, error) {
func (cli *DockerCli) encodeRegistryAuth(index *registrytypes.IndexInfo) (string, error) {
authConfig := registry.ResolveAuthConfig(cli.configFile.AuthConfigs, index)
return cliconfig.EncodeAuthToBase64(authConfig)
return encodeAuthToBase64(authConfig)
}
func (cli *DockerCli) registryAuthenticationPrivilegedFunc(index *registry.IndexInfo, cmdName string) lib.RequestPrivilegeFunc {
func (cli *DockerCli) registryAuthenticationPrivilegedFunc(index *registrytypes.IndexInfo, cmdName string) lib.RequestPrivilegeFunc {
return func() (string, error) {
fmt.Fprintf(cli.out, "\nPlease login prior to %s:\n", cmdName)
if err := cli.CmdLogin(index.GetAuthConfigKey()); err != nil {
if err := cli.CmdLogin(registry.GetAuthConfigKey(index)); err != nil {
return "", err
}
return cli.encodeRegistryAuth(index)
+1 -1
View File
@@ -134,7 +134,7 @@ type ImageBuildOptions struct {
Dockerfile string
Ulimits []*ulimit.Ulimit
BuildArgs []string
AuthConfigs map[string]types.AuthConfig
AuthConfigs map[string]AuthConfig
Context io.Reader
}
@@ -0,0 +1,75 @@
package registry
import (
"encoding/json"
"net"
)
// ServiceConfig stores daemon registry services configuration.
type ServiceConfig struct {
InsecureRegistryCIDRs []*NetIPNet `json:"InsecureRegistryCIDRs"`
IndexConfigs map[string]*IndexInfo `json:"IndexConfigs"`
Mirrors []string
}
// NetIPNet is the net.IPNet type, which can be marshalled and
// unmarshalled to JSON
type NetIPNet net.IPNet
// MarshalJSON returns the JSON representation of the IPNet
func (ipnet *NetIPNet) MarshalJSON() ([]byte, error) {
return json.Marshal((*net.IPNet)(ipnet).String())
}
// UnmarshalJSON sets the IPNet from a byte array of JSON
func (ipnet *NetIPNet) UnmarshalJSON(b []byte) (err error) {
var ipnetStr string
if err = json.Unmarshal(b, &ipnetStr); err == nil {
var cidr *net.IPNet
if _, cidr, err = net.ParseCIDR(ipnetStr); err == nil {
*ipnet = NetIPNet(*cidr)
}
}
return
}
// IndexInfo contains information about a registry
//
// RepositoryInfo Examples:
// {
// "Index" : {
// "Name" : "docker.io",
// "Mirrors" : ["https://registry-2.docker.io/v1/", "https://registry-3.docker.io/v1/"],
// "Secure" : true,
// "Official" : true,
// },
// "RemoteName" : "library/debian",
// "LocalName" : "debian",
// "CanonicalName" : "docker.io/debian"
// "Official" : true,
// }
//
// {
// "Index" : {
// "Name" : "127.0.0.1:5000",
// "Mirrors" : [],
// "Secure" : false,
// "Official" : false,
// },
// "RemoteName" : "user/repo",
// "LocalName" : "127.0.0.1:5000/user/repo",
// "CanonicalName" : "127.0.0.1:5000/user/repo",
// "Official" : false,
// }
type IndexInfo struct {
// Name is the name of the registry, such as "docker.io"
Name string
// Mirrors is a list of mirrors, expressed as URIs
Mirrors []string
// Secure is set to false if the registry is part of the list of
// insecure registries. Insecure registries accept HTTP and/or accept
// HTTPS with certificates from unknown CAs.
Secure bool
// Official indicates whether this is an official registry
Official bool
}
+1 -1
View File
@@ -5,9 +5,9 @@ import (
"time"
"github.com/docker/docker/api/types/network"
"github.com/docker/docker/api/types/registry"
"github.com/docker/docker/pkg/nat"
"github.com/docker/docker/pkg/version"
"github.com/docker/docker/registry"
"github.com/docker/docker/runconfig"
)