feat(server): add /api/v1/session endpoint
All checks were successful
arcad/emissary/pipeline/head This commit looks good
All checks were successful
arcad/emissary/pipeline/head This commit looks good
This commit is contained in:
35
internal/server/api/get_session.go
Normal file
35
internal/server/api/get_session.go
Normal file
@ -0,0 +1,35 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"forge.cadoles.com/Cadoles/emissary/internal/auth"
|
||||
"forge.cadoles.com/Cadoles/emissary/internal/datastore"
|
||||
"github.com/pkg/errors"
|
||||
"gitlab.com/wpetit/goweb/api"
|
||||
"gitlab.com/wpetit/goweb/logger"
|
||||
)
|
||||
|
||||
func (m *Mount) getSession(w http.ResponseWriter, r *http.Request) {
|
||||
user, ok := assertRequestUser(w, r)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
ctx := r.Context()
|
||||
|
||||
tenant, err := m.tenantRepo.Get(ctx, user.Tenant())
|
||||
if err != nil && !errors.Is(err, datastore.ErrNotFound) {
|
||||
err = errors.WithStack(err)
|
||||
logger.Error(ctx, "could not retrieve user tenant", logger.CapturedE(err))
|
||||
api.ErrorResponse(w, http.StatusInternalServerError, ErrCodeUnknownError, nil)
|
||||
}
|
||||
|
||||
api.DataResponse(w, http.StatusOK, struct {
|
||||
User auth.User `json:"user"`
|
||||
Tenant *datastore.Tenant `json:"tenant"`
|
||||
}{
|
||||
User: user,
|
||||
Tenant: tenant,
|
||||
})
|
||||
}
|
@ -23,6 +23,8 @@ func (m *Mount) Mount(r chi.Router) {
|
||||
r.Group(func(r chi.Router) {
|
||||
r.Use(auth.Middleware(m.authenticators...))
|
||||
|
||||
r.Get("/session", m.getSession)
|
||||
|
||||
r.Route("/agents", func(r chi.Router) {
|
||||
r.With(assertUserWithWriteAccess).Post("/claim", m.claimAgent)
|
||||
|
||||
|
Reference in New Issue
Block a user