Example #1
0
func handlerBlob(w http.ResponseWriter, r *http.Request) {
	if !checkAuth(w, r) {
		return
	}

	vars := mux.Vars(r)
	_, exists := vars["repo"]
	if !exists {
		http.NotFound(w, r)
		return
	}

	_, exists = vars["image_name"]
	if !exists {
		http.NotFound(w, r)
		return
	}

	blobRef, exists := vars["blob_ref"]
	if !exists {
		http.NotFound(w, r)
		return
	}

	// Just write back the blob reference; completely fake content, not even a tar.
	io.WriteString(w, blobRef)
}
Example #2
0
func handlerImageManifest(w http.ResponseWriter, r *http.Request) {
	if !checkAuth(w, r) {
		return
	}

	vars := mux.Vars(r)
	repo, exists := vars["repo"]
	if !exists {
		http.NotFound(w, r)
		return
	}

	imageName, exists := vars["image_name"]
	if !exists {
		http.NotFound(w, r)
		return
	}

	// Tag or digest.
	imageRef, exists := vars["image_ref"]
	if !exists {
		http.NotFound(w, r)
		return
	}

	manifest, exists := testImageManifests[fmt.Sprintf("%s/%s:%s", repo, imageName, imageRef)]
	if !exists {
		http.NotFound(w, r)
		return
	}
	io.WriteString(w, manifest)
}
Example #3
0
func handlerTags(w http.ResponseWriter, r *http.Request) {
	if !checkAuth(w, r) {
		return
	}

	vars := mux.Vars(r)
	tags, exists := testRepositories[vars["repository"]]
	if !exists {
		http.NotFound(w, r)
		return
	}

	writeResponse(w, 200, tags)
}
Example #4
0
func handlerImage(w http.ResponseWriter, r *http.Request) {
	if !checkAuth(w, r) {
		return
	}

	vars := mux.Vars(r)
	layer, exists := testLayers[vars["image_id"]]
	if !exists {
		http.NotFound(w, r)
		return
	}

	layer_size := len(layer["layer"])
	w.Header().Add("X-Docker-Size", strconv.Itoa(layer_size))
	io.WriteString(w, layer[vars["data_type"]])
}