Commit da224549 authored by ale's avatar ale

Add a GetResource API

parent 6f6114ec
......@@ -5,6 +5,27 @@ import (
"fmt"
)
// GetResourceRequest requests a specific resource.
type GetResourceRequest struct {
AdminResourceRequestBase
}
// GetResourceResponse is the response type for GetResourceRequest.
type GetResourceResponse struct {
Resource *Resource `json:"resource"`
Owner string `json:"owner"`
}
func (r *GetResourceRequest) Serve(rctx *RequestContext) (interface{}, error) {
resp := GetResourceResponse{
Resource: rctx.Resource,
}
if rctx.User != nil {
resp.Owner = rctx.User.Name
}
return &resp, nil
}
// setResourceStatus sets the status of a single resource (shared
// logic between enable / disable resource methods).
func setResourceStatus(rctx *RequestContext, status string) error {
......@@ -100,6 +121,7 @@ type MoveResourceResponse struct {
// Serve the request.
func (r *MoveResourceRequest) Serve(rctx *RequestContext) (interface{}, error) {
resources := []*Resource{rctx.Resource}
// If we have an associated user, collect all related
// resources, as they should all be moved at once.
if rctx.User != nil && rctx.Resource.Group != "" {
......
......@@ -57,6 +57,7 @@ func New(service *as.AccountService, backend as.Backend) *APIServer {
s.Register("/api/user/disable_otp", &as.DisableOTPRequest{})
s.Register("/api/user/create_app_specific_password", &as.CreateApplicationSpecificPasswordRequest{})
s.Register("/api/user/delete_app_specific_password", &as.DeleteApplicationSpecificPasswordRequest{})
s.Register("/api/resource/get", &as.GetResourceRequest{})
s.Register("/api/resource/enable", &as.EnableResourceRequest{})
s.Register("/api/resource/disable", &as.DisableResourceRequest{})
s.Register("/api/resource/create", &as.CreateResourcesRequest{})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment