summaryrefslogtreecommitdiffstats
path: root/src/dcm/api/quotaHandler.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/dcm/api/quotaHandler.go')
-rw-r--r--src/dcm/api/quotaHandler.go50
1 files changed, 32 insertions, 18 deletions
diff --git a/src/dcm/api/quotaHandler.go b/src/dcm/api/quotaHandler.go
index fd9b40f8..1f0e45a5 100644
--- a/src/dcm/api/quotaHandler.go
+++ b/src/dcm/api/quotaHandler.go
@@ -23,9 +23,8 @@ import (
"io"
"net/http"
- "github.com/onap/multicloud-k8s/src/dcm/pkg/module"
-
"github.com/gorilla/mux"
+ "github.com/onap/multicloud-k8s/src/dcm/pkg/module"
)
// quotaHandler is used to store backend implementations objects
@@ -34,7 +33,6 @@ type quotaHandler struct {
}
// CreateHandler handles creation of the quota entry in the database
-
func (h quotaHandler) createHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
project := vars["project-name"]
@@ -72,8 +70,32 @@ func (h quotaHandler) createHandler(w http.ResponseWriter, r *http.Request) {
}
}
+// getHandler handles GET operations over quotas
+// Returns a list of Quotas
+func (h quotaHandler) 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.GetAllQuotas(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 handle GET operations on a particular name
-// Returns a quota
+// Returns a Quota
func (h quotaHandler) getHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
project := vars["project-name"]
@@ -82,22 +104,14 @@ func (h quotaHandler) getHandler(w http.ResponseWriter, r *http.Request) {
var ret interface{}
var err error
- if len(name) == 0 {
- ret, err = h.client.GetAllQuotas(project, logicalCloud)
- if err != nil {
- http.Error(w, err.Error(), http.StatusInternalServerError)
- return
- }
- } else {
- ret, err = h.client.GetQuota(project, logicalCloud, name)
- if err != nil {
- if err.Error() == "Cluster Quota does not exist" {
- http.Error(w, err.Error(), http.StatusNotFound)
- return
- }
- http.Error(w, err.Error(), http.StatusInternalServerError)
+ ret, err = h.client.GetQuota(project, logicalCloud, name)
+ if err != nil {
+ if err.Error() == "Cluster Quota 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")