generated from TrueCloudLab/basic
[#64] engine: Add user and group targets
All checks were successful
DCO action / DCO (pull_request) Successful in 1m6s
Tests and linters / Tests (1.20) (pull_request) Successful in 1m19s
Tests and linters / Tests (1.21) (pull_request) Successful in 1m25s
Tests and linters / Tests with -race (pull_request) Successful in 1m41s
Tests and linters / Staticcheck (pull_request) Successful in 1m42s
Tests and linters / Lint (pull_request) Successful in 2m28s
All checks were successful
DCO action / DCO (pull_request) Successful in 1m6s
Tests and linters / Tests (1.20) (pull_request) Successful in 1m19s
Tests and linters / Tests (1.21) (pull_request) Successful in 1m25s
Tests and linters / Tests with -race (pull_request) Successful in 1m41s
Tests and linters / Staticcheck (pull_request) Successful in 1m42s
Tests and linters / Lint (pull_request) Successful in 2m28s
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
parent
530248de75
commit
0e69e48511
3 changed files with 55 additions and 7 deletions
|
@ -37,6 +37,8 @@ type TargetType rune
|
|||
const (
|
||||
Namespace TargetType = 'n'
|
||||
Container TargetType = 'c'
|
||||
User TargetType = 'u'
|
||||
Group TargetType = 'g'
|
||||
)
|
||||
|
||||
type Target struct {
|
||||
|
@ -48,6 +50,8 @@ type Target struct {
|
|||
type RequestTarget struct {
|
||||
Namespace *Target
|
||||
Container *Target
|
||||
User *Target
|
||||
Groups []Target
|
||||
}
|
||||
|
||||
func NewRequestTargetWithNamespace(namespace string) RequestTarget {
|
||||
|
@ -73,6 +77,24 @@ func NewRequestTarget(namespace, container string) RequestTarget {
|
|||
}
|
||||
}
|
||||
|
||||
func NewRequestTargetExtended(namespace, container, user string, groups []string) RequestTarget {
|
||||
nt := NamespaceTarget(namespace)
|
||||
ct := ContainerTarget(container)
|
||||
u := UserTarget(user)
|
||||
rt := RequestTarget{
|
||||
Namespace: &nt,
|
||||
Container: &ct,
|
||||
User: &u,
|
||||
}
|
||||
if len(groups) != 0 {
|
||||
rt.Groups = make([]Target, len(groups))
|
||||
for i := range groups {
|
||||
rt.Groups[i] = GroupTarget(groups[i])
|
||||
}
|
||||
}
|
||||
return rt
|
||||
}
|
||||
|
||||
func (rt *RequestTarget) Targets() (targets []Target) {
|
||||
if rt.Namespace != nil {
|
||||
targets = append(targets, *rt.Namespace)
|
||||
|
@ -80,6 +102,12 @@ func (rt *RequestTarget) Targets() (targets []Target) {
|
|||
if rt.Container != nil {
|
||||
targets = append(targets, *rt.Container)
|
||||
}
|
||||
if rt.User != nil {
|
||||
targets = append(targets, *rt.User)
|
||||
}
|
||||
if len(rt.Groups) != 0 {
|
||||
targets = append(targets, rt.Groups...)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -97,6 +125,20 @@ func ContainerTarget(container string) Target {
|
|||
}
|
||||
}
|
||||
|
||||
func UserTarget(user string) Target {
|
||||
return Target{
|
||||
Type: User,
|
||||
Name: user,
|
||||
}
|
||||
}
|
||||
|
||||
func GroupTarget(group string) Target {
|
||||
return Target{
|
||||
Type: Group,
|
||||
Name: group,
|
||||
}
|
||||
}
|
||||
|
||||
// MorphRuleChainStorageReader is the interface that provides read-only methods to receive
|
||||
// data like chains, target or admin from a chain storage.
|
||||
type MorphRuleChainStorageReader interface {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue