forked from TrueCloudLab/policy-engine
df15b38c63
* Make changing state methods like AddMorphRuleChain, RemoveMorphRuleChain return transaction hash and VUB. Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
54 lines
1.7 KiB
Go
54 lines
1.7 KiB
Go
package inmemory
|
|
|
|
import (
|
|
"git.frostfs.info/TrueCloudLab/policy-engine/pkg/chain"
|
|
"git.frostfs.info/TrueCloudLab/policy-engine/pkg/engine"
|
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
|
)
|
|
|
|
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) (_ util.Uint256, _ uint32, err error) {
|
|
switch target.Type {
|
|
case engine.Namespace:
|
|
_, err = s.nameToNamespaceChains.AddOverride(name, target, c)
|
|
case engine.Container:
|
|
_, err = s.nameToContainerChains.AddOverride(name, target, c)
|
|
default:
|
|
err = engine.ErrUnknownTarget
|
|
}
|
|
return
|
|
}
|
|
|
|
func (s *inmemoryMorphRuleChainStorage) RemoveMorphRuleChain(name chain.Name, target engine.Target, chainID chain.ID) (_ util.Uint256, _ uint32, err error) {
|
|
switch target.Type {
|
|
case engine.Namespace:
|
|
err = s.nameToNamespaceChains.RemoveOverride(name, target, chainID)
|
|
case engine.Container:
|
|
err = s.nameToContainerChains.RemoveOverride(name, target, chainID)
|
|
default:
|
|
err = engine.ErrUnknownTarget
|
|
}
|
|
return
|
|
}
|
|
|
|
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)
|
|
case engine.Container:
|
|
return s.nameToContainerChains.ListOverrides(name, target)
|
|
default:
|
|
}
|
|
return nil, engine.ErrUnknownTarget
|
|
}
|