Skip to content

Commit 47c5b47

Browse files
committed
chore: whoami - return perms and role
1 parent 3da698e commit 47c5b47

File tree

9 files changed

+199
-89
lines changed

9 files changed

+199
-89
lines changed

auth/controllers.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/flanksource/incident-commander/api"
1616
"github.com/flanksource/incident-commander/db"
1717
"github.com/flanksource/incident-commander/mail"
18+
"github.com/flanksource/incident-commander/rbac"
1819
)
1920

2021
type InviteUserRequest struct {
@@ -134,12 +135,18 @@ func WhoAmI(c echo.Context) error {
134135
if dbURL, err := url.Parse(db.ConnectionString); err == nil {
135136
dbName = strings.TrimPrefix(dbURL.Path, "/")
136137
}
138+
139+
roles, _ := rbac.RolesForUser(user.ID.URN())
140+
permissions, _ := rbac.PermsForUser(user.ID.URN())
141+
137142
return c.JSON(http.StatusOK, dutyAPI.HTTPSuccess{
138143
Message: "success",
139144
Payload: map[string]any{
140-
"user": user,
141-
"hostname": hostname,
142-
"database": dbName,
145+
"user": user,
146+
"roles": roles,
147+
"permissions": permissions,
148+
"hostname": hostname,
149+
"database": dbName,
143150
},
144151
})
145152
}

auth/kratos.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,11 @@ func (k *kratosMiddleware) Session(next echo.HandlerFunc) echo.HandlerFunc {
178178
person.Email = e
179179
}
180180

181+
switch v := traits["name"].(type) {
182+
case map[string]string:
183+
person.Name = fmt.Sprintf("%s %s", v["first"], v["last"])
184+
}
185+
181186
if agent, ok := traits["agent"].(models.Agent); ok {
182187
ctx = ctx.WithAgent(agent)
183188
}

db/info.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func (info *Info) Get(db *gorm.DB) error {
1818
functions
1919
FROM (SELECT array_agg(information_schema.views.table_name) AS views
2020
FROM information_schema.views
21-
WHERE information_schema.views.table_schema = any (current_schemas(false)) AND table_name not like 'pg_%
21+
WHERE information_schema.views.table_schema = any (current_schemas(false)) AND table_name not like 'pg_%'
2222
)
2323
t,
2424
(SELECT array_agg(information_schema.tables.table_name) AS tables

go.mod

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ require (
88
github.com/adityathebe/go-strip-markdown/v2 v2.0.1
99
github.com/andygrunwald/go-jira v1.16.0
1010
github.com/casbin/casbin/v2 v2.87.1
11+
github.com/casbin/gorm-adapter/v3 v3.26.0
1112
github.com/containrrr/shoutrrr v0.8.0
1213
github.com/fergusstrange/embedded-postgres v1.25.0 // indirect
1314
github.com/flanksource/commons v1.24.2
@@ -108,6 +109,7 @@ require (
108109
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
109110
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
110111
github.com/distribution/reference v0.5.0 // indirect
112+
github.com/dustin/go-humanize v1.0.1 // indirect
111113
github.com/eko/gocache/lib/v4 v4.1.6 // indirect
112114
github.com/eko/gocache/store/go_cache/v4 v4.2.2 // indirect
113115
github.com/emicklei/go-restful/v3 v3.11.1 // indirect
@@ -125,6 +127,8 @@ require (
125127
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
126128
github.com/geoffgarside/ber v1.1.0 // indirect
127129
github.com/ghodss/yaml v1.0.0 // indirect
130+
github.com/glebarez/go-sqlite v1.20.3 // indirect
131+
github.com/glebarez/sqlite v1.7.0 // indirect
128132
github.com/go-errors/errors v1.5.1 // indirect
129133
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
130134
github.com/go-logr/stdr v1.2.2 // indirect
@@ -137,6 +141,8 @@ require (
137141
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
138142
github.com/gobwas/glob v0.2.3 // indirect
139143
github.com/gofrs/uuid v4.2.0+incompatible // indirect
144+
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 // indirect
145+
github.com/golang-sql/sqlexp v0.1.0 // indirect
140146
github.com/golang/mock v1.6.0 // indirect
141147
github.com/google/btree v1.1.2 // indirect
142148
github.com/google/gnostic-models v0.6.9-0.20230804172637-c7be7c783f49 // indirect
@@ -163,6 +169,7 @@ require (
163169
github.com/kr/fs v0.1.0 // indirect
164170
github.com/liamylian/jsontime/v2 v2.0.0 // indirect
165171
github.com/mailru/easyjson v0.7.7 // indirect
172+
github.com/microsoft/go-mssqldb v1.6.0 // indirect
166173
github.com/microsoft/kiota-serialization-form-go v1.0.0 // indirect
167174
github.com/mitchellh/copystructure v1.2.0 // indirect
168175
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
@@ -178,6 +185,7 @@ require (
178185
github.com/prometheus/client_model v0.6.1 // indirect
179186
github.com/prometheus/common v0.55.0 // indirect
180187
github.com/prometheus/procfs v0.15.1 // indirect
188+
github.com/remyoudompheng/bigfft v0.0.0-20230126093431-47fa9a501578 // indirect
181189
github.com/robertkrimen/otto v0.3.0 // indirect
182190
github.com/rodaine/table v1.1.0 // indirect
183191
github.com/rogpeppe/go-internal v1.12.0 // indirect
@@ -225,13 +233,19 @@ require (
225233
gopkg.in/warnings.v0 v0.1.2 // indirect
226234
gorm.io/driver/mysql v1.5.6 // indirect
227235
gorm.io/driver/postgres v1.5.9 // indirect
236+
gorm.io/driver/sqlserver v1.5.3 // indirect
237+
gorm.io/plugin/dbresolver v1.3.0 // indirect
228238
k8s.io/apiextensions-apiserver v0.28.3 // indirect
229239
k8s.io/cli-runtime v0.28.2 // indirect
230240
k8s.io/component-base v0.28.3 // indirect
231241
k8s.io/klog/v2 v2.110.1 // indirect
232242
k8s.io/kube-openapi v0.0.0-20231129212854-f0671cc7e66a // indirect
233243
k8s.io/utils v0.0.0-20240102154912-e7106e64919e // indirect
234244
layeh.com/gopher-json v0.0.0-20201124131017-552bb3c4c3bf // indirect
245+
modernc.org/libc v1.22.2 // indirect
246+
modernc.org/mathutil v1.5.0 // indirect
247+
modernc.org/memory v1.5.0 // indirect
248+
modernc.org/sqlite v1.20.3 // indirect
235249
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
236250
sigs.k8s.io/kustomize v2.0.3+incompatible // indirect
237251
sigs.k8s.io/kustomize/api v0.15.0 // indirect

0 commit comments

Comments
 (0)