Browse code

Allow index server address to vary during execution

shin- authored on 2013/05/09 23:41:59
Showing 2 changed files
... ...
@@ -15,7 +15,7 @@ import (
15 15
 const CONFIGFILE = ".dockercfg"
16 16
 
17 17
 // the registry server we want to login against
18
-const INDEX_SERVER = "https://index.docker.io"
18
+const INDEX_SERVER = "https://index.docker.io/v1"
19 19
 
20 20
 type AuthConfig struct {
21 21
 	Username string `json:"username"`
... ...
@@ -35,7 +35,7 @@ func NewAuthConfig(username, password, email, rootPath string) *AuthConfig {
35 35
 
36 36
 func IndexServerAddress() string {
37 37
 	if os.Getenv("DOCKER_INDEX_URL") != "" {
38
-		return os.Getenv("DOCKER_INDEX_URL")
38
+		return os.Getenv("DOCKER_INDEX_URL") + "/v1"
39 39
 	}
40 40
 	return INDEX_SERVER
41 41
 }
... ...
@@ -126,7 +126,7 @@ func Login(authConfig *AuthConfig) (string, error) {
126 126
 
127 127
 	// using `bytes.NewReader(jsonBody)` here causes the server to respond with a 411 status.
128 128
 	b := strings.NewReader(string(jsonBody))
129
-	req1, err := http.Post(INDEX_SERVER+"/v1/users/", "application/json; charset=utf-8", b)
129
+	req1, err := http.Post(IndexServerAddress()+"/users/", "application/json; charset=utf-8", b)
130 130
 	if err != nil {
131 131
 		return "", fmt.Errorf("Server Error: %s", err)
132 132
 	}
... ...
@@ -146,7 +146,7 @@ func Login(authConfig *AuthConfig) (string, error) {
146 146
 			"Please check your e-mail for a confirmation link.")
147 147
 	} else if reqStatusCode == 400 {
148 148
 		if string(reqBody) == "\"Username or email already exists\"" {
149
-			req, err := http.NewRequest("GET", INDEX_SERVER+"/v1/users/", nil)
149
+			req, err := http.NewRequest("GET", IndexServerAddress()+"/users/", nil)
150 150
 			req.SetBasicAuth(authConfig.Username, authConfig.Password)
151 151
 			resp, err := client.Do(req)
152 152
 			if err != nil {
... ...
@@ -15,8 +15,6 @@ import (
15 15
 	"strings"
16 16
 )
17 17
 
18
-var INDEX_ENDPOINT = auth.IndexServerAddress() + "/v1"
19
-
20 18
 // Build an Image object from raw json data
21 19
 func NewImgJson(src []byte) (*Image, error) {
22 20
 	ret := &Image{}
... ...
@@ -90,7 +88,7 @@ func (graph *Graph) LookupRemoteImage(imgId, registry string, authConfig *auth.A
90 90
 }
91 91
 
92 92
 func (graph *Graph) getImagesInRepository(repository string, authConfig *auth.AuthConfig) ([]map[string]string, error) {
93
-	u := INDEX_ENDPOINT + "/repositories/" + repository + "/images"
93
+	u := auth.IndexServerAddress() + "/repositories/" + repository + "/images"
94 94
 	req, err := http.NewRequest("GET", u, nil)
95 95
 	if err != nil {
96 96
 		return nil, err
... ...
@@ -270,8 +268,8 @@ func (graph *Graph) PullImage(stdout io.Writer, imgId, registry string, token []
270 270
 func (graph *Graph) PullRepository(stdout io.Writer, remote, askedTag string, repositories *TagStore, authConfig *auth.AuthConfig) error {
271 271
 	client := graph.getHttpClient()
272 272
 
273
-	fmt.Fprintf(stdout, "Pulling repository %s from %s\r\n", remote, INDEX_ENDPOINT)
274
-	repositoryTarget := INDEX_ENDPOINT + "/repositories/" + remote + "/images"
273
+	fmt.Fprintf(stdout, "Pulling repository %s from %s\r\n", remote, auth.IndexServerAddress())
274
+	repositoryTarget := auth.IndexServerAddress() + "/repositories/" + remote + "/images"
275 275
 
276 276
 	req, err := http.NewRequest("GET", repositoryTarget, nil)
277 277
 	if err != nil {
... ...
@@ -629,7 +627,7 @@ func (graph *Graph) PushRepository(stdout io.Writer, remote string, localRepo Re
629 629
 	Debugf("json sent: %s\n", imgListJson)
630 630
 
631 631
 	fmt.Fprintf(stdout, "Sending image list\n")
632
-	req, err := http.NewRequest("PUT", INDEX_ENDPOINT+"/repositories/"+remote+"/", bytes.NewReader(imgListJson))
632
+	req, err := http.NewRequest("PUT", auth.IndexServerAddress()+"/repositories/"+remote+"/", bytes.NewReader(imgListJson))
633 633
 	if err != nil {
634 634
 		return err
635 635
 	}
... ...
@@ -693,7 +691,8 @@ func (graph *Graph) PushRepository(stdout io.Writer, remote string, localRepo Re
693 693
 		}
694 694
 	}
695 695
 
696
-	req2, err := http.NewRequest("PUT", INDEX_ENDPOINT+"/repositories/"+remote+"/images", bytes.NewReader(imgListJson))
696
+
697
+	req2, err := http.NewRequest("PUT", auth.IndexServerAddress()+"/repositories/"+remote+"/images", bytes.NewReader(imgListJson))
697 698
 	if err != nil {
698 699
 		return err
699 700
 	}
... ...
@@ -724,7 +723,7 @@ type SearchResults struct {
724 724
 
725 725
 func (graph *Graph) SearchRepositories(stdout io.Writer, term string) (*SearchResults, error) {
726 726
 	client := graph.getHttpClient()
727
-	u := INDEX_ENDPOINT + "/search?q=" + url.QueryEscape(term)
727
+	u := auth.IndexServerAddress() + "/search?q=" + url.QueryEscape(term)
728 728
 	req, err := http.NewRequest("GET", u, nil)
729 729
 	if err != nil {
730 730
 		return nil, err