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"
|
|
|
|
"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
|
|
|
|
}
|
|
|
|
|
2023-12-01 15:12:57 +00:00
|
|
|
func (im *inmemory) IsAllowed(name chain.Name, rt engine.RequestTarget, r resource.Request) (status chain.Status, ruleFound bool, err error) {
|
|
|
|
return im.router.IsAllowed(name, rt, r)
|
2023-11-07 18:29:51 +00:00
|
|
|
}
|