this repo has no description
1package knotserver
2
3import (
4 "context"
5 "net/http"
6
7 "github.com/go-chi/chi/v5"
8 "github.com/sotangled/tangled/knotserver/db"
9 "github.com/sotangled/tangled/rbac"
10)
11
12type InternalHandle struct {
13 db *db.DB
14 e *rbac.Enforcer
15}
16
17func (h *InternalHandle) PushAllowed(w http.ResponseWriter, r *http.Request) {
18 user := r.URL.Query().Get("user")
19 repo := r.URL.Query().Get("repo")
20
21 if user == "" || repo == "" {
22 w.WriteHeader(http.StatusBadRequest)
23 return
24 }
25
26 ok, err := h.e.IsPushAllowed(user, ThisServer, repo)
27 if err != nil || !ok {
28 w.WriteHeader(http.StatusForbidden)
29 return
30 }
31
32 w.WriteHeader(http.StatusNoContent)
33 return
34}
35
36func Internal(ctx context.Context, db *db.DB, e *rbac.Enforcer) http.Handler {
37 r := chi.NewRouter()
38
39 h := InternalHandle{
40 db,
41 e,
42 }
43
44 r.Get("/push-allowed", h.PushAllowed)
45
46 return r
47}