2023-11-07 18:29:51 +00:00
|
|
|
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:
|
2023-12-01 13:08:52 +00:00
|
|
|
_, err = s.nameToNamespaceChains.AddOverride(name, target, c)
|
2023-11-07 18:29:51 +00:00
|
|
|
case engine.Container:
|
2023-12-01 13:08:52 +00:00
|
|
|
_, err = s.nameToContainerChains.AddOverride(name, target, c)
|
2023-11-07 18:29:51 +00:00
|
|
|
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:
|
2023-12-01 13:08:52 +00:00
|
|
|
return s.nameToNamespaceChains.RemoveOverride(name, target, chainID)
|
2023-11-07 18:29:51 +00:00
|
|
|
case engine.Container:
|
2023-12-01 13:08:52 +00:00
|
|
|
return s.nameToContainerChains.RemoveOverride(name, target, chainID)
|
2023-11-07 18:29:51 +00:00
|
|
|
default:
|
|
|
|
return engine.ErrUnknownTarget
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *inmemoryMorphRuleChainStorage) ListMorphRuleChains(name chain.Name, target engine.Target) ([]*chain.Chain, error) {
|
|
|
|
switch target.Type {
|
|
|
|
case engine.Namespace:
|
2023-12-01 13:08:52 +00:00
|
|
|
return s.nameToNamespaceChains.ListOverrides(name, target)
|
2023-11-07 18:29:51 +00:00
|
|
|
case engine.Container:
|
2023-12-01 13:08:52 +00:00
|
|
|
return s.nameToContainerChains.ListOverrides(name, target)
|
2023-11-07 18:29:51 +00:00
|
|
|
default:
|
|
|
|
}
|
|
|
|
return nil, engine.ErrUnknownTarget
|
|
|
|
}
|