Permalink
Browse files

re-organised controller code

  • Loading branch information...
1 parent 7e71a97 commit 7457e7c9ddf6a4b5b8d63c74ff2e82cca301d506 @jaredwilkening jaredwilkening committed Jul 9, 2013
View
106 README.md
@@ -19,7 +19,7 @@ Shock is actively being developed at [github.com/MG-RAST/Shock](http://github.co
<br>
Building:
---------
-Shock (requires go=>1.0.0 [golang.org/doc/install/source](http://golang.org/doc/install/source), git, mercurial, bazaar):
+Shock (requires go=>1.1.0 [golang.org](http://golang.org/), git, mercurial, bazaar):
go get github.com/MG-RAST/Shock/...
@@ -114,8 +114,6 @@ Routes Overview
- [/node/{id}](#get_node) view node, download file (full or partial)
- [/node/{id}/acl]() view node acls
- [/node/{id}/acl/{type}]() view node acls of type {type}
-- [/user](#get_users) list users (admin users only)
-- [/user/{id}](#get_user) view user
#####PUT
@@ -126,7 +124,6 @@ Routes Overview
#####POST
- [/node](#post_node) create node
-- [/user](#post_user) create user
#####DELETE
@@ -144,22 +141,11 @@ Routes Overview
Authentication:
---------------
-Shock currently supports two forms of Authentication. Http Basic Auth with local user support and Globus Online Nexus oauth implementation. See configuration for more details.
-
-### Basic Auth
-In this configuration Shock locally stores user information. Users must create accounts via the [user api](#post_user). Once this is done they can pass basic auth headers to authenticate.
-
-Example
-
- curl --user username:password ...
-
-<br>
+Shock supports multiple forms of Authentication via plugin modules. Credentials are cached for 1 hour to speed up high transaction loads. Server restarts will clear the credential cache.
### Globus Online
In this configuration Shock locally stores only uuids for users that it has already seen. The registration of new users is done exclusively with the external auth provider. The user api is disabled in this mode.
-__Note__: Using the basic auth method shown below is significantly slower than the bearer token. Its highly discouraged for large numbers of request.
-
Examples:
# globus online username & password
@@ -204,27 +190,6 @@ Data Types
"status": 200
}
-<br>
-### User:
-
-- uuid: unique identifier
-- name: username
-- passwd: all responds are masked "**********"
-- admin: boolean
-
-##### user example:
-
- {
- "data": {
- "uuid": "67394386a4acac62fdb851d78691ee48"
- "name": "joeuser",
- "passwd": "**********",
- "admin": false,
- },
- "error": null,
- "status": 200
- }
-
<br>
### Index:
@@ -514,73 +479,6 @@ Modify node, create index
"status": <http status of request>
}
-<a name="post_user"/>
-<br>
-### POST /user
-
-Create user (basic auth only)
-
-Requires Basic Auth encoded as 'username:password'. To create an admin user 'username:password:secret-key:true' where secret-key was specified at server start.
-
-##### example
-
- # regular user (when config Anonymous:create-user=true)
- curl -X POST --user joeuser:1234 http://<host>[:<port>]/user
-
- # regular user (when config Anonymous:create-user=false)
- curl -X POST --user joeuser:1234:supersupersecret:false http://<host>[:<port>]/user
-
- # admin user
- curl -X POST --user joeuser:1234:supersupersecret:true http://<host>[:<port>]/user
-
-##### returns
-
- {
- "data": {<user>},
- "error": <error message or null>,
- "status": <http status of request>
- }
-
-<a name="get_user"/>
-<br>
-### GET /user/{id}
-
-View user (basic auth only)
-
-Requires Basic Auth encoded username:password. Regular user are able to see their own information while Admin user are able to access all.
-
-##### example
-
- curl -X GET --user joeuser:1234 http://<host>[:<port>]/user/{id}
-
-##### returns
-
- {
- "data": {<user>},
- "error": <error message or null>,
- "status": <http status of request>
- }
-
-<a name="get_users"/>
-<br>
-### GET /user
-
-List users (basic auth only)
-
-Requires Basic Auth encoded username:password. Restricted to Admin users.
-
-##### example
-
- curl -X GET --user joeadmin:12345 http://<host>[:<port>]/user
-
-##### returns
-
- {
- "data": {[<user>,...]},
- "error": <error message or null>,
- "status": <http status of request>
- }
-
<br>
License
---
@@ -0,0 +1,22 @@
+package controller
+
+import (
+ "github.com/MG-RAST/Shock/shock-server/controller/node"
+ "github.com/MG-RAST/Shock/shock-server/controller/node/acl"
+ "github.com/MG-RAST/Shock/shock-server/controller/preauth"
+ "github.com/jaredwilkening/goweb"
+)
+
+type Controller struct {
+ Node *node.Controller
+ Acl map[string]goweb.ControllerFunc
+ Preauth func(*goweb.Context)
+}
+
+func New() *Controller {
+ return &Controller{
+ Node: new(node.Controller),
+ Acl: map[string]goweb.ControllerFunc{"base": acl.Controller, "typed": acl.ControllerTyped},
+ Preauth: preauth.PreAuthRequest,
+ }
+}
@@ -1,9 +1,11 @@
-package main
+package acl
import (
"errors"
e "github.com/MG-RAST/Shock/shock-server/errors"
+ "github.com/MG-RAST/Shock/shock-server/logger"
"github.com/MG-RAST/Shock/shock-server/node"
+ "github.com/MG-RAST/Shock/shock-server/request"
"github.com/MG-RAST/Shock/shock-server/user"
"github.com/jaredwilkening/goweb"
"net/http"
@@ -15,11 +17,11 @@ var (
)
// GET, POST, PUT, DELETE: /node/{nid}/acl/
-var AclController goweb.ControllerFunc = func(cx *goweb.Context) {
- LogRequest(cx.Request)
- u, err := AuthenticateRequest(cx.Request)
+var Controller goweb.ControllerFunc = func(cx *goweb.Context) {
+ request.Log(cx.Request)
+ u, err := request.Authenticate(cx.Request)
if err != nil && err.Error() != e.NoAuth {
- handleAuthError(err, cx)
+ request.AuthError(err, cx)
return
}
@@ -42,7 +44,7 @@ var AclController goweb.ControllerFunc = func(cx *goweb.Context) {
} else {
// In theory the db connection could be lost between
// checking user and load but seems unlikely.
- log.Error("Err@node_Read:LoadNode: " + err.Error())
+ logger.Error("Err@node_Read:LoadNode: " + err.Error())
cx.RespondWithError(http.StatusInternalServerError)
return
}
@@ -85,11 +87,11 @@ var AclController goweb.ControllerFunc = func(cx *goweb.Context) {
}
// GET, POST, PUT, DELETE: /node/{nid}/acl/{type}
-var AclControllerTyped goweb.ControllerFunc = func(cx *goweb.Context) {
- LogRequest(cx.Request)
- u, err := AuthenticateRequest(cx.Request)
+var ControllerTyped goweb.ControllerFunc = func(cx *goweb.Context) {
+ request.Log(cx.Request)
+ u, err := request.Authenticate(cx.Request)
if err != nil && err.Error() != e.NoAuth {
- handleAuthError(err, cx)
+ request.AuthError(err, cx)
return
}
@@ -118,7 +120,7 @@ var AclControllerTyped goweb.ControllerFunc = func(cx *goweb.Context) {
} else {
// In theory the db connection could be lost between
// checking user and load but seems unlikely.
- log.Error("Err@node_Read:LoadNode: " + err.Error())
+ logger.Error("Err@node_Read:LoadNode: " + err.Error())
cx.RespondWithError(http.StatusInternalServerError)
return
}
@@ -182,8 +184,8 @@ var AclControllerTyped goweb.ControllerFunc = func(cx *goweb.Context) {
func parseAclRequest(cx *goweb.Context) (ids map[string][]string, err error) {
ids = map[string][]string{}
users := map[string][]string{}
- query := &Query{list: cx.Request.URL.Query()}
- params, _, err := ParseMultipartForm(cx.Request)
+ query := request.Q(cx.Request.URL.Query())
+ params, _, err := request.ParseMultipartForm(cx.Request)
if err != nil && err.Error() == "request Content-Type isn't multipart/form-data" && (query.Has("all") || query.Has("read") || query.Has("write") || query.Has("delete")) {
if query.Has("all") {
users["all"] = strings.Split(query.Value("all"), ",")
@@ -233,8 +235,8 @@ func parseAclRequest(cx *goweb.Context) (ids map[string][]string, err error) {
func parseAclRequestTyped(cx *goweb.Context) (ids []string, err error) {
var users []string
- query := &Query{list: cx.Request.URL.Query()}
- params, _, err := ParseMultipartForm(cx.Request)
+ query := request.Q(cx.Request.URL.Query())
+ params, _, err := request.ParseMultipartForm(cx.Request)
if err != nil && err.Error() == "request Content-Type isn't multipart/form-data" && query.Has("users") {
users = strings.Split(query.Value("users"), ",")
} else if params["users"] != "" {
Oops, something went wrong.

0 comments on commit 7457e7c

Please sign in to comment.