Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

Commit 96c1009

Browse files
committed
Move IndexInfo and ServiceConfig types to api/types/registry/registry.go
Signed-off-by: Daniel Nephin <dnephin@gmail.com>
1 parent 5b321e3 commit 96c1009

File tree

25 files changed

+187
-170
lines changed

25 files changed

+187
-170
lines changed

api/client/login.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"strings"
1010

1111
"github.com/docker/docker/api/client/lib"
12+
"github.com/docker/docker/api/types"
1213
Cli "github.com/docker/docker/cli"
1314
flag "github.com/docker/docker/pkg/mflag"
1415
"github.com/docker/docker/pkg/term"

api/client/pull.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"github.com/docker/docker/api/client/lib"
99
"github.com/docker/docker/api/types"
1010
Cli "github.com/docker/docker/cli"
11-
"github.com/docker/docker/cliconfig"
1211
"github.com/docker/docker/pkg/jsonmessage"
1312
flag "github.com/docker/docker/pkg/mflag"
1413
"github.com/docker/docker/registry"
@@ -78,7 +77,7 @@ func (cli *DockerCli) CmdPull(args ...string) error {
7877

7978
func (cli *DockerCli) imagePullPrivileged(authConfig types.AuthConfig, imageID, tag string, requestPrivilege lib.RequestPrivilegeFunc) error {
8079

81-
encodedAuth, err := cliconfig.EncodeAuthToBase64(authConfig)
80+
encodedAuth, err := encodeAuthToBase64(authConfig)
8281
if err != nil {
8382
return err
8483
}

api/client/push.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"github.com/docker/docker/api/client/lib"
1010
"github.com/docker/docker/api/types"
1111
Cli "github.com/docker/docker/cli"
12-
"github.com/docker/docker/cliconfig"
1312
"github.com/docker/docker/pkg/jsonmessage"
1413
flag "github.com/docker/docker/pkg/mflag"
1514
"github.com/docker/docker/registry"
@@ -66,7 +65,7 @@ func (cli *DockerCli) CmdPush(args ...string) error {
6665
}
6766

6867
func (cli *DockerCli) imagePushPrivileged(authConfig types.AuthConfig, imageID, tag string, outputStream io.Writer, requestPrivilege lib.RequestPrivilegeFunc) error {
69-
encodedAuth, err := cliconfig.EncodeAuthToBase64(authConfig)
68+
encodedAuth, err := encodeAuthToBase64(authConfig)
7069
if err != nil {
7170
return err
7271
}

api/client/search.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99

1010
"github.com/docker/docker/api/types"
1111
Cli "github.com/docker/docker/cli"
12-
"github.com/docker/docker/cliconfig"
1312
flag "github.com/docker/docker/pkg/mflag"
1413
"github.com/docker/docker/pkg/stringutils"
1514
"github.com/docker/docker/registry"
@@ -39,7 +38,7 @@ func (cli *DockerCli) CmdSearch(args ...string) error {
3938
authConfig := registry.ResolveAuthConfig(cli.configFile.AuthConfigs, indexInfo)
4039
requestPrivilege := cli.registryAuthenticationPrivilegedFunc(indexInfo, "search")
4140

42-
encodedAuth, err := cliconfig.EncodeAuthToBase64(authConfig)
41+
encodedAuth, err := encodeAuthToBase64(authConfig)
4342
if err != nil {
4443
return err
4544
}

api/client/trust.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"github.com/docker/distribution/registry/client/transport"
2525
"github.com/docker/docker/api/client/lib"
2626
"github.com/docker/docker/api/types"
27+
registrytypes "github.com/docker/docker/api/types/registry"
2728
"github.com/docker/docker/cliconfig"
2829
"github.com/docker/docker/pkg/ansiescape"
2930
"github.com/docker/docker/pkg/ioutils"
@@ -81,7 +82,7 @@ func (cli *DockerCli) certificateDirectory(server string) (string, error) {
8182
return filepath.Join(cliconfig.ConfigDir(), "tls", u.Host), nil
8283
}
8384

84-
func trustServer(index *registry.IndexInfo) (string, error) {
85+
func trustServer(index *registrytypes.IndexInfo) (string, error) {
8586
if s := os.Getenv("DOCKER_CONTENT_TRUST_SERVER"); s != "" {
8687
urlObj, err := url.Parse(s)
8788
if err != nil || urlObj.Scheme != "https" {

api/client/trust_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"os"
55
"testing"
66

7+
registrytypes "github.com/docker/docker/api/types/registry"
78
"github.com/docker/docker/registry"
89
)
910

@@ -14,7 +15,7 @@ func unsetENV() {
1415

1516
func TestENVTrustServer(t *testing.T) {
1617
defer unsetENV()
17-
indexInfo := &registry.IndexInfo{Name: "testserver"}
18+
indexInfo := &registrytypes.IndexInfo{Name: "testserver"}
1819
if err := os.Setenv("DOCKER_CONTENT_TRUST_SERVER", "https://notary-test.com:5000"); err != nil {
1920
t.Fatal("Failed to set ENV variable")
2021
}
@@ -27,7 +28,7 @@ func TestENVTrustServer(t *testing.T) {
2728

2829
func TestHTTPENVTrustServer(t *testing.T) {
2930
defer unsetENV()
30-
indexInfo := &registry.IndexInfo{Name: "testserver"}
31+
indexInfo := &registrytypes.IndexInfo{Name: "testserver"}
3132
if err := os.Setenv("DOCKER_CONTENT_TRUST_SERVER", "http://notary-test.com:5000"); err != nil {
3233
t.Fatal("Failed to set ENV variable")
3334
}
@@ -38,15 +39,15 @@ func TestHTTPENVTrustServer(t *testing.T) {
3839
}
3940

4041
func TestOfficialTrustServer(t *testing.T) {
41-
indexInfo := &registry.IndexInfo{Name: "testserver", Official: true}
42+
indexInfo := &registrytypes.IndexInfo{Name: "testserver", Official: true}
4243
output, err := trustServer(indexInfo)
4344
if err != nil || output != registry.NotaryServer {
4445
t.Fatalf("Expected server to be %s, got %s", registry.NotaryServer, output)
4546
}
4647
}
4748

4849
func TestNonOfficialTrustServer(t *testing.T) {
49-
indexInfo := &registry.IndexInfo{Name: "testserver", Official: false}
50+
indexInfo := &registrytypes.IndexInfo{Name: "testserver", Official: false}
5051
output, err := trustServer(indexInfo)
5152
expectedStr := "https://" + indexInfo.Name
5253
if err != nil || output != expectedStr {

api/client/utils.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,30 @@ import (
1212
"github.com/Sirupsen/logrus"
1313
"github.com/docker/docker/api/client/lib"
1414
"github.com/docker/docker/api/types"
15+
registrytypes "github.com/docker/docker/api/types/registry"
1516
"github.com/docker/docker/pkg/signal"
1617
"github.com/docker/docker/pkg/term"
1718
"github.com/docker/docker/registry"
1819
)
1920

2021
// encodeAuthToBase64 serializes the auth configuration as JSON base64 payload
21-
func encodeAuthToBase64(authConfig AuthConfig) (string, error) {
22+
func encodeAuthToBase64(authConfig types.AuthConfig) (string, error) {
2223
buf, err := json.Marshal(authConfig)
2324
if err != nil {
2425
return "", err
2526
}
2627
return base64.URLEncoding.EncodeToString(buf), nil
2728
}
2829

29-
func (cli *DockerCli) encodeRegistryAuth(index *registry.IndexInfo) (string, error) {
30+
func (cli *DockerCli) encodeRegistryAuth(index *registrytypes.IndexInfo) (string, error) {
3031
authConfig := registry.ResolveAuthConfig(cli.configFile.AuthConfigs, index)
31-
return cliconfig.EncodeAuthToBase64(authConfig)
32+
return encodeAuthToBase64(authConfig)
3233
}
3334

34-
func (cli *DockerCli) registryAuthenticationPrivilegedFunc(index *registry.IndexInfo, cmdName string) lib.RequestPrivilegeFunc {
35+
func (cli *DockerCli) registryAuthenticationPrivilegedFunc(index *registrytypes.IndexInfo, cmdName string) lib.RequestPrivilegeFunc {
3536
return func() (string, error) {
3637
fmt.Fprintf(cli.out, "\nPlease login prior to %s:\n", cmdName)
37-
if err := cli.CmdLogin(index.GetAuthConfigKey()); err != nil {
38+
if err := cli.CmdLogin(registry.GetAuthConfigKey(index)); err != nil {
3839
return "", err
3940
}
4041
return cli.encodeRegistryAuth(index)

api/types/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ type ImageBuildOptions struct {
134134
Dockerfile string
135135
Ulimits []*ulimit.Ulimit
136136
BuildArgs []string
137-
AuthConfigs map[string]types.AuthConfig
137+
AuthConfigs map[string]AuthConfig
138138
Context io.Reader
139139
}
140140

api/types/registry/registry.go

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package registry
2+
3+
import (
4+
"encoding/json"
5+
"net"
6+
)
7+
8+
// ServiceConfig stores daemon registry services configuration.
9+
type ServiceConfig struct {
10+
InsecureRegistryCIDRs []*NetIPNet `json:"InsecureRegistryCIDRs"`
11+
IndexConfigs map[string]*IndexInfo `json:"IndexConfigs"`
12+
Mirrors []string
13+
}
14+
15+
// NetIPNet is the net.IPNet type, which can be marshalled and
16+
// unmarshalled to JSON
17+
type NetIPNet net.IPNet
18+
19+
// MarshalJSON returns the JSON representation of the IPNet
20+
func (ipnet *NetIPNet) MarshalJSON() ([]byte, error) {
21+
return json.Marshal((*net.IPNet)(ipnet).String())
22+
}
23+
24+
// UnmarshalJSON sets the IPNet from a byte array of JSON
25+
func (ipnet *NetIPNet) UnmarshalJSON(b []byte) (err error) {
26+
var ipnetStr string
27+
if err = json.Unmarshal(b, &ipnetStr); err == nil {
28+
var cidr *net.IPNet
29+
if _, cidr, err = net.ParseCIDR(ipnetStr); err == nil {
30+
*ipnet = NetIPNet(*cidr)
31+
}
32+
}
33+
return
34+
}
35+
36+
// IndexInfo contains information about a registry
37+
//
38+
// RepositoryInfo Examples:
39+
// {
40+
// "Index" : {
41+
// "Name" : "docker.io",
42+
// "Mirrors" : ["https://registry-2.docker.io/v1/", "https://registry-3.docker.io/v1/"],
43+
// "Secure" : true,
44+
// "Official" : true,
45+
// },
46+
// "RemoteName" : "library/debian",
47+
// "LocalName" : "debian",
48+
// "CanonicalName" : "docker.io/debian"
49+
// "Official" : true,
50+
// }
51+
//
52+
// {
53+
// "Index" : {
54+
// "Name" : "127.0.0.1:5000",
55+
// "Mirrors" : [],
56+
// "Secure" : false,
57+
// "Official" : false,
58+
// },
59+
// "RemoteName" : "user/repo",
60+
// "LocalName" : "127.0.0.1:5000/user/repo",
61+
// "CanonicalName" : "127.0.0.1:5000/user/repo",
62+
// "Official" : false,
63+
// }
64+
type IndexInfo struct {
65+
// Name is the name of the registry, such as "docker.io"
66+
Name string
67+
// Mirrors is a list of mirrors, expressed as URIs
68+
Mirrors []string
69+
// Secure is set to false if the registry is part of the list of
70+
// insecure registries. Insecure registries accept HTTP and/or accept
71+
// HTTPS with certificates from unknown CAs.
72+
Secure bool
73+
// Official indicates whether this is an official registry
74+
Official bool
75+
}

api/types/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import (
55
"time"
66

77
"github.com/docker/docker/api/types/network"
8+
"github.com/docker/docker/api/types/registry"
89
"github.com/docker/docker/pkg/nat"
910
"github.com/docker/docker/pkg/version"
10-
"github.com/docker/docker/registry"
1111
"github.com/docker/docker/runconfig"
1212
)
1313

0 commit comments

Comments
 (0)