add a simple auth function
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
parent
e1aff8d16b
commit
87fe581353
10 changed files with 206 additions and 8 deletions
|
|
@ -27,7 +27,10 @@ func (h *SyncHandler) Trigger(w http.ResponseWriter, r *http.Request) {
|
|||
Error(w, http.StatusBadRequest, "invalid id")
|
||||
return
|
||||
}
|
||||
// Validate repo exists before returning.
|
||||
if err := Authorize(r.Context(), ActionSyncTrigger, repoID); err != nil {
|
||||
Error(w, http.StatusForbidden, "forbidden")
|
||||
return
|
||||
}
|
||||
if err := h.svc.ValidateRepo(r.Context(), repoID); errors.Is(err, store.ErrNotFound) {
|
||||
Error(w, http.StatusNotFound, "repo not found")
|
||||
return
|
||||
|
|
@ -49,6 +52,10 @@ func (h *SyncHandler) ListPending(w http.ResponseWriter, r *http.Request) {
|
|||
Error(w, http.StatusBadRequest, "invalid id")
|
||||
return
|
||||
}
|
||||
if err := Authorize(r.Context(), ActionSyncRead, repoID); err != nil {
|
||||
Error(w, http.StatusForbidden, "forbidden")
|
||||
return
|
||||
}
|
||||
pkgs, err := h.svc.ListPending(r.Context(), repoID)
|
||||
if errors.Is(err, store.ErrNotFound) {
|
||||
Error(w, http.StatusNotFound, "repo not found")
|
||||
|
|
@ -70,6 +77,10 @@ func (h *SyncHandler) Approve(w http.ResponseWriter, r *http.Request) {
|
|||
Error(w, http.StatusBadRequest, "invalid id")
|
||||
return
|
||||
}
|
||||
if err := Authorize(r.Context(), ActionSyncApprove, repoID); err != nil {
|
||||
Error(w, http.StatusForbidden, "forbidden")
|
||||
return
|
||||
}
|
||||
var req SyncSelectionRequest
|
||||
if err := json.NewDecoder(r.Body).Decode(&req); err != nil || len(req.IDs) == 0 {
|
||||
Error(w, http.StatusBadRequest, "body must contain non-empty ids array")
|
||||
|
|
@ -97,6 +108,10 @@ func (h *SyncHandler) Reject(w http.ResponseWriter, r *http.Request) {
|
|||
Error(w, http.StatusBadRequest, "invalid id")
|
||||
return
|
||||
}
|
||||
if err := Authorize(r.Context(), ActionSyncReject, repoID); err != nil {
|
||||
Error(w, http.StatusForbidden, "forbidden")
|
||||
return
|
||||
}
|
||||
var req SyncSelectionRequest
|
||||
if err := json.NewDecoder(r.Body).Decode(&req); err != nil || len(req.IDs) == 0 {
|
||||
Error(w, http.StatusBadRequest, "body must contain non-empty ids array")
|
||||
|
|
@ -118,6 +133,10 @@ func (h *SyncHandler) Block(w http.ResponseWriter, r *http.Request) {
|
|||
Error(w, http.StatusBadRequest, "invalid id")
|
||||
return
|
||||
}
|
||||
if err := Authorize(r.Context(), ActionSyncBlock, repoID); err != nil {
|
||||
Error(w, http.StatusForbidden, "forbidden")
|
||||
return
|
||||
}
|
||||
var req SyncSelectionRequest
|
||||
if err := json.NewDecoder(r.Body).Decode(&req); err != nil || len(req.IDs) == 0 {
|
||||
Error(w, http.StatusBadRequest, "body must contain non-empty ids array")
|
||||
|
|
@ -139,6 +158,10 @@ func (h *SyncHandler) Unblock(w http.ResponseWriter, r *http.Request) {
|
|||
Error(w, http.StatusBadRequest, "invalid id")
|
||||
return
|
||||
}
|
||||
if err := Authorize(r.Context(), ActionSyncBlock, repoID); err != nil {
|
||||
Error(w, http.StatusForbidden, "forbidden")
|
||||
return
|
||||
}
|
||||
var req SyncSelectionRequest
|
||||
if err := json.NewDecoder(r.Body).Decode(&req); err != nil || len(req.IDs) == 0 {
|
||||
Error(w, http.StatusBadRequest, "body must contain non-empty ids array")
|
||||
|
|
@ -160,6 +183,10 @@ func (h *SyncHandler) ListBlocked(w http.ResponseWriter, r *http.Request) {
|
|||
Error(w, http.StatusBadRequest, "invalid id")
|
||||
return
|
||||
}
|
||||
if err := Authorize(r.Context(), ActionSyncRead, repoID); err != nil {
|
||||
Error(w, http.StatusForbidden, "forbidden")
|
||||
return
|
||||
}
|
||||
pkgs, err := h.svc.ListBlocked(r.Context(), repoID)
|
||||
if errors.Is(err, store.ErrNotFound) {
|
||||
Error(w, http.StatusNotFound, "repo not found")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue