Docker-DCO-1.1-Signed-off-by: Cristian Staretu <cristian.staretu@gmail.com> (github: unclejack)
| ... | ... |
@@ -224,12 +224,11 @@ func Login(authConfig *AuthConfig, factory *utils.HTTPRequestFactory) (string, e |
| 224 | 224 |
return "", fmt.Errorf("Login: Account is not Active. Please check your e-mail for a confirmation link.")
|
| 225 | 225 |
} |
| 226 | 226 |
return "", fmt.Errorf("Login: Account is not Active. Please see the documentation of the registry %s for instructions how to activate it.", serverAddress)
|
| 227 |
- } else {
|
|
| 228 |
- return "", fmt.Errorf("Login: %s (Code: %d; Headers: %s)", body, resp.StatusCode, resp.Header)
|
|
| 229 | 227 |
} |
| 230 |
- } else {
|
|
| 231 |
- return "", fmt.Errorf("Registration: %s", reqBody)
|
|
| 228 |
+ return "", fmt.Errorf("Login: %s (Code: %d; Headers: %s)", body, resp.StatusCode, resp.Header)
|
|
| 232 | 229 |
} |
| 230 |
+ return "", fmt.Errorf("Registration: %s", reqBody)
|
|
| 231 |
+ |
|
| 233 | 232 |
} else if reqStatusCode == 401 {
|
| 234 | 233 |
// This case would happen with private registries where /v1/users is |
| 235 | 234 |
// protected, so people can use `docker login` as an auth check. |
| ... | ... |
@@ -13,7 +13,7 @@ import ( |
| 13 | 13 |
) |
| 14 | 14 |
|
| 15 | 15 |
// scans string for api version in the URL path. returns the trimmed hostname, if version found, string and API version. |
| 16 |
-func scanForApiVersion(hostname string) (string, APIVersion) {
|
|
| 16 |
+func scanForAPIVersion(hostname string) (string, APIVersion) {
|
|
| 17 | 17 |
var ( |
| 18 | 18 |
chunks []string |
| 19 | 19 |
apiVersionStr string |
| ... | ... |
@@ -43,7 +43,7 @@ func NewEndpoint(hostname string) (*Endpoint, error) {
|
| 43 | 43 |
if !strings.HasPrefix(hostname, "http") {
|
| 44 | 44 |
hostname = "https://" + hostname |
| 45 | 45 |
} |
| 46 |
- trimmedHostname, endpoint.Version = scanForApiVersion(hostname) |
|
| 46 |
+ trimmedHostname, endpoint.Version = scanForAPIVersion(hostname) |
|
| 47 | 47 |
endpoint.URL, err = url.Parse(trimmedHostname) |
| 48 | 48 |
if err != nil {
|
| 49 | 49 |
return nil, err |
| ... | ... |
@@ -19,7 +19,7 @@ import ( |
| 19 | 19 |
) |
| 20 | 20 |
|
| 21 | 21 |
var ( |
| 22 |
- testHttpServer *httptest.Server |
|
| 22 |
+ testHTTPServer *httptest.Server |
|
| 23 | 23 |
testLayers = map[string]map[string]string{
|
| 24 | 24 |
"77dbf71da1d00e3fbddc480176eac8994025630c6590d11cfc8fe1209c2a1d20": {
|
| 25 | 25 |
"json": `{"id":"77dbf71da1d00e3fbddc480176eac8994025630c6590d11cfc8fe1209c2a1d20",
|
| ... | ... |
@@ -99,7 +99,7 @@ func init() {
|
| 99 | 99 |
// /v2/ |
| 100 | 100 |
r.HandleFunc("/v2/version", handlerGetPing).Methods("GET")
|
| 101 | 101 |
|
| 102 |
- testHttpServer = httptest.NewServer(handlerAccessLog(r)) |
|
| 102 |
+ testHTTPServer = httptest.NewServer(handlerAccessLog(r)) |
|
| 103 | 103 |
} |
| 104 | 104 |
|
| 105 | 105 |
func handlerAccessLog(handler http.Handler) http.Handler {
|
| ... | ... |
@@ -111,7 +111,7 @@ func handlerAccessLog(handler http.Handler) http.Handler {
|
| 111 | 111 |
} |
| 112 | 112 |
|
| 113 | 113 |
func makeURL(req string) string {
|
| 114 |
- return testHttpServer.URL + req |
|
| 114 |
+ return testHTTPServer.URL + req |
|
| 115 | 115 |
} |
| 116 | 116 |
|
| 117 | 117 |
func writeHeaders(w http.ResponseWriter) {
|
| ... | ... |
@@ -198,8 +198,8 @@ func handlerGetImage(w http.ResponseWriter, r *http.Request) {
|
| 198 | 198 |
return |
| 199 | 199 |
} |
| 200 | 200 |
writeHeaders(w) |
| 201 |
- layer_size := len(layer["layer"]) |
|
| 202 |
- w.Header().Add("X-Docker-Size", strconv.Itoa(layer_size))
|
|
| 201 |
+ layerSize := len(layer["layer"]) |
|
| 202 |
+ w.Header().Add("X-Docker-Size", strconv.Itoa(layerSize))
|
|
| 203 | 203 |
io.WriteString(w, layer[vars["action"]]) |
| 204 | 204 |
} |
| 205 | 205 |
|
| ... | ... |
@@ -208,16 +208,16 @@ func handlerPutImage(w http.ResponseWriter, r *http.Request) {
|
| 208 | 208 |
return |
| 209 | 209 |
} |
| 210 | 210 |
vars := mux.Vars(r) |
| 211 |
- image_id := vars["image_id"] |
|
| 211 |
+ imageID := vars["image_id"] |
|
| 212 | 212 |
action := vars["action"] |
| 213 |
- layer, exists := testLayers[image_id] |
|
| 213 |
+ layer, exists := testLayers[imageID] |
|
| 214 | 214 |
if !exists {
|
| 215 | 215 |
if action != "json" {
|
| 216 | 216 |
http.NotFound(w, r) |
| 217 | 217 |
return |
| 218 | 218 |
} |
| 219 | 219 |
layer = make(map[string]string) |
| 220 |
- testLayers[image_id] = layer |
|
| 220 |
+ testLayers[imageID] = layer |
|
| 221 | 221 |
} |
| 222 | 222 |
if checksum := r.Header.Get("X-Docker-Checksum"); checksum != "" {
|
| 223 | 223 |
if checksum != layer["checksum_simple"] && checksum != layer["checksum_tarsum"] {
|
| ... | ... |
@@ -301,7 +301,7 @@ func handlerUsers(w http.ResponseWriter, r *http.Request) {
|
| 301 | 301 |
} |
| 302 | 302 |
|
| 303 | 303 |
func handlerImages(w http.ResponseWriter, r *http.Request) {
|
| 304 |
- u, _ := url.Parse(testHttpServer.URL) |
|
| 304 |
+ u, _ := url.Parse(testHTTPServer.URL) |
|
| 305 | 305 |
w.Header().Add("X-Docker-Endpoints", fmt.Sprintf("%s , %s ", u.Host, "test.example.com"))
|
| 306 | 306 |
w.Header().Add("X-Docker-Token", fmt.Sprintf("FAKE-SESSION-%d", time.Now().UnixNano()))
|
| 307 | 307 |
if r.Method == "PUT" {
|
| ... | ... |
@@ -317,9 +317,9 @@ func handlerImages(w http.ResponseWriter, r *http.Request) {
|
| 317 | 317 |
return |
| 318 | 318 |
} |
| 319 | 319 |
images := []map[string]string{}
|
| 320 |
- for image_id, layer := range testLayers {
|
|
| 320 |
+ for imageID, layer := range testLayers {
|
|
| 321 | 321 |
image := make(map[string]string) |
| 322 |
- image["id"] = image_id |
|
| 322 |
+ image["id"] = imageID |
|
| 323 | 323 |
image["checksum"] = layer["checksum_tarsum"] |
| 324 | 324 |
image["Tag"] = "latest" |
| 325 | 325 |
images = append(images, image) |
| ... | ... |
@@ -11,9 +11,12 @@ import ( |
| 11 | 11 |
) |
| 12 | 12 |
|
| 13 | 13 |
var ( |
| 14 |
- IMAGE_ID = "42d718c941f5c532ac049bf0b0ab53f0062f09a03afd4aa4a02c098e46032b9d" |
|
| 15 |
- TOKEN = []string{"fake-token"}
|
|
| 16 |
- REPO = "foo42/bar" |
|
| 14 |
+ token = []string{"fake-token"}
|
|
| 15 |
+) |
|
| 16 |
+ |
|
| 17 |
+const ( |
|
| 18 |
+ imageID = "42d718c941f5c532ac049bf0b0ab53f0062f09a03afd4aa4a02c098e46032b9d" |
|
| 19 |
+ REPO = "foo42/bar" |
|
| 17 | 20 |
) |
| 18 | 21 |
|
| 19 | 22 |
func spawnTestRegistrySession(t *testing.T) *Session {
|
| ... | ... |
@@ -43,27 +46,27 @@ func TestPingRegistryEndpoint(t *testing.T) {
|
| 43 | 43 |
|
| 44 | 44 |
func TestGetRemoteHistory(t *testing.T) {
|
| 45 | 45 |
r := spawnTestRegistrySession(t) |
| 46 |
- hist, err := r.GetRemoteHistory(IMAGE_ID, makeURL("/v1/"), TOKEN)
|
|
| 46 |
+ hist, err := r.GetRemoteHistory(imageID, makeURL("/v1/"), token)
|
|
| 47 | 47 |
if err != nil {
|
| 48 | 48 |
t.Fatal(err) |
| 49 | 49 |
} |
| 50 | 50 |
assertEqual(t, len(hist), 2, "Expected 2 images in history") |
| 51 |
- assertEqual(t, hist[0], IMAGE_ID, "Expected "+IMAGE_ID+"as first ancestry") |
|
| 51 |
+ assertEqual(t, hist[0], imageID, "Expected "+imageID+"as first ancestry") |
|
| 52 | 52 |
assertEqual(t, hist[1], "77dbf71da1d00e3fbddc480176eac8994025630c6590d11cfc8fe1209c2a1d20", |
| 53 | 53 |
"Unexpected second ancestry") |
| 54 | 54 |
} |
| 55 | 55 |
|
| 56 | 56 |
func TestLookupRemoteImage(t *testing.T) {
|
| 57 | 57 |
r := spawnTestRegistrySession(t) |
| 58 |
- found := r.LookupRemoteImage(IMAGE_ID, makeURL("/v1/"), TOKEN)
|
|
| 58 |
+ found := r.LookupRemoteImage(imageID, makeURL("/v1/"), token)
|
|
| 59 | 59 |
assertEqual(t, found, true, "Expected remote lookup to succeed") |
| 60 |
- found = r.LookupRemoteImage("abcdef", makeURL("/v1/"), TOKEN)
|
|
| 60 |
+ found = r.LookupRemoteImage("abcdef", makeURL("/v1/"), token)
|
|
| 61 | 61 |
assertEqual(t, found, false, "Expected remote lookup to fail") |
| 62 | 62 |
} |
| 63 | 63 |
|
| 64 | 64 |
func TestGetRemoteImageJSON(t *testing.T) {
|
| 65 | 65 |
r := spawnTestRegistrySession(t) |
| 66 |
- json, size, err := r.GetRemoteImageJSON(IMAGE_ID, makeURL("/v1/"), TOKEN)
|
|
| 66 |
+ json, size, err := r.GetRemoteImageJSON(imageID, makeURL("/v1/"), token)
|
|
| 67 | 67 |
if err != nil {
|
| 68 | 68 |
t.Fatal(err) |
| 69 | 69 |
} |
| ... | ... |
@@ -72,7 +75,7 @@ func TestGetRemoteImageJSON(t *testing.T) {
|
| 72 | 72 |
t.Fatal("Expected non-empty json")
|
| 73 | 73 |
} |
| 74 | 74 |
|
| 75 |
- _, _, err = r.GetRemoteImageJSON("abcdef", makeURL("/v1/"), TOKEN)
|
|
| 75 |
+ _, _, err = r.GetRemoteImageJSON("abcdef", makeURL("/v1/"), token)
|
|
| 76 | 76 |
if err == nil {
|
| 77 | 77 |
t.Fatal("Expected image not found error")
|
| 78 | 78 |
} |
| ... | ... |
@@ -80,7 +83,7 @@ func TestGetRemoteImageJSON(t *testing.T) {
|
| 80 | 80 |
|
| 81 | 81 |
func TestGetRemoteImageLayer(t *testing.T) {
|
| 82 | 82 |
r := spawnTestRegistrySession(t) |
| 83 |
- data, err := r.GetRemoteImageLayer(IMAGE_ID, makeURL("/v1/"), TOKEN, 0)
|
|
| 83 |
+ data, err := r.GetRemoteImageLayer(imageID, makeURL("/v1/"), token, 0)
|
|
| 84 | 84 |
if err != nil {
|
| 85 | 85 |
t.Fatal(err) |
| 86 | 86 |
} |
| ... | ... |
@@ -88,7 +91,7 @@ func TestGetRemoteImageLayer(t *testing.T) {
|
| 88 | 88 |
t.Fatal("Expected non-nil data result")
|
| 89 | 89 |
} |
| 90 | 90 |
|
| 91 |
- _, err = r.GetRemoteImageLayer("abcdef", makeURL("/v1/"), TOKEN, 0)
|
|
| 91 |
+ _, err = r.GetRemoteImageLayer("abcdef", makeURL("/v1/"), token, 0)
|
|
| 92 | 92 |
if err == nil {
|
| 93 | 93 |
t.Fatal("Expected image not found error")
|
| 94 | 94 |
} |
| ... | ... |
@@ -96,14 +99,14 @@ func TestGetRemoteImageLayer(t *testing.T) {
|
| 96 | 96 |
|
| 97 | 97 |
func TestGetRemoteTags(t *testing.T) {
|
| 98 | 98 |
r := spawnTestRegistrySession(t) |
| 99 |
- tags, err := r.GetRemoteTags([]string{makeURL("/v1/")}, REPO, TOKEN)
|
|
| 99 |
+ tags, err := r.GetRemoteTags([]string{makeURL("/v1/")}, REPO, token)
|
|
| 100 | 100 |
if err != nil {
|
| 101 | 101 |
t.Fatal(err) |
| 102 | 102 |
} |
| 103 | 103 |
assertEqual(t, len(tags), 1, "Expected one tag") |
| 104 |
- assertEqual(t, tags["latest"], IMAGE_ID, "Expected tag latest to map to "+IMAGE_ID) |
|
| 104 |
+ assertEqual(t, tags["latest"], imageID, "Expected tag latest to map to "+imageID) |
|
| 105 | 105 |
|
| 106 |
- _, err = r.GetRemoteTags([]string{makeURL("/v1/")}, "foo42/baz", TOKEN)
|
|
| 106 |
+ _, err = r.GetRemoteTags([]string{makeURL("/v1/")}, "foo42/baz", token)
|
|
| 107 | 107 |
if err == nil {
|
| 108 | 108 |
t.Fatal("Expected error when fetching tags for bogus repo")
|
| 109 | 109 |
} |
| ... | ... |
@@ -111,11 +114,11 @@ func TestGetRemoteTags(t *testing.T) {
|
| 111 | 111 |
|
| 112 | 112 |
func TestGetRepositoryData(t *testing.T) {
|
| 113 | 113 |
r := spawnTestRegistrySession(t) |
| 114 |
- parsedUrl, err := url.Parse(makeURL("/v1/"))
|
|
| 114 |
+ parsedURL, err := url.Parse(makeURL("/v1/"))
|
|
| 115 | 115 |
if err != nil {
|
| 116 | 116 |
t.Fatal(err) |
| 117 | 117 |
} |
| 118 |
- host := "http://" + parsedUrl.Host + "/v1/" |
|
| 118 |
+ host := "http://" + parsedURL.Host + "/v1/" |
|
| 119 | 119 |
data, err := r.GetRepositoryData("foo42/bar")
|
| 120 | 120 |
if err != nil {
|
| 121 | 121 |
t.Fatal(err) |
| ... | ... |
@@ -137,7 +140,7 @@ func TestPushImageJSONRegistry(t *testing.T) {
|
| 137 | 137 |
Checksum: "sha256:1ac330d56e05eef6d438586545ceff7550d3bdcb6b19961f12c5ba714ee1bb37", |
| 138 | 138 |
} |
| 139 | 139 |
|
| 140 |
- err := r.PushImageJSONRegistry(imgData, []byte{0x42, 0xdf, 0x0}, makeURL("/v1/"), TOKEN)
|
|
| 140 |
+ err := r.PushImageJSONRegistry(imgData, []byte{0x42, 0xdf, 0x0}, makeURL("/v1/"), token)
|
|
| 141 | 141 |
if err != nil {
|
| 142 | 142 |
t.Fatal(err) |
| 143 | 143 |
} |
| ... | ... |
@@ -146,7 +149,7 @@ func TestPushImageJSONRegistry(t *testing.T) {
|
| 146 | 146 |
func TestPushImageLayerRegistry(t *testing.T) {
|
| 147 | 147 |
r := spawnTestRegistrySession(t) |
| 148 | 148 |
layer := strings.NewReader("")
|
| 149 |
- _, _, err := r.PushImageLayerRegistry(IMAGE_ID, layer, makeURL("/v1/"), TOKEN, []byte{})
|
|
| 149 |
+ _, _, err := r.PushImageLayerRegistry(imageID, layer, makeURL("/v1/"), token, []byte{})
|
|
| 150 | 150 |
if err != nil {
|
| 151 | 151 |
t.Fatal(err) |
| 152 | 152 |
} |
| ... | ... |
@@ -180,7 +183,7 @@ func TestResolveRepositoryName(t *testing.T) {
|
| 180 | 180 |
|
| 181 | 181 |
func TestPushRegistryTag(t *testing.T) {
|
| 182 | 182 |
r := spawnTestRegistrySession(t) |
| 183 |
- err := r.PushRegistryTag("foo42/bar", IMAGE_ID, "stable", makeURL("/v1/"), TOKEN)
|
|
| 183 |
+ err := r.PushRegistryTag("foo42/bar", imageID, "stable", makeURL("/v1/"), token)
|
|
| 184 | 184 |
if err != nil {
|
| 185 | 185 |
t.Fatal(err) |
| 186 | 186 |
} |
| ... | ... |
@@ -3,6 +3,7 @@ package registry |
| 3 | 3 |
import ( |
| 4 | 4 |
"bytes" |
| 5 | 5 |
"crypto/sha256" |
| 6 |
+ // this is required for some certificates |
|
| 6 | 7 |
_ "crypto/sha512" |
| 7 | 8 |
"encoding/hex" |
| 8 | 9 |
"encoding/json" |
| ... | ... |
@@ -243,11 +244,11 @@ func (r *Session) GetRemoteTags(registries []string, repository string, token [] |
| 243 | 243 |
|
| 244 | 244 |
func buildEndpointsList(headers []string, indexEp string) ([]string, error) {
|
| 245 | 245 |
var endpoints []string |
| 246 |
- parsedUrl, err := url.Parse(indexEp) |
|
| 246 |
+ parsedURL, err := url.Parse(indexEp) |
|
| 247 | 247 |
if err != nil {
|
| 248 | 248 |
return nil, err |
| 249 | 249 |
} |
| 250 |
- var urlScheme = parsedUrl.Scheme |
|
| 250 |
+ var urlScheme = parsedURL.Scheme |
|
| 251 | 251 |
// The Registry's URL scheme has to match the Index' |
| 252 | 252 |
for _, ep := range headers {
|
| 253 | 253 |
epList := strings.Split(ep, ",") |