frostfs-node/pkg/ape/router/single_pass.go
Airat Arifullin 47bcd346d3 [#1216] ape: Introduce BearerChainFeedRouter
* Unlike default chain router, `BearerChainFedRouter` performs checks for
  overrides defined in the bearer token;
* Add unit-test for the introduced router.

Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
2024-07-05 18:26:48 +00:00

30 lines
1 KiB
Go

package router
import (
"fmt"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/bearer"
apechain "git.frostfs.info/TrueCloudLab/policy-engine/pkg/chain"
"git.frostfs.info/TrueCloudLab/policy-engine/pkg/engine"
"git.frostfs.info/TrueCloudLab/policy-engine/pkg/engine/inmemory"
)
// SingleUseRouterWithBearerTokenChains creates chain router with inmemory storage implementation and
// fed with APE chains defined in Bearer token.
func SingleUseRouterWithBearerTokenChains(overrides []bearer.APEOverride) (engine.ChainRouter, error) {
storage := inmemory.NewInmemoryMorphRuleChainStorage()
for _, override := range overrides {
target, err := newTarget(override.Target)
if err != nil {
return nil, err
}
for i := range override.Chains {
chain := new(apechain.Chain)
if err := chain.DecodeBytes(override.Chains[i].Raw); err != nil {
return nil, fmt.Errorf("invalid ape chain: %w", err)
}
_, _, _ = storage.AddMorphRuleChain(apechain.Ingress, target, chain)
}
}
return engine.NewDefaultChainRouter(storage), nil
}