controller

package
v0.9.68 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2018 License: BSD-2-Clause Imports: 29 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
		}
	}

	rights := cg.Acl.Check(u.Uuid)
	if cg.Acl.Owner != u.Uuid && u.Admin == false && cg.Acl.Owner != "public" && rights["read"] == 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 OPTIONS and GET 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
	}

	ids, err := parseClientGroupAclRequestTyped(cx)
	if err != nil {
		cx.RespondWithErrorMessage(err.Error(), http.StatusBadRequest)
		return
	}

	if cg.Acl.Owner != u.Uuid && u.Admin == false {
		if rmeth == "DELETE" {
			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" {
				cg.Acl.UnSet(ids[0], map[string]bool{"read": true, "write": true, "delete": true, "execute": true})
			} else {
				cg.Acl.UnSet(ids[0], map[string]bool{rtype: true})
			}
			cg.Save()
			cx.RespondWithData(cg.Acl)
			return
		}
		cx.RespondWithErrorMessage("Users that are not clientgroup owners can only delete themselves from ACLs.", http.StatusBadRequest)
		return
	}

	if rmeth == "GET" {
		cx.RespondWithData(cg.Acl)
		return
	} else if rmeth == "POST" || rmeth == "PUT" {
		if rtype == "owner" {
			if len(ids) == 1 {
				cg.Acl.SetOwner(ids[0])
			} else {
				cx.RespondWithErrorMessage("Clientgroups must have one owner.", http.StatusBadRequest)
				return
			}
		} else if rtype == "all" {
			for _, i := range ids {
				cg.Acl.Set(i, map[string]bool{"read": true, "write": true, "delete": true, "execute": 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" {
			cg.Acl.Set("public", map[string]bool{"read": true, "write": true, "delete": true, "execute": true})
		} else {
			for _, i := range ids {
				cg.Acl.Set(i, map[string]bool{rtype: true})
			}
		}
		cg.Save()
		cx.RespondWithData(cg.Acl)
		return
	} 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 _, i := range ids {
				cg.Acl.UnSet(i, map[string]bool{"read": true, "write": true, "delete": true, "execute": 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" {
			cg.Acl.UnSet("public", map[string]bool{"read": true, "write": true, "delete": true, "execute": true})
		} else {
			for _, i := range ids {
				cg.Acl.UnSet(i, map[string]bool{rtype: true})
			}
		}
		cg.Save()
		cx.RespondWithData(cg.Acl)
		return
	} else {
		cx.RespondWithErrorMessage("This request type is not implemented.", http.StatusNotImplemented)
		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
	}

	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
		}
	}

	jid := cx.PathParams["jid"]

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

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

	rights := acl.Check(u.Uuid)
	if acl.Owner != u.Uuid && u.Admin == false && acl.Owner != "public" && rights["read"] == false {
		cx.RespondWithErrorMessage(e.UnAuth, http.StatusUnauthorized)
		return
	}

	if cx.Request.Method == "GET" {
		cx.RespondWithData(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 !validJobAclTypes[rtype] {
		cx.RespondWithErrorMessage("Invalid acl type", http.StatusBadRequest)
		return
	}

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

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

	ids, err := parseJobAclRequestTyped(cx)
	if err != nil {
		cx.RespondWithErrorMessage(err.Error(), http.StatusBadRequest)
		return
	}

	if acl.Owner != u.Uuid && u.Admin == false {
		if rmeth == "DELETE" {
			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" {
				acl.UnSet(ids[0], map[string]bool{"read": true, "write": true, "delete": true})
			} else {
				acl.UnSet(ids[0], map[string]bool{rtype: true})
			}

			err = core.DbUpdateJobField(jid, "acl", acl)
			if err != nil {
				cx.RespondWithErrorMessage("acl update error: "+jid, http.StatusBadRequest)
				return
			}

			cx.RespondWithData(acl)
			return
		}
		cx.RespondWithErrorMessage("Users that are not job owners can only delete themselves from ACLs.", http.StatusBadRequest)
		return
	}

	if rmeth == "GET" {
		cx.RespondWithData(acl)
		return
	} else if rmeth == "POST" || rmeth == "PUT" {
		if rtype == "owner" {
			if len(ids) == 1 {
				acl.SetOwner(ids[0])
			} else {
				cx.RespondWithErrorMessage("Jobs must have one owner.", http.StatusBadRequest)
				return
			}
		} else if rtype == "all" {
			for _, i := range ids {
				acl.Set(i, map[string]bool{"read": true, "write": true, "delete": true})
			}
		} else if rtype == "public_read" {
			acl.Set("public", map[string]bool{"read": true})
		} else if rtype == "public_write" {
			acl.Set("public", map[string]bool{"write": true})
		} else if rtype == "public_delete" {
			acl.Set("public", map[string]bool{"delete": true})
		} else if rtype == "public_all" {
			acl.Set("public", map[string]bool{"read": true, "write": true, "delete": true})
		} else {
			for _, i := range ids {
				acl.Set(i, map[string]bool{rtype: true})
			}
		}
		err = core.DbUpdateJobField(jid, "acl", acl)
		if err != nil {
			cx.RespondWithErrorMessage("acl update error: "+jid, http.StatusBadRequest)
			return
		}

		cx.RespondWithData(acl)
		return
	} 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 _, i := range ids {
				acl.UnSet(i, map[string]bool{"read": true, "write": true, "delete": true})
			}
		} else if rtype == "public_read" {
			acl.UnSet("public", map[string]bool{"read": true})
		} else if rtype == "public_write" {
			acl.UnSet("public", map[string]bool{"write": true})
		} else if rtype == "public_delete" {
			acl.UnSet("public", map[string]bool{"delete": true})
		} else if rtype == "public_all" {
			acl.UnSet("public", map[string]bool{"read": true, "write": true, "delete": true})
		} else {
			for _, i := range ids {
				acl.UnSet(i, map[string]bool{rtype: true})
			}
		}
		err = core.DbUpdateJobField(jid, "acl", acl)
		if err != nil {
			cx.RespondWithErrorMessage("acl update error: "+jid, http.StatusBadRequest)
			return
		}
		cx.RespondWithData(acl)
		return
	} else {
		cx.RespondWithErrorMessage("This request type is not implemented.", http.StatusNotImplemented)
		return
	}
}

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

Functions

func DecodeBase64 added in v0.9.62

func DecodeBase64(cx *goweb.Context, id string) (return_id string)

func GetAuthorizedUser added in v0.9.62

func GetAuthorizedUser(cx *goweb.Context) (u *user.User, done bool)

func GetClientGroup added in v0.9.62

func GetClientGroup(cx *goweb.Context) (cg *core.ClientGroup, done 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 LoggerController added in v0.9.30

type LoggerController struct{}

func (*LoggerController) Create added in v0.9.30

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

POST: /logger

func (*LoggerController) Delete added in v0.9.30

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

DELETE: /logger/{id}

func (*LoggerController) DeleteMany added in v0.9.30

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

DELETE: /logger

func (*LoggerController) Options added in v0.9.30

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

OPTIONS: /logger

func (*LoggerController) Read added in v0.9.30

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

GET: /logger/{id}

func (*LoggerController) ReadMany added in v0.9.30

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

GET: /logger

func (*LoggerController) Update added in v0.9.30

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

PUT: /logger/{id}

func (*LoggerController) UpdateMany added in v0.9.30

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

PUT: /logger

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) Empty added in v0.9.26

func (q *Query) Empty() bool

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
	Logger           *LoggerController
	Queue            *QueueController
	Work             *WorkController
}

func NewServerController

func NewServerController() *ServerController

type StandardResponse added in v0.9.33

type StandardResponse struct {
	S int         `json:"status"`
	D interface{} `json:"data"`
	E []string    `json:"error"`
}

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