forked from TrueCloudLab/frostfs-node
35 lines
951 B
Go
35 lines
951 B
Go
package main
|
|
|
|
import (
|
|
"sync"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/container"
|
|
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
|
"git.frostfs.info/TrueCloudLab/policy-engine/pkg/engine"
|
|
"git.frostfs.info/TrueCloudLab/policy-engine/pkg/engine/inmemory"
|
|
)
|
|
|
|
type apeChainSourceImpl struct {
|
|
mtx sync.Mutex
|
|
localChainStorage map[cid.ID]engine.LocalOverrideEngine
|
|
}
|
|
|
|
func NewAPESource() container.AccessPolicyEngineChainSource {
|
|
return &apeChainSourceImpl{
|
|
localChainStorage: make(map[cid.ID]engine.LocalOverrideEngine),
|
|
}
|
|
}
|
|
|
|
var _ container.AccessPolicyEngineChainSource = (*apeChainSourceImpl)(nil)
|
|
|
|
func (c *apeChainSourceImpl) GetChainSource(cid cid.ID) (engine.LocalOverrideEngine, error) {
|
|
c.mtx.Lock()
|
|
defer c.mtx.Unlock()
|
|
|
|
s, ok := c.localChainStorage[cid]
|
|
if ok {
|
|
return s, nil
|
|
}
|
|
c.localChainStorage[cid] = inmemory.NewInMemoryLocalOverrides()
|
|
return c.localChainStorage[cid], nil
|
|
}
|