blob: 415517dcd6ebcfacdc3ca20ad0a737b35ea1a4d6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
package controllers
import (
"context"
"net/http"
"time"
"code.crute.us/mcrute/cloud-identity-broker/app"
"code.crute.us/mcrute/cloud-identity-broker/app/models"
"code.crute.us/mcrute/golib/echo/controller"
"github.com/labstack/echo/v4"
)
type jsonListUser struct {
Username string `bson:"_id" json:"username"`
IsAdmin bool `json:"is_admin"`
IsService bool `json:"is_service"`
SelfLink string `json:"self"`
Deleted *time.Time `json:"deleted,omitempty"`
}
type APIUserListHandler struct {
store models.UserStore
}
func NewAPIUserListHandler(s models.UserStore) echo.HandlerFunc {
al := &APIUserListHandler{store: s}
h := &controller.ContentTypeNegotiatingHandler{
DefaultHandler: al.Handle,
Handlers: map[string]echo.HandlerFunc{
contentTypeV2: al.Handle,
},
}
return h.Handle
}
func (h *APIUserListHandler) Handle(c echo.Context) error {
users, err := h.store.List(context.Background())
if err != nil {
return echo.ErrInternalServerError
}
out := map[string]*jsonListUser{}
for _, v := range users {
out[v.Username] = &jsonListUser{
Username: v.Username,
IsAdmin: v.IsAdmin,
IsService: v.IsService,
SelfLink: app.AppURL{}.User(c, &v.Username),
Deleted: v.Deleted,
}
}
return c.JSON(http.StatusOK, out)
}
|