platform: modularize api/gui, add docs-tests-web foundation, and refresh root config
This commit is contained in:
61
selective-vpn-api/app/egress_identity_handlers.go
Normal file
61
selective-vpn-api/app/egress_identity_handlers.go
Normal file
@@ -0,0 +1,61 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func handleEgressIdentityGet(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodGet {
|
||||
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
|
||||
scope := strings.TrimSpace(r.URL.Query().Get("scope"))
|
||||
if scope == "" {
|
||||
http.Error(w, "scope is required", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
refresh := false
|
||||
switch strings.ToLower(strings.TrimSpace(r.URL.Query().Get("refresh"))) {
|
||||
case "1", "true", "yes", "on":
|
||||
refresh = true
|
||||
}
|
||||
|
||||
item, err := egressIdentitySWR.getSnapshot(scope, refresh)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
writeJSON(w, http.StatusOK, EgressIdentityResponse{
|
||||
OK: true,
|
||||
Message: "ok",
|
||||
Item: item,
|
||||
})
|
||||
}
|
||||
|
||||
func handleEgressIdentityRefresh(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodPost {
|
||||
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
|
||||
var body EgressIdentityRefreshRequest
|
||||
if r.Body != nil {
|
||||
defer r.Body.Close()
|
||||
if err := json.NewDecoder(io.LimitReader(r.Body, 1<<20)).Decode(&body); err != nil && err != io.EOF {
|
||||
http.Error(w, "bad json", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
resp, err := egressIdentitySWR.queueRefresh(body.Scopes, body.Force)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
writeJSON(w, http.StatusOK, resp)
|
||||
}
|
||||
Reference in New Issue
Block a user