forked from TrueCloudLab/policy-engine
17453d3cda
* Nuke out CachedChainStorage interface * Introduce LocalOverrideStorage interface to manage local overrides * Introduce MorphRuleChainStorage interface to manage chains in the policy contract * Extend Engine interface Signed-off-by: Airat Arifullin <aarifullin@yadro.com>
48 lines
1.3 KiB
Go
48 lines
1.3 KiB
Go
package inmemory
|
|
|
|
import (
|
|
"git.frostfs.info/TrueCloudLab/policy-engine/pkg/chain"
|
|
"git.frostfs.info/TrueCloudLab/policy-engine/pkg/engine"
|
|
"git.frostfs.info/TrueCloudLab/policy-engine/pkg/resource"
|
|
)
|
|
|
|
type inmemory struct {
|
|
router engine.ChainRouter
|
|
|
|
morph engine.MorphRuleChainStorage
|
|
|
|
local engine.LocalOverrideStorage
|
|
}
|
|
|
|
// NewInMemoryLocalOverrides returns new inmemory instance of chain storage with
|
|
// local overrides manager.
|
|
func NewInMemoryLocalOverrides() engine.LocalOverrideEngine {
|
|
morph := NewInmemoryMorphRuleChainStorage()
|
|
local := NewInmemoryLocalStorage()
|
|
return &inmemory{
|
|
router: engine.NewDefaultChainRouterWithLocalOverrides(morph, local),
|
|
morph: morph,
|
|
local: local,
|
|
}
|
|
}
|
|
|
|
// NewInMemory returns new inmemory instance of chain storage.
|
|
func NewInMemory() engine.Engine {
|
|
morph := NewInmemoryMorphRuleChainStorage()
|
|
return &inmemory{
|
|
router: engine.NewDefaultChainRouter(morph),
|
|
morph: morph,
|
|
}
|
|
}
|
|
|
|
func (im *inmemory) LocalStorage() engine.LocalOverrideStorage {
|
|
return im.local
|
|
}
|
|
|
|
func (im *inmemory) MorphRuleChainStorage() engine.MorphRuleChainStorage {
|
|
return im.morph
|
|
}
|
|
|
|
func (im *inmemory) IsAllowed(name chain.Name, namespace string, r resource.Request) (status chain.Status, ruleFound bool, err error) {
|
|
return im.router.IsAllowed(name, namespace, r)
|
|
}
|