-
Notifications
You must be signed in to change notification settings - Fork 53
/
login.go
37 lines (34 loc) · 890 Bytes
/
login.go
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
package noauth
import (
"html/template"
"net/http"
"sort"
"google.golang.org/protobuf/types/known/emptypb"
)
func (s *Server) renderLoginPage(w http.ResponseWriter, r *http.Request) {
rbs, err := s.mgmtApiClient.ListRoleBindings(r.Context(), &emptypb.Empty{})
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
knownusers := map[string]struct{}{}
for _, rb := range rbs.Items {
for _, subject := range rb.Subjects {
knownusers[subject] = struct{}{}
}
}
allUsersSorted := make([]string, 0, len(knownusers))
for u := range knownusers {
allUsersSorted = append(allUsersSorted, u)
}
sort.Strings(allUsersSorted)
data := templateData{
Users: allUsersSorted,
}
tmpl := template.New("index.html")
siteTemplate, err := tmpl.ParseFS(webFS, "web/templates/index.html")
if err != nil {
return
}
siteTemplate.Execute(w, data)
}