-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathquotas.go
More file actions
57 lines (47 loc) · 1.61 KB
/
Copy pathquotas.go
File metadata and controls
57 lines (47 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// SPDX-FileCopyrightText: 2019 SAP SE or an SAP affiliate company
// SPDX-License-Identifier: Apache-2.0
package keppelv1
import (
"net/http"
"github.com/gorilla/mux"
"github.com/sapcc/go-bits/errext"
"github.com/sapcc/go-bits/httpapi"
"github.com/sapcc/go-bits/respondwith"
"github.com/sapcc/keppel/internal/keppel"
"github.com/sapcc/keppel/internal/processor"
)
func (a *API) handleGetQuotas(w http.ResponseWriter, r *http.Request) {
httpapi.IdentifyEndpoint(r, "/keppel/v1/quotas/:auth_tenant_id")
authTenantID := mux.Vars(r)["auth_tenant_id"]
authz := a.authenticateRequest(w, r, authTenantScope(keppel.CanViewQuotas, authTenantID))
if authz == nil {
return
}
resp, err := a.processor().GetQuotas(r.Context(), authTenantID)
if respondwith.ObfuscatedErrorText(w, err) {
return
}
respondwith.JSON(w, http.StatusOK, resp)
}
func (a *API) handlePutQuotas(w http.ResponseWriter, r *http.Request) {
httpapi.IdentifyEndpoint(r, "/keppel/v1/quotas/:auth_tenant_id")
authTenantID := mux.Vars(r)["auth_tenant_id"]
authz := a.authenticateRequest(w, r, authTenantScope(keppel.CanChangeQuotas, authTenantID))
if authz == nil {
return
}
var req processor.QuotaRequest
err := decodeJSONRequestBody(r.Body, &req)
if respondwith.ObfuscatedErrorText(w, err) {
return
}
resp, err := a.processor().SetQuotas(r.Context(), authTenantID, req, authz.UserIdentity.UserInfo(), r)
if iqerr, ok := errext.As[processor.ImpossibleQuotaError](err); ok {
http.Error(w, iqerr.Message, http.StatusUnprocessableEntity)
return
}
if respondwith.ObfuscatedErrorText(w, err) {
return
}
respondwith.JSON(w, http.StatusOK, resp)
}