-
Notifications
You must be signed in to change notification settings - Fork 0
/
role.go
34 lines (28 loc) · 841 Bytes
/
role.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
package ui
import teleservices "github.com/gravitational/teleport/lib/services"
// Role describes user role consumed by web ui
type Role struct {
// Name is role name
Name string `json:"name"`
// Access is a set of attributes describing role permissions
Access RoleAccess `json:"access"`
// System is a flag indicating if a role is builtin system role
System bool `json:"system"`
}
// NewRole creates a new instance of UI Role
func NewRole(sRole teleservices.Role) *Role {
uiRole := Role{
Name: sRole.GetName(),
}
uiRole.Access.init(sRole)
return &uiRole
}
// ToTeleRole converts UI Role to Storage Role
func (r *Role) ToTeleRole() (teleservices.Role, error) {
teleRole, err := teleservices.NewRole(r.Name, teleservices.RoleSpecV2{})
if err != nil {
return nil, err
}
r.Access.Apply(teleRole)
return teleRole, nil
}