controller

package
v0.9.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 19, 2014 License: BSD-2-Clause Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ClientGroupAclController goweb.ControllerFunc = func(cx *goweb.Context) {
	LogRequest(cx.Request)

	if cx.Request.Method == "OPTIONS" {
		cx.RespondWithOK()
		return
	}

	u, err := request.Authenticate(cx.Request)
	if err != nil && err.Error() != e.NoAuth {
		cx.RespondWithErrorMessage(err.Error(), http.StatusUnauthorized)
		return
	}

	if u == nil {
		if conf.ANON_CG_READ == true {
			u = &user.User{Uuid: "public"}
		} else {
			cx.RespondWithErrorMessage(e.NoAuth, http.StatusUnauthorized)
			return
		}
	}

	cgid := cx.PathParams["cgid"]

	cg, err := core.LoadClientGroup(cgid)

	if err != nil {
		if err == mgo.ErrNotFound {
			cx.RespondWithNotFound()
			return
		} else {

			cx.RespondWithErrorMessage("clientgroup not found: "+cgid, http.StatusBadRequest)
			return
		}
	}

	if cg.Acl.Owner != u.Uuid && u.Admin == false {
		cx.RespondWithErrorMessage(e.UnAuth, http.StatusUnauthorized)
		return
	}

	if cx.Request.Method == "GET" {
		cx.RespondWithData(cg.Acl)
	} else {
		cx.RespondWithErrorMessage("This request type is not implemented.", http.StatusNotImplemented)
	}
	return
}

GET: /cgroup/{cgid}/acl/ (only GET and OPTIONS are supported here)

View Source
var ClientGroupAclControllerTyped goweb.ControllerFunc = func(cx *goweb.Context) {
	LogRequest(cx.Request)

	if cx.Request.Method == "OPTIONS" {
		cx.RespondWithOK()
		return
	}

	u, err := request.Authenticate(cx.Request)
	if err != nil {
		cx.RespondWithErrorMessage(err.Error(), http.StatusUnauthorized)
		return
	}

	cgid := cx.PathParams["cgid"]
	rtype := cx.PathParams["type"]
	rmeth := cx.Request.Method

	if !validClientGroupAclTypes[rtype] {
		cx.RespondWithErrorMessage("Invalid acl type", http.StatusBadRequest)
		return
	}

	cg, err := core.LoadClientGroup(cgid)

	if err != nil {
		if err == mgo.ErrNotFound {
			cx.RespondWithNotFound()
		} else {

			cx.RespondWithErrorMessage("clientgroup not found: "+cgid, http.StatusBadRequest)
		}
		return
	}

	if cg.Acl.Owner != u.Uuid && u.Admin == false {
		if rmeth == "DELETE" {
			ids, err := parseClientGroupAclRequestTyped(cx)
			if err != nil {
				cx.RespondWithErrorMessage(err.Error(), http.StatusBadRequest)
				return
			}
			if len(ids) != 1 || (len(ids) == 1 && ids[0] != u.Uuid) {
				cx.RespondWithErrorMessage("Non-owners of clientgroups can delete one and only user from the ACLs (themselves)", http.StatusBadRequest)
				return
			}
			if rtype == "owner" {
				cx.RespondWithErrorMessage("Deleting ownership is not a supported request type.", http.StatusBadRequest)
				return
			} else if rtype == "all" {
				for _, atype := range []string{"read", "write", "delete", "execute"} {
					cg.Acl.UnSet(ids[0], map[string]bool{atype: true})
				}
			} else {
				cg.Acl.UnSet(ids[0], map[string]bool{rtype: true})
			}
			cg.Save()
			cx.RespondWithOK()
			return
		}
		cx.RespondWithErrorMessage("Users that are not clientgroup owners can only delete themselves from ACLs.", http.StatusBadRequest)
		return
	}

	if rmeth != "GET" {
		ids, err := parseClientGroupAclRequestTyped(cx)
		if err != nil {
			cx.RespondWithErrorMessage(err.Error(), http.StatusBadRequest)
			return
		}
		if rmeth == "POST" || rmeth == "PUT" {
			if rtype == "owner" {
				if len(ids) == 1 {
					cg.Acl.SetOwner(ids[0])
				} else {
					cx.RespondWithErrorMessage("Too many users. Clientgroups may have only one owner.", http.StatusBadRequest)
					return
				}
			} else if rtype == "all" {
				for _, atype := range []string{"read", "write", "delete", "execute"} {
					for _, i := range ids {
						cg.Acl.Set(i, map[string]bool{atype: true})
					}
				}
			} else if rtype == "public_read" {
				cg.Acl.Set("public", map[string]bool{"read": true})
			} else if rtype == "public_write" {
				cg.Acl.Set("public", map[string]bool{"write": true})
			} else if rtype == "public_delete" {
				cg.Acl.Set("public", map[string]bool{"delete": true})
			} else if rtype == "public_execute" {
				cg.Acl.Set("public", map[string]bool{"execute": true})
			} else if rtype == "public_all" {
				for _, atype := range []string{"read", "write", "delete", "execute"} {
					cg.Acl.Set("public", map[string]bool{atype: true})
				}
			} else {
				for _, i := range ids {
					cg.Acl.Set(i, map[string]bool{rtype: true})
				}
			}
			cg.Save()
		} else if rmeth == "DELETE" {
			if rtype == "owner" {
				cx.RespondWithErrorMessage("Deleting ownership is not a supported request type.", http.StatusBadRequest)
				return
			} else if rtype == "all" {
				for _, atype := range []string{"read", "write", "delete", "execute"} {
					for _, i := range ids {
						cg.Acl.UnSet(i, map[string]bool{atype: true})
					}
				}
			} else if rtype == "public_read" {
				cg.Acl.UnSet("public", map[string]bool{"read": true})
			} else if rtype == "public_write" {
				cg.Acl.UnSet("public", map[string]bool{"write": true})
			} else if rtype == "public_delete" {
				cg.Acl.UnSet("public", map[string]bool{"delete": true})
			} else if rtype == "public_execute" {
				cg.Acl.UnSet("public", map[string]bool{"execute": true})
			} else if rtype == "public_all" {
				for _, atype := range []string{"read", "write", "delete", "execute"} {
					cg.Acl.UnSet("public", map[string]bool{atype: true})
				}
			} else {
				for _, i := range ids {
					cg.Acl.UnSet(i, map[string]bool{rtype: true})
				}
			}
			cg.Save()
		} else {
			cx.RespondWithErrorMessage("This request type is not implemented.", http.StatusNotImplemented)
			return
		}
	}

	switch rtype {
	default:
		cx.RespondWithErrorMessage("This request type is not implemented.", http.StatusNotImplemented)
	case "owner":
		cx.RespondWithData(map[string]string{"owner": cg.Acl.Owner})
	case "read", "public_read":
		cx.RespondWithData(map[string][]string{"read": cg.Acl.Read})
	case "write", "public_write":
		cx.RespondWithData(map[string][]string{"write": cg.Acl.Write})
	case "delete", "public_delete":
		cx.RespondWithData(map[string][]string{"delete": cg.Acl.Delete})
	case "execute", "public_execute":
		cx.RespondWithData(map[string][]string{"execute": cg.Acl.Execute})
	case "all", "public_all":
		cx.RespondWithData(cg.Acl)
	}

	return
}

GET, POST, PUT, DELETE, OPTIONS: /cgroup/{cgid}/acl/{type}

View Source
var ClientGroupTokenController goweb.ControllerFunc = func(cx *goweb.Context) {
	LogRequest(cx.Request)

	if cx.Request.Method == "OPTIONS" {
		cx.RespondWithOK()
		return
	}

	u, err := request.Authenticate(cx.Request)
	if err != nil && err.Error() != e.NoAuth {
		cx.RespondWithErrorMessage(err.Error(), http.StatusUnauthorized)
		return
	}

	if u == nil {
		if conf.ANON_CG_WRITE == true {
			u = &user.User{Uuid: "public"}
		} else {
			cx.RespondWithErrorMessage(e.UnAuth, http.StatusUnauthorized)
			return
		}
	}

	cgid := cx.PathParams["cgid"]
	cg, err := core.LoadClientGroup(cgid)

	if err != nil {
		if err == mgo.ErrNotFound {
			cx.RespondWithNotFound()
		} else {

			cx.RespondWithErrorMessage("clientgroup id not found:"+cgid, http.StatusBadRequest)
		}
		return
	}

	rights := cg.Acl.Check(u.Uuid)
	public_rights := cg.Acl.Check("public")
	if (u.Uuid != "public" && (cg.Acl.Owner == u.Uuid || rights["write"] == true || u.Admin == true || public_rights["write"] == true)) ||
		(u.Uuid == "public" && conf.ANON_CG_WRITE == true && public_rights["write"] == true) {

		switch cx.Request.Method {
		case "PUT":
			if cg.Token != "" {
				cx.RespondWithErrorMessage("Clientgroup has existing token.  This must be deleted before a new token can be generated.", http.StatusBadRequest)
				return
			}
			cg.SetToken()
			if err = cg.Save(); err != nil {
				cx.RespondWithErrorMessage("Could not save clientgroup.", http.StatusInternalServerError)
				return
			}
			cx.RespondWithData(cg)
			return
		case "DELETE":
			cg.Token = ""
			if err = cg.Save(); err != nil {
				cx.RespondWithErrorMessage("Could not save clientgroup.", http.StatusInternalServerError)
				return
			}
			cx.RespondWithData(cg)
			return
		default:
			cx.RespondWithError(http.StatusNotImplemented)
			return
		}
	}

	cx.RespondWithErrorMessage(e.UnAuth, http.StatusUnauthorized)
	return
}

GET, POST, PUT, DELETE, OPTIONS: /cgroup/{cgid}/token/ (only OPTIONS, PUT and DELETE are implemented)

View Source
var JobAclController goweb.ControllerFunc = func(cx *goweb.Context) {
	LogRequest(cx.Request)

	if cx.Request.Method == "OPTIONS" {
		cx.RespondWithOK()
		return
	}

	jid := cx.PathParams["jid"]

	u, err := request.Authenticate(cx.Request)
	if err != nil && err.Error() != e.NoAuth {
		cx.RespondWithErrorMessage(err.Error(), http.StatusUnauthorized)
		return
	}

	if u == nil {
		if conf.ANON_READ == true {
			u = &user.User{Uuid: "public"}
		} else {
			cx.RespondWithErrorMessage(e.NoAuth, http.StatusUnauthorized)
			return
		}
	}

	job, err := core.LoadJob(jid)
	if err != nil {
		if err == mgo.ErrNotFound {
			cx.RespondWithNotFound()
		} else {

			cx.RespondWithErrorMessage("job not found: "+jid, http.StatusBadRequest)
		}
		return
	}

	if job.Acl.Owner != u.Uuid && u.Admin == false && job.Acl.Owner != "public" {
		cx.RespondWithErrorMessage(e.UnAuth, http.StatusUnauthorized)
		return
	}

	if cx.Request.Method == "GET" {
		cx.RespondWithData(job.Acl)
	} else {
		cx.RespondWithErrorMessage("This request type is not implemented.", http.StatusNotImplemented)
	}
	return
}

GET: /job/{jid}/acl/ (only OPTIONS and GET are supported here)

View Source
var JobAclControllerTyped goweb.ControllerFunc = func(cx *goweb.Context) {
	LogRequest(cx.Request)

	if cx.Request.Method == "OPTIONS" {
		cx.RespondWithOK()
		return
	}

	u, err := request.Authenticate(cx.Request)
	if err != nil {
		cx.RespondWithErrorMessage(err.Error(), http.StatusUnauthorized)
		return
	}

	jid := cx.PathParams["jid"]
	rtype := cx.PathParams["type"]
	rmeth := cx.Request.Method

	if rtype != "all" && rtype != "owner" && rtype != "read" && rtype != "write" && rtype != "delete" {
		cx.RespondWithErrorMessage("Invalid acl type", http.StatusBadRequest)
		return
	}

	job, err := core.LoadJob(jid)

	if err != nil {
		if err == mgo.ErrNotFound {
			cx.RespondWithNotFound()
		} else {
			cx.RespondWithErrorMessage("job not found: "+jid, http.StatusBadRequest)
		}
		return
	}

	if job.Acl.Owner != u.Uuid && u.Admin == false {
		if rmeth == "DELETE" {
			ids, err := parseJobAclRequestTyped(cx)
			if err != nil {
				cx.RespondWithErrorMessage(err.Error(), http.StatusBadRequest)
				return
			}
			if len(ids) != 1 || (len(ids) == 1 && ids[0] != u.Uuid) {
				cx.RespondWithErrorMessage("Non-owners of a job can delete one and only user from the ACLs (themselves).", http.StatusBadRequest)
				return
			}
			if rtype == "owner" {
				cx.RespondWithErrorMessage("Deleting job ownership is not a supported request type.", http.StatusBadRequest)
				return
			}
			if rtype == "all" {
				for _, atype := range []string{"read", "write", "delete"} {
					job.Acl.UnSet(ids[0], map[string]bool{atype: true})
				}
			} else {
				job.Acl.UnSet(ids[0], map[string]bool{rtype: true})
			}
			job.Save()
			cx.RespondWithOK()
			return
		}
		cx.RespondWithErrorMessage("Users that are not job owners can only delete themselves from ACLs.", http.StatusBadRequest)
		return
	}

	if rmeth != "GET" {
		ids, err := parseJobAclRequestTyped(cx)
		if err != nil {
			cx.RespondWithErrorMessage(err.Error(), http.StatusBadRequest)
			return
		}
		if rmeth == "POST" || rmeth == "PUT" {
			if rtype == "owner" {
				if len(ids) == 1 {
					job.Acl.SetOwner(ids[0])
				} else {
					cx.RespondWithErrorMessage("Too many users. Jobs may have only one owner.", http.StatusBadRequest)
					return
				}
			} else if rtype == "all" {
				for _, atype := range []string{"read", "write", "delete"} {
					for _, i := range ids {
						job.Acl.Set(i, map[string]bool{atype: true})
					}
				}
			} else if rtype == "public_read" {
				job.Acl.Set("public", map[string]bool{"read": true})
			} else if rtype == "public_write" {
				job.Acl.Set("public", map[string]bool{"write": true})
			} else if rtype == "public_delete" {
				job.Acl.Set("public", map[string]bool{"delete": true})
			} else if rtype == "public_all" {
				for _, atype := range []string{"read", "write", "delete"} {
					job.Acl.Set("public", map[string]bool{atype: true})
				}
			} else {
				for _, i := range ids {
					job.Acl.Set(i, map[string]bool{rtype: true})
				}
			}
			job.Save()
		} else if rmeth == "DELETE" {
			if rtype == "owner" {
				cx.RespondWithErrorMessage("Deleting ownership is not a supported request type.", http.StatusBadRequest)
				return
			} else if rtype == "all" {
				for _, atype := range []string{"read", "write", "delete", "execute"} {
					for _, i := range ids {
						job.Acl.UnSet(i, map[string]bool{atype: true})
					}
				}
			} else if rtype == "public_read" {
				job.Acl.UnSet("public", map[string]bool{"read": true})
			} else if rtype == "public_write" {
				job.Acl.UnSet("public", map[string]bool{"write": true})
			} else if rtype == "public_delete" {
				job.Acl.UnSet("public", map[string]bool{"delete": true})
			} else if rtype == "public_all" {
				for _, atype := range []string{"read", "write", "delete"} {
					job.Acl.UnSet("public", map[string]bool{atype: true})
				}
			} else {
				for _, i := range ids {
					job.Acl.UnSet(i, map[string]bool{rtype: true})
				}
			}
			job.Save()
		} else {
			cx.RespondWithErrorMessage("This request type is not implemented.", http.StatusNotImplemented)
			return
		}
	}

	switch rtype {
	default:
		cx.RespondWithErrorMessage("This request type is not implemented.", http.StatusNotImplemented)
	case "owner":
		cx.RespondWithData(map[string]string{"owner": job.Acl.Owner})
	case "read", "public_read":
		cx.RespondWithData(map[string][]string{"read": job.Acl.Read})
	case "write", "public_write":
		cx.RespondWithData(map[string][]string{"write": job.Acl.Write})
	case "delete", "public_delete":
		cx.RespondWithData(map[string][]string{"delete": job.Acl.Delete})
	case "all", "public_all":
		cx.RespondWithData(job.Acl)
	}

	return
}

GET, POST, PUT, DELETE, OPTIONS: /job/{jid}/acl/{type}

Functions

func AdminAuthenticated added in v0.9.3

func AdminAuthenticated(cx *goweb.Context) bool

func LogRequest

func LogRequest(req *http.Request)

func ParseMultipartForm

func ParseMultipartForm(r *http.Request) (params map[string]string, files core.FormFiles, err error)

helper function for create & update

func PrintLogo()

func RawDir

func RawDir(cx *goweb.Context)

func ResourceDescription

func ResourceDescription(cx *goweb.Context)

func RespondPrivateEnvInHeader added in v0.9.3

func RespondPrivateEnvInHeader(cx *goweb.Context, Envs map[string]string) (err error)

func RespondTokenInHeader

func RespondTokenInHeader(cx *goweb.Context, token string)

func SiteDir

func SiteDir(cx *goweb.Context)

Types

type AwfController

type AwfController struct{}

func (*AwfController) Options

func (cr *AwfController) Options(cx *goweb.Context)

OPTIONS: /awf

func (*AwfController) Read

func (cr *AwfController) Read(id string, cx *goweb.Context)

GET: /awf/{name} get a workflow by name, read-only

func (*AwfController) ReadMany

func (cr *AwfController) ReadMany(cx *goweb.Context)

GET: /awf get all loaded workflows

type ClientController

type ClientController struct{}

func (*ClientController) Create

func (cr *ClientController) Create(cx *goweb.Context)

POST: /client - register a new client

func (*ClientController) Delete

func (cr *ClientController) Delete(id string, cx *goweb.Context)

DELETE: /client/{id}

func (*ClientController) DeleteMany

func (cr *ClientController) DeleteMany(cx *goweb.Context)

DELETE: /client

func (*ClientController) Options

func (cr *ClientController) Options(cx *goweb.Context)

OPTIONS: /client

func (*ClientController) Read

func (cr *ClientController) Read(id string, cx *goweb.Context)

GET: /client/{id}

func (*ClientController) ReadMany

func (cr *ClientController) ReadMany(cx *goweb.Context)

GET: /client

func (*ClientController) Update

func (cr *ClientController) Update(id string, cx *goweb.Context)

PUT: /client/{id} -> status update

func (*ClientController) UpdateMany

func (cr *ClientController) UpdateMany(cx *goweb.Context)

PUT: /client

type ClientGroupController added in v0.9.3

type ClientGroupController struct{}

func (*ClientGroupController) CreateWithId added in v0.9.3

func (cr *ClientGroupController) CreateWithId(name string, cx *goweb.Context)

POST: /cgroup/{name}

func (*ClientGroupController) Delete added in v0.9.3

func (cr *ClientGroupController) Delete(id string, cx *goweb.Context)

DELETE: /cgroup/{id}

func (*ClientGroupController) Options added in v0.9.3

func (cr *ClientGroupController) Options(cx *goweb.Context)

OPTIONS: /cgroup

func (*ClientGroupController) Read added in v0.9.3

func (cr *ClientGroupController) Read(id string, cx *goweb.Context)

GET: /cgroup/{id}

func (*ClientGroupController) ReadMany added in v0.9.3

func (cr *ClientGroupController) ReadMany(cx *goweb.Context)

GET: /cgroup

type JobController

type JobController struct{}

func (*JobController) Create

func (cr *JobController) Create(cx *goweb.Context)

POST: /job

func (*JobController) Delete

func (cr *JobController) Delete(id string, cx *goweb.Context)

DELETE: /job/{id}

func (*JobController) DeleteMany

func (cr *JobController) DeleteMany(cx *goweb.Context)

DELETE: /job?suspend, /job?zombie

func (*JobController) Options

func (cr *JobController) Options(cx *goweb.Context)

OPTIONS: /job

func (*JobController) Read

func (cr *JobController) Read(id string, cx *goweb.Context)

GET: /job/{id}

func (*JobController) ReadMany

func (cr *JobController) ReadMany(cx *goweb.Context)

GET: /job To do: - Iterate job queries

func (*JobController) Update

func (cr *JobController) Update(id string, cx *goweb.Context)

PUT: /job/{id} -> used for job manipulation

func (*JobController) UpdateMany

func (cr *JobController) UpdateMany(cx *goweb.Context)

PUT: /job

type ProxyController

type ProxyController struct {
	Client *ClientController
	Work   *WorkController
}

func NewProxyController

func NewProxyController() *ProxyController

type Query

type Query struct {
	Li map[string][]string
}

func (*Query) All

func (q *Query) All() map[string][]string

func (*Query) Has

func (q *Query) Has(key string) bool

func (*Query) List

func (q *Query) List(key string) []string

func (*Query) Value

func (q *Query) Value(key string) string

type QueueController

type QueueController struct{}

func (*QueueController) Create

func (cr *QueueController) Create(cx *goweb.Context)

POST: /queue

func (*QueueController) Delete

func (cr *QueueController) Delete(id string, cx *goweb.Context)

DELETE: /queue/{id}

func (*QueueController) DeleteMany

func (cr *QueueController) DeleteMany(cx *goweb.Context)

DELETE: /queue

func (*QueueController) Options

func (cr *QueueController) Options(cx *goweb.Context)

OPTIONS: /queue

func (*QueueController) Read

func (cr *QueueController) Read(id string, cx *goweb.Context)

GET: /queue/{id}

func (*QueueController) ReadMany

func (cr *QueueController) ReadMany(cx *goweb.Context)

GET: /queue get status from queue manager

func (*QueueController) Update

func (cr *QueueController) Update(id string, cx *goweb.Context)

PUT: /queue/{id} -> status update

func (*QueueController) UpdateMany

func (cr *QueueController) UpdateMany(cx *goweb.Context)

PUT: /queue

type ServerController

type ServerController struct {
	Awf              *AwfController
	Client           *ClientController
	ClientGroup      *ClientGroupController
	ClientGroupAcl   map[string]goweb.ControllerFunc
	ClientGroupToken goweb.ControllerFunc
	Job              *JobController
	JobAcl           map[string]goweb.ControllerFunc
	Queue            *QueueController
	Work             *WorkController
}

func NewServerController

func NewServerController() *ServerController

type WorkController

type WorkController struct{}

func (*WorkController) Options

func (cr *WorkController) Options(cx *goweb.Context)

OPTIONS: /work

func (*WorkController) Read

func (cr *WorkController) Read(id string, cx *goweb.Context)

GET: /work/{id} get a workunit by id, read-only

func (*WorkController) ReadMany

func (cr *WorkController) ReadMany(cx *goweb.Context)

GET: /work checkout a workunit with earliest submission time to-do: to support more options for workunit checkout

func (*WorkController) Update

func (cr *WorkController) Update(id string, cx *goweb.Context)

PUT: /work/{id} -> status update

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL