2023-12-05 09:12:35 +00:00
|
|
|
package policy
|
|
|
|
|
|
|
|
import (
|
2023-12-08 07:44:13 +00:00
|
|
|
policycontract "git.frostfs.info/TrueCloudLab/frostfs-contract/policy"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/cache"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/handler"
|
|
|
|
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
2023-12-05 09:12:35 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/policy-engine/pkg/chain"
|
|
|
|
"git.frostfs.info/TrueCloudLab/policy-engine/pkg/engine"
|
|
|
|
"git.frostfs.info/TrueCloudLab/policy-engine/pkg/resource"
|
2023-12-08 07:44:13 +00:00
|
|
|
"go.uber.org/zap"
|
2023-12-05 09:12:35 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Storage struct {
|
|
|
|
router engine.ChainRouter
|
|
|
|
|
2024-02-13 08:50:11 +00:00
|
|
|
morph *MorphRuleChainStorage
|
2023-12-08 07:44:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type StorageConfig struct {
|
|
|
|
Contract Contract
|
|
|
|
Cache *cache.MorphPolicyCache
|
|
|
|
Log *zap.Logger
|
|
|
|
}
|
|
|
|
|
2024-02-13 08:50:11 +00:00
|
|
|
type MultiTransaction interface {
|
|
|
|
AddChain(entity policycontract.Kind, entityName string, name []byte, chain []byte)
|
|
|
|
RemoveChain(entity policycontract.Kind, entityName string, name []byte)
|
|
|
|
Scripts() ([][]byte, error)
|
|
|
|
}
|
|
|
|
|
2023-12-08 07:44:13 +00:00
|
|
|
type Contract interface {
|
2024-02-13 08:50:11 +00:00
|
|
|
GetChain(entity policycontract.Kind, entityName string, name []byte) ([]byte, error)
|
|
|
|
ListChains(entity policycontract.Kind, entityName string, prefix []byte) ([][]byte, error)
|
|
|
|
|
|
|
|
StartTx() MultiTransaction
|
|
|
|
SendTx(transaction MultiTransaction) error
|
2023-12-05 09:12:35 +00:00
|
|
|
}
|
|
|
|
|
2023-12-08 07:44:13 +00:00
|
|
|
var _ handler.APE = (*Storage)(nil)
|
2023-12-05 09:12:35 +00:00
|
|
|
|
2023-12-08 07:44:13 +00:00
|
|
|
func NewStorage(cfg StorageConfig) *Storage {
|
|
|
|
morph := NewMorphRuleChainStorage(&MorphRuleChainStorageConfig{
|
|
|
|
Contract: cfg.Contract,
|
|
|
|
Cache: cfg.Cache,
|
|
|
|
Log: cfg.Log,
|
|
|
|
})
|
|
|
|
|
2023-12-05 09:12:35 +00:00
|
|
|
return &Storage{
|
2024-06-18 06:41:30 +00:00
|
|
|
router: engine.NewDefaultChainRouter(morph),
|
2023-12-05 09:12:35 +00:00
|
|
|
morph: morph,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-08 07:44:13 +00:00
|
|
|
func (s *Storage) IsAllowed(name chain.Name, target engine.RequestTarget, r resource.Request) (status chain.Status, found bool, err error) {
|
2023-12-05 09:12:35 +00:00
|
|
|
return s.router.IsAllowed(name, target, r)
|
|
|
|
}
|
|
|
|
|
2024-02-19 07:51:41 +00:00
|
|
|
func (s *Storage) PutBucketPolicy(ns string, cnrID cid.ID, policy []byte, policyChains []*chain.Chain) error {
|
|
|
|
return s.morph.PutBucketPolicy(ns, cnrID, policy, policyChains)
|
2023-12-08 07:44:13 +00:00
|
|
|
}
|
|
|
|
|
2024-04-01 09:51:05 +00:00
|
|
|
func (s *Storage) DeleteBucketPolicy(ns string, cnrID cid.ID, chainIDs []chain.ID) error {
|
|
|
|
return s.morph.DeleteBucketPolicy(ns, cnrID, chainIDs)
|
2023-12-08 07:44:13 +00:00
|
|
|
}
|
|
|
|
|
2024-02-13 08:50:11 +00:00
|
|
|
func (s *Storage) GetBucketPolicy(ns string, cnrID cid.ID) ([]byte, error) {
|
|
|
|
return s.morph.GetBucketPolicy(ns, cnrID)
|
2023-12-08 07:44:13 +00:00
|
|
|
}
|
|
|
|
|
2024-02-13 08:50:11 +00:00
|
|
|
func (s *Storage) SaveACLChains(ns string, chains []*chain.Chain) error {
|
|
|
|
return s.morph.SaveACLChains(ns, chains)
|
2023-12-08 07:44:13 +00:00
|
|
|
}
|