small refactor rbac interfaces
This commit is contained in:
parent
f67657f72d
commit
725738f05a
@ -1,66 +1,68 @@
|
|||||||
package rbac
|
package rbac
|
||||||
|
|
||||||
// Permissions is a stateful object
|
type (
|
||||||
type Permissions interface /* for Session, User, Roles, Resource */ {
|
// Permissions is a stateful object
|
||||||
// Scoped for [Resource]
|
Permissions interface /* for Session, User, Roles, Resource */ {
|
||||||
Grant(permission string) error
|
// Scoped for [Resource]
|
||||||
Revoke(permission string) error
|
Grant(permission string) error
|
||||||
List() ([]string, error)
|
Revoke(permission string) error
|
||||||
|
List() ([]string, error)
|
||||||
|
|
||||||
// Check permission of stateful object (Session, User, Roles)
|
// Check permission of stateful object (Session, User, Roles)
|
||||||
CheckAccess(permission string) (bool, error)
|
CheckAccess(permission string) (bool, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Roles is a stateful object
|
// Roles is a stateful object
|
||||||
type Roles interface /* for Session, User */ {
|
Roles interface /* for Session, User */ {
|
||||||
// Scoped to User
|
// Scoped to User
|
||||||
Add(role string) error
|
Add(role string) error
|
||||||
Delete(role string) error
|
Delete(role string) error
|
||||||
|
|
||||||
// Scoped to Session, User
|
// Scoped to Session, User
|
||||||
List() ([]string, error)
|
List() ([]string, error)
|
||||||
ListAuthorized() ([]string, error)
|
ListAuthorized() ([]string, error)
|
||||||
|
|
||||||
// Scoped to Session
|
// Scoped to Session
|
||||||
GrantRole(role string) error
|
GrantRole(role string) error
|
||||||
RevokeRole(role string) error
|
RevokeRole(role string) error
|
||||||
|
|
||||||
// Permissions are scoped to [Session, User]
|
// Permissions are scoped to [Session, User]
|
||||||
Permissions(role string) Permissions
|
Permissions(role string) Permissions
|
||||||
}
|
}
|
||||||
|
|
||||||
// Session object holds session state (Create, Load)
|
// Session object holds session state (Create, Load)
|
||||||
type Session interface {
|
Session interface {
|
||||||
// Unscoped functions
|
// Unscoped functions
|
||||||
Create(userID string, roles ...string) error
|
Create(userID string, roles ...string) error
|
||||||
Load(sessionID string) error
|
Load(sessionID string) error
|
||||||
Delete() error
|
Delete() error
|
||||||
|
|
||||||
// User returns User scoped object with global roles/permissions
|
// User returns User scoped object with global roles/permissions
|
||||||
User() (User, error)
|
User() (User, error)
|
||||||
|
|
||||||
// Roles and Permissions return session scoped objects
|
// Roles and Permissions return session scoped objects
|
||||||
Roles() Roles
|
Roles() Roles
|
||||||
Permissions() Permissions
|
Permissions() Permissions
|
||||||
}
|
}
|
||||||
|
|
||||||
// Resource is a static object
|
// Resource is a static object
|
||||||
type Resource interface {
|
Resource interface {
|
||||||
Load(resource string) error
|
Load(resource string) error
|
||||||
Create(resource string) error
|
Create(resource string) error
|
||||||
Delete(resource string) error
|
Delete(resource string) error
|
||||||
|
|
||||||
RolePermissions(resource string, role string) Permissions
|
RolePermissions(resource string, role string) Permissions
|
||||||
UserPermissions(resource string, user string) Permissions
|
UserPermissions(resource string, user string) Permissions
|
||||||
}
|
}
|
||||||
|
|
||||||
// Users is a static object
|
// Users is a static object
|
||||||
type User interface {
|
User interface {
|
||||||
Load(user string) error
|
Load(user string) error
|
||||||
Create(user string) error
|
Create(user string) error
|
||||||
Delete(user string) error
|
Delete(user string) error
|
||||||
|
|
||||||
// Roles and Permissions return User scoped objects
|
// Roles and Permissions return User scoped objects
|
||||||
Roles(user string) Roles
|
Roles(user string) Roles
|
||||||
Permissions(user string) Permissions
|
Permissions(user string) Permissions
|
||||||
}
|
}
|
||||||
|
)
|
||||||
|
|||||||
@ -1,2 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
echo $(echo $(sed -n 's/^\(type \|\s*\)\([A-Z][^[:space:]]*\) interface .*/\2/p' "interfaces.go") | tr ' ' ',')
|
|
||||||
Loading…
x
Reference in New Issue
Block a user