CI / changes (push) Successful in 6s
CI / commitlint (push) Skipped
CI / openapi (push) Successful in 27s
CI / web (push) Successful in 51s
CI / go (push) Successful in 2m19s
CI / bird2 (push) Successful in 13s
CI / release (push) Successful in 4m24s
Added support for portal JWT authentication, enabling single sign-on (SSO) capabilities. Updated the application to handle JWT claims for user permissions and roles, enhancing security and access control. Refactored relevant components and API routes to accommodate the new authentication flow, ensuring a seamless user experience. Updated documentation to reflect the new authentication requirements and configurations. Co-authored-by: Cursor <[email protected]>
38 lines
929 B
Go
38 lines
929 B
Go
package httpapi
|
|
|
|
import (
|
|
"errors"
|
|
"net/http"
|
|
"strings"
|
|
|
|
"evobgp/internal/lookup"
|
|
"evobgp/internal/store"
|
|
)
|
|
|
|
// handleLookup implements GET /v1/lookup?q= (operationId: lookupMembership).
|
|
func (s *Server) handleLookup(w http.ResponseWriter, r *http.Request) {
|
|
a, ok := authFromContext(r.Context())
|
|
if !ok {
|
|
writeProblem(w, http.StatusUnauthorized, "Unauthorized", "missing auth")
|
|
return
|
|
}
|
|
if !s.requirePerm(w, a, "bgp:lookup:read") {
|
|
return
|
|
}
|
|
q := strings.TrimSpace(r.URL.Query().Get("q"))
|
|
if q == "" {
|
|
writeProblem(w, http.StatusBadRequest, "Bad Request", "query parameter q is required")
|
|
return
|
|
}
|
|
res, err := lookup.Lookup(r.Context(), s.store, a.TenantID, q)
|
|
if err != nil {
|
|
if errors.Is(err, store.ErrInvalidInput) {
|
|
writeProblem(w, http.StatusBadRequest, "Bad Request", "query must be an IP address or FQDN")
|
|
return
|
|
}
|
|
writeStoreErr(w, err)
|
|
return
|
|
}
|
|
writeJSON(w, http.StatusOK, res)
|
|
}
|