Skip to content
This repository has been archived by the owner on Apr 26, 2021. It is now read-only.

Commit

Permalink
Change API's pattern muxer and improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
scorphus committed Aug 28, 2014
1 parent a4e6c86 commit 1a58fbc
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 117 deletions.
12 changes: 10 additions & 2 deletions Godeps/Godeps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions api/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"strconv"
"strings"

"github.com/gorilla/pat"
"github.com/tsuru/config"
"github.com/tsuru/gandalf/db"
"github.com/tsuru/gandalf/hook"
Expand Down Expand Up @@ -55,6 +56,32 @@ func accessParameters(body io.ReadCloser) (repositories, users []string, err err
return repositories, users, nil
}

func SetupRouter() *pat.Router {
router := pat.New()
router.Post("/user/{name}/key", http.HandlerFunc(AddKey))
router.Delete("/user/{name}/key/{keyname}", http.HandlerFunc(RemoveKey))
router.Get("/user/{name}/keys", http.HandlerFunc(ListKeys))
router.Post("/user", http.HandlerFunc(NewUser))
router.Delete("/user/{name}", http.HandlerFunc(RemoveUser))
router.Post("/repository/grant", http.HandlerFunc(GrantAccess))
router.Post("/repository", http.HandlerFunc(NewRepository))
router.Delete("/repository/revoke", http.HandlerFunc(RevokeAccess))
router.Delete("/repository/{name}", http.HandlerFunc(RemoveRepository))
router.Get("/repository/{name}", http.HandlerFunc(GetRepository))
router.Put("/repository/{name}", http.HandlerFunc(RenameRepository))
router.Get("/repository/{name}/archive", http.HandlerFunc(GetArchive))
router.Get("/repository/{name}/contents", http.HandlerFunc(GetFileContents))
router.Get("/repository/{name}/tree", http.HandlerFunc(GetTree))
router.Get("/repository/{name}/branches", http.HandlerFunc(GetBranches))
router.Get("/repository/{name}/tags", http.HandlerFunc(GetTags))
router.Get("/repository/{name}/diff/commits", http.HandlerFunc(GetDiff))
router.Post("/repository/{name}/commit", http.HandlerFunc(Commit))
router.Get("/repository/{name}/logs", http.HandlerFunc(GetLog))
router.Get("/healthcheck", http.HandlerFunc(HealthCheck))
router.Post("/hook/{name}", http.HandlerFunc(AddHook))
return router
}

func GrantAccess(w http.ResponseWriter, r *http.Request) {
// TODO: update README
repositories, users, err := accessParameters(r.Body)
Expand Down
Loading

0 comments on commit 1a58fbc

Please sign in to comment.