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 }