forked from TrueCloudLab/policy-engine
wip: support new targets in inmemory implementation
Signed-off-by: Alex Vanin <a.vanin@yadro.com>
This commit is contained in:
parent
b7767e1e3d
commit
ec0f7cb30d
2 changed files with 42 additions and 4 deletions
|
@ -21,7 +21,7 @@ func NewInmemoryMorphRuleChainStorage() engine.MorphRuleChainStorage {
|
|||
|
||||
func (s *inmemoryMorphRuleChainStorage) AddMorphRuleChain(name chain.Name, target engine.Target, c *chain.Chain) (_ util.Uint256, _ uint32, err error) {
|
||||
switch target.Type {
|
||||
case engine.Namespace, engine.Container:
|
||||
case engine.Namespace, engine.Container, engine.User, engine.Group:
|
||||
_, err = s.storage.AddOverride(name, target, c)
|
||||
default:
|
||||
err = engine.ErrUnknownTarget
|
||||
|
@ -31,7 +31,7 @@ func (s *inmemoryMorphRuleChainStorage) AddMorphRuleChain(name chain.Name, targe
|
|||
|
||||
func (s *inmemoryMorphRuleChainStorage) RemoveMorphRuleChain(name chain.Name, target engine.Target, chainID chain.ID) (_ util.Uint256, _ uint32, err error) {
|
||||
switch target.Type {
|
||||
case engine.Namespace, engine.Container:
|
||||
case engine.Namespace, engine.Container, engine.User, engine.Group:
|
||||
err = s.storage.RemoveOverride(name, target, chainID)
|
||||
default:
|
||||
err = engine.ErrUnknownTarget
|
||||
|
@ -41,7 +41,7 @@ func (s *inmemoryMorphRuleChainStorage) RemoveMorphRuleChain(name chain.Name, ta
|
|||
|
||||
func (s *inmemoryMorphRuleChainStorage) RemoveMorphRuleChainsByTarget(name chain.Name, target engine.Target) (_ util.Uint256, _ uint32, err error) {
|
||||
switch target.Type {
|
||||
case engine.Namespace, engine.Container:
|
||||
case engine.Namespace, engine.Container, engine.User, engine.Group:
|
||||
err = s.storage.RemoveOverridesByTarget(name, target)
|
||||
default:
|
||||
err = engine.ErrUnknownTarget
|
||||
|
@ -51,7 +51,7 @@ func (s *inmemoryMorphRuleChainStorage) RemoveMorphRuleChainsByTarget(name chain
|
|||
|
||||
func (s *inmemoryMorphRuleChainStorage) ListMorphRuleChains(name chain.Name, target engine.Target) ([]*chain.Chain, error) {
|
||||
switch target.Type {
|
||||
case engine.Namespace, engine.Container:
|
||||
case engine.Namespace, engine.Container, engine.User, engine.Group:
|
||||
return s.storage.ListOverrides(name, target)
|
||||
default:
|
||||
}
|
||||
|
@ -99,6 +99,40 @@ func (s *inmemoryMorphRuleChainStorage) ListTargetsIterator(targetType engine.Ta
|
|||
it.Values = append(it.Values, stackitem.NewByteArray([]byte(t.Name)))
|
||||
}
|
||||
|
||||
targets, err = s.storage.ListOverrideDefinedTargets(chain.S3)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
for _, t := range targets {
|
||||
it.Values = append(it.Values, stackitem.NewByteArray([]byte(t.Name)))
|
||||
}
|
||||
case engine.User:
|
||||
var targets []engine.Target
|
||||
targets, err = s.storage.ListOverrideDefinedTargets(chain.Ingress)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
for _, t := range targets {
|
||||
it.Values = append(it.Values, stackitem.NewByteArray([]byte(t.Name)))
|
||||
}
|
||||
|
||||
targets, err = s.storage.ListOverrideDefinedTargets(chain.S3)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
for _, t := range targets {
|
||||
it.Values = append(it.Values, stackitem.NewByteArray([]byte(t.Name)))
|
||||
}
|
||||
case engine.Group:
|
||||
var targets []engine.Target
|
||||
targets, err = s.storage.ListOverrideDefinedTargets(chain.Ingress)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
for _, t := range targets {
|
||||
it.Values = append(it.Values, stackitem.NewByteArray([]byte(t.Name)))
|
||||
}
|
||||
|
||||
targets, err = s.storage.ListOverrideDefinedTargets(chain.S3)
|
||||
if err != nil {
|
||||
return
|
||||
|
|
|
@ -209,6 +209,10 @@ func policyKind(typ engine.TargetType) (policy.Kind, error) {
|
|||
return policy.Namespace, nil
|
||||
} else if typ == engine.Container {
|
||||
return policy.Container, nil
|
||||
} else if typ == engine.User {
|
||||
return 'u', nil
|
||||
} else if typ == engine.Group {
|
||||
return 'g', nil
|
||||
}
|
||||
return policy.Kind(0), ErrEngineTargetTypeUnsupported
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue