Skip to content

Commit

Permalink
Merge pull request moby#4 from jlhawn/vbatts-v2_hacking
Browse files Browse the repository at this point in the history
Vbatts v2 hacking
  • Loading branch information
vbatts committed Aug 29, 2014
2 parents 79b2ed0 + bcbb00d commit 4e99c9b
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 11 deletions.
13 changes: 8 additions & 5 deletions registry/session_prov.go
Expand Up @@ -7,7 +7,6 @@ import (
"io/ioutil"
"log"
"net/url"
"strings"

"github.com/docker/docker/registry/v2/routes"
"github.com/docker/docker/utils"
Expand Down Expand Up @@ -67,12 +66,16 @@ func (r *Session) GetV2Version(token []string) (*RegistryInfo, error) {
if res.StatusCode != 200 {
return nil, utils.NewHTTPRequestError(fmt.Sprintf("Server error: %d fetching Version", res.StatusCode), res)
}
buf, err := ioutil.ReadAll(res.Body)

decoder := json.NewDecoder(res.Body)
versionInfo := new(RegistryInfo)

err = decoder.Decode(versionInfo)
if err != nil {
return nil, err
return nil, fmt.Errorf("unable to decode GetV2Version JSON response: %s", err)
}

return &RegistryInfo{Version: strings.TrimSpace(string(buf))}, nil
return versionInfo, nil
}

//
Expand Down Expand Up @@ -197,7 +200,7 @@ func (r *Session) PutV2ImageBlob(imageName, sumType string, blobRdr io.Reader, t
return "", err
}
defer res.Body.Close()
if res.StatusCode != 200 {
if res.StatusCode != 201 {
if res.StatusCode == 401 {
return "", errLoginRequired
}
Expand Down
15 changes: 9 additions & 6 deletions registry/v2/routes/router.go
Expand Up @@ -16,22 +16,25 @@ const (
func NewRegistryRouter() *mux.Router {
router := mux.NewRouter()

v2Route := router.PathPrefix("/v2/").Subrouter()
v2Router := router.PathPrefix("/v2/").Subrouter()

// Version Info
v2Router.Path("/version").Name(VersionRoutename)

// Image Manifests
v2Route.Path("/manifest/{imagename:[a-z0-9-._/]+}/{tagname:[a-zA-Z0-9-._]+}").Name(ManifestsRouteName)
v2Router.Path("/manifest/{imagename:[a-z0-9-._/]+}/{tagname:[a-zA-Z0-9-._]+}").Name(ManifestsRouteName)

// List Image Tags
v2Route.Path("/tags/{imagename:[a-z0-9-._/]+}").Name(TagsRouteName)
v2Router.Path("/tags/{imagename:[a-z0-9-._/]+}").Name(TagsRouteName)

// Download a blob
v2Route.Path("/blob/{imagename:[a-z0-9-._/]+}/{sumtype:[a-z0-9_+-]+}/{sum:[a-fA-F0-9]{4,}}").Name(DownloadBlobRouteName)
v2Router.Path("/blob/{imagename:[a-z0-9-._/]+}/{sumtype:[a-z0-9_+-]+}/{sum:[a-fA-F0-9]{4,}}").Name(DownloadBlobRouteName)

// Upload a blob
v2Route.Path("/blob/{imagename:[a-z0-9-._/]+}/{sumtype:[a-z0-9_+-]+}").Name(UploadBlobRouteName)
v2Router.Path("/blob/{imagename:[a-z0-9-._/]+}/{sumtype:[a-z0-9_+-]+}").Name(UploadBlobRouteName)

// Mounting a blob in an image
v2Route.Path("/mountblob/{imagename:[a-z0-9-._/]+}/{sumtype:[a-z0-9_+-]+}/{sum:[a-fA-F0-9]{4,}}").Name(MountBlobRouteName)
v2Router.Path("/mountblob/{imagename:[a-z0-9-._/]+}/{sumtype:[a-z0-9_+-]+}/{sum:[a-fA-F0-9]{4,}}").Name(MountBlobRouteName)

return router
}
3 changes: 3 additions & 0 deletions registry/v2/server/set_handlers.go
Expand Up @@ -9,6 +9,9 @@ import (

func setRegistryRouteHandlers(registryRouter *mux.Router) {
routeHandlers := map[string]map[string]http.Handler{
routes.VersionRoutename: {
"GET": http.HandlerFunc(getVersion),
},
routes.ManifestsRouteName: {
"GET": http.HandlerFunc(getManifest),
"PUT": http.HandlerFunc(putManifest),
Expand Down
25 changes: 25 additions & 0 deletions registry/v2/server/version.go
@@ -0,0 +1,25 @@
package server

import (
"encoding/json"
"log"
"net/http"

"github.com/docker/docker/registry"
)

func getVersion(w http.ResponseWriter, r *http.Request) {
log.Println("Get Version")

versionInfo := &registry.RegistryInfo{
Version: "2.0",
Standalone: true,
}

encoder := json.NewEncoder(w)
err := encoder.Encode(versionInfo)
if err != nil {
log.Printf("unable to JSON encode version info: %s\n", err)
w.WriteHeader(500)
}
}

0 comments on commit 4e99c9b

Please sign in to comment.