This adds parsing and validation for grant strings along with the ability to create canonical JSON and text strings from a grant. It also adds an ACL implementation, allowing a collection of grant strings to then be checked against a resource/action tuple and indicate if it's allowed. Note that only specific sets of provided data in grant strings is allowed. This vastly simplifies logic. Test coverage is 100%. A future update will consolidate and migrate types between this and IAM but I didn't want to mix that in with this.
66 lines
1.5 KiB
Go
66 lines
1.5 KiB
Go
package iam
|
|
|
|
// Action defines a type for the Actions of Resources
|
|
// actions are also stored as a lookup db table named iam_action
|
|
type Action int
|
|
|
|
// not using iota intentionally, since the values are stored in the db as well.
|
|
const (
|
|
ActionUnknown Action = 0
|
|
ActionList Action = 1
|
|
ActionCreate Action = 2
|
|
ActionUpdate Action = 3
|
|
ActionRead Action = 4
|
|
ActionDelete Action = 5
|
|
ActionAuthen Action = 6
|
|
ActionAll Action = 7
|
|
ActionConnect Action = 8
|
|
)
|
|
|
|
var ActionMap = map[string]Action{
|
|
"unknown": ActionUnknown,
|
|
"list": ActionList,
|
|
"create": ActionCreate,
|
|
"update": ActionUpdate,
|
|
"read": ActionRead,
|
|
"delete": ActionDelete,
|
|
"authen": ActionAuthen,
|
|
"*": ActionAll,
|
|
"connect": ActionConnect,
|
|
}
|
|
|
|
func (a Action) String() string {
|
|
return [...]string{
|
|
"unknown",
|
|
"list",
|
|
"create",
|
|
"update",
|
|
"read",
|
|
"delete",
|
|
"authen",
|
|
"*",
|
|
"connect",
|
|
}[a]
|
|
}
|
|
|
|
// CrudActions returns a standard set of actions for resources that support a CRUD API
|
|
func CrudActions() map[string]Action {
|
|
return map[string]Action{
|
|
ActionCreate.String(): ActionCreate,
|
|
ActionUpdate.String(): ActionUpdate,
|
|
ActionRead.String(): ActionRead,
|
|
ActionDelete.String(): ActionDelete,
|
|
}
|
|
}
|
|
|
|
// CrudlActions adds list to the standard set of actions for resources that support a CRUD API
|
|
func CrudlActions() map[string]Action {
|
|
return map[string]Action{
|
|
ActionCreate.String(): ActionCreate,
|
|
ActionUpdate.String(): ActionUpdate,
|
|
ActionRead.String(): ActionRead,
|
|
ActionDelete.String(): ActionDelete,
|
|
ActionList.String(): ActionList,
|
|
}
|
|
}
|