2024-02-27 14:14:30 +01:00
|
|
|
package user
|
2023-03-07 23:10:42 +01:00
|
|
|
|
2024-02-26 18:20:40 +01:00
|
|
|
import (
|
|
|
|
"forge.cadoles.com/Cadoles/emissary/internal/auth"
|
|
|
|
"forge.cadoles.com/Cadoles/emissary/internal/datastore"
|
|
|
|
)
|
2023-03-07 23:10:42 +01:00
|
|
|
|
|
|
|
type Role string
|
|
|
|
|
|
|
|
const (
|
|
|
|
RoleWriter Role = "writer"
|
|
|
|
RoleReader Role = "reader"
|
2024-02-27 14:14:30 +01:00
|
|
|
RoleAdmin Role = "admin"
|
2023-03-07 23:10:42 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func isValidRole(r string) bool {
|
|
|
|
rr := Role(r)
|
|
|
|
|
2024-02-27 14:14:30 +01:00
|
|
|
return rr == RoleWriter || rr == RoleReader || rr == RoleAdmin
|
2023-03-07 23:10:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type User struct {
|
2024-02-26 18:20:40 +01:00
|
|
|
subject string
|
|
|
|
tenantID datastore.TenantID
|
|
|
|
role Role
|
2023-03-07 23:10:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Subject implements auth.User
|
|
|
|
func (u *User) Subject() string {
|
|
|
|
return u.subject
|
|
|
|
}
|
|
|
|
|
2024-02-26 18:20:40 +01:00
|
|
|
// Tenant implements auth.User
|
|
|
|
func (u *User) Tenant() datastore.TenantID {
|
|
|
|
return u.tenantID
|
|
|
|
}
|
|
|
|
|
2023-03-07 23:10:42 +01:00
|
|
|
func (u *User) Role() Role {
|
|
|
|
return u.role
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ auth.User = &User{}
|