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"
|
2023-11-29 13:36:54 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
2023-11-07 18:29:51 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type inmemoryMorphRuleChainStorage struct {
|
|
|
|
nameToNamespaceChains engine.LocalOverrideStorage
|
|
|
|
nameToContainerChains engine.LocalOverrideStorage
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewInmemoryMorphRuleChainStorage() engine.MorphRuleChainStorage {
|
|
|
|
return &inmemoryMorphRuleChainStorage{
|
|
|
|
nameToNamespaceChains: NewInmemoryLocalStorage(),
|
|
|
|
nameToContainerChains: NewInmemoryLocalStorage(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-29 13:36:54 +00:00
|
|
|
func (s *inmemoryMorphRuleChainStorage) AddMorphRuleChain(name chain.Name, target engine.Target, c *chain.Chain) (_ util.Uint256, _ uint32, err error) {
|
2023-11-07 18:29:51 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2023-11-29 13:36:54 +00:00
|
|
|
func (s *inmemoryMorphRuleChainStorage) RemoveMorphRuleChain(name chain.Name, target engine.Target, chainID chain.ID) (_ util.Uint256, _ uint32, err error) {
|
2023-11-07 18:29:51 +00:00
|
|
|
switch target.Type {
|
|
|
|
case engine.Namespace:
|
2023-11-29 13:36:54 +00:00
|
|
|
err = s.nameToNamespaceChains.RemoveOverride(name, target, chainID)
|
2023-11-07 18:29:51 +00:00
|
|
|
case engine.Container:
|
2023-11-29 13:36:54 +00:00
|
|
|
err = s.nameToContainerChains.RemoveOverride(name, target, chainID)
|
2023-11-07 18:29:51 +00:00
|
|
|
default:
|
2023-11-29 13:36:54 +00:00
|
|
|
err = engine.ErrUnknownTarget
|
2023-11-07 18:29:51 +00:00
|
|
|
}
|
2023-11-29 13:36:54 +00:00
|
|
|
return
|
2023-11-07 18:29:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
2024-02-26 15:19:37 +00:00
|
|
|
|
|
|
|
func (s *inmemoryMorphRuleChainStorage) GetAdmin() (util.Uint160, error) {
|
|
|
|
panic("not implemented")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *inmemoryMorphRuleChainStorage) SetAdmin(_ util.Uint160) (util.Uint256, uint32, error) {
|
|
|
|
panic("not implemented")
|
|
|
|
}
|