forked from TrueCloudLab/policy-engine
53 lines
1.6 KiB
Go
53 lines
1.6 KiB
Go
|
package inmemory
|
||
|
|
||
|
import (
|
||
|
"git.frostfs.info/TrueCloudLab/policy-engine/pkg/chain"
|
||
|
"git.frostfs.info/TrueCloudLab/policy-engine/pkg/engine"
|
||
|
)
|
||
|
|
||
|
type inmemoryMorphRuleChainStorage struct {
|
||
|
nameToNamespaceChains engine.LocalOverrideStorage
|
||
|
nameToContainerChains engine.LocalOverrideStorage
|
||
|
}
|
||
|
|
||
|
func NewInmemoryMorphRuleChainStorage() engine.MorphRuleChainStorage {
|
||
|
return &inmemoryMorphRuleChainStorage{
|
||
|
nameToNamespaceChains: NewInmemoryLocalStorage(),
|
||
|
nameToContainerChains: NewInmemoryLocalStorage(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (s *inmemoryMorphRuleChainStorage) AddMorphRuleChain(name chain.Name, target engine.Target, c *chain.Chain) (err error) {
|
||
|
switch target.Type {
|
||
|
case engine.Namespace:
|
||
|
_, err = s.nameToNamespaceChains.AddOverride(name, target.Name, c)
|
||
|
case engine.Container:
|
||
|
_, err = s.nameToContainerChains.AddOverride(name, target.Name, c)
|
||
|
default:
|
||
|
err = engine.ErrUnknownTarget
|
||
|
}
|
||
|
return
|
||
|
}
|
||
|
|
||
|
func (s *inmemoryMorphRuleChainStorage) RemoveMorphRuleChain(name chain.Name, target engine.Target, chainID chain.ID) error {
|
||
|
switch target.Type {
|
||
|
case engine.Namespace:
|
||
|
return s.nameToNamespaceChains.RemoveOverride(name, target.Name, chainID)
|
||
|
case engine.Container:
|
||
|
return s.nameToContainerChains.RemoveOverride(name, target.Name, chainID)
|
||
|
default:
|
||
|
return engine.ErrUnknownTarget
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (s *inmemoryMorphRuleChainStorage) ListMorphRuleChains(name chain.Name, target engine.Target) ([]*chain.Chain, error) {
|
||
|
switch target.Type {
|
||
|
case engine.Namespace:
|
||
|
return s.nameToNamespaceChains.ListOverrides(name, target.Name)
|
||
|
case engine.Container:
|
||
|
return s.nameToContainerChains.ListOverrides(name, target.Name)
|
||
|
default:
|
||
|
}
|
||
|
return nil, engine.ErrUnknownTarget
|
||
|
}
|