summaryrefslogtreecommitdiffstats
path: root/src/dcm/api/userPermissionsHandler.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/dcm/api/userPermissionsHandler.go')
-rw-r--r--src/dcm/api/userPermissionsHandler.go47
1 files changed, 31 insertions, 16 deletions
diff --git a/src/dcm/api/userPermissionsHandler.go b/src/dcm/api/userPermissionsHandler.go
index 3ac955fa..6d88f573 100644
--- a/src/dcm/api/userPermissionsHandler.go
+++ b/src/dcm/api/userPermissionsHandler.go
@@ -33,7 +33,6 @@ type userPermissionHandler struct {
}
// CreateHandler handles creation of the user permission entry in the database
-
func (h userPermissionHandler) createHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
@@ -72,7 +71,31 @@ func (h userPermissionHandler) createHandler(w http.ResponseWriter, r *http.Requ
}
}
-// getHandler handle GET operations on a particular name
+// getAllHandler handles GET operations over user permissions
+// Returns a list of User Permissions
+func (h userPermissionHandler) getAllHandler(w http.ResponseWriter, r *http.Request) {
+ vars := mux.Vars(r)
+ project := vars["project-name"]
+ logicalCloud := vars["logical-cloud-name"]
+ var ret interface{}
+ var err error
+
+ ret, err = h.client.GetAllUserPerms(project, logicalCloud)
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+
+ w.Header().Set("Content-Type", "application/json")
+ w.WriteHeader(http.StatusOK)
+ err = json.NewEncoder(w).Encode(ret)
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+}
+
+// getHandler handles GET operations on a particular name
// Returns a User Permission
func (h userPermissionHandler) getHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
@@ -82,22 +105,14 @@ func (h userPermissionHandler) getHandler(w http.ResponseWriter, r *http.Request
var ret interface{}
var err error
- if len(name) == 0 {
- ret, err = h.client.GetAllUserPerms(project, logicalCloud)
- if err != nil {
- http.Error(w, err.Error(), http.StatusInternalServerError)
- return
- }
- } else {
- ret, err = h.client.GetUserPerm(project, logicalCloud, name)
- if err != nil {
- if err.Error() == "User Permission does not exist" {
- http.Error(w, err.Error(), http.StatusNotFound)
- return
- }
- http.Error(w, err.Error(), http.StatusInternalServerError)
+ ret, err = h.client.GetUserPerm(project, logicalCloud, name)
+ if err != nil {
+ if err.Error() == "User Permission does not exist" {
+ http.Error(w, err.Error(), http.StatusNotFound)
return
}
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
}
w.Header().Set("Content-Type", "application/json")