46 lines
1.3 KiB
Go
46 lines
1.3 KiB
Go
package policy
|
|
|
|
import (
|
|
policycontract "git.frostfs.info/TrueCloudLab/frostfs-contract/policy"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/handler"
|
|
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
type MorphPolicyStorage struct {
|
|
contract Contract
|
|
}
|
|
|
|
type MorphPolicyStorageConfig struct {
|
|
Contract Contract
|
|
Log *zap.Logger
|
|
}
|
|
|
|
var _ handler.PolicyStorage = (*MorphPolicyStorage)(nil)
|
|
|
|
const policyStoragePrefix = 'b'
|
|
|
|
func NewMorphPolicyStorage(config *MorphPolicyStorageConfig) *MorphPolicyStorage {
|
|
return &MorphPolicyStorage{
|
|
contract: config.Contract,
|
|
}
|
|
}
|
|
|
|
func (c *MorphPolicyStorage) PutPolicy(namespace string, cnrID cid.ID, policy []byte) error {
|
|
name := getPolicyStorageName(cnrID)
|
|
return c.contract.Wait(c.contract.AddChain(policycontract.IAM, namespace, name, policy))
|
|
}
|
|
|
|
func (c *MorphPolicyStorage) GetPolicy(namespace string, cnrID cid.ID) ([]byte, error) {
|
|
name := getPolicyStorageName(cnrID)
|
|
return c.contract.GetChain(policycontract.IAM, namespace, name)
|
|
}
|
|
|
|
func (c *MorphPolicyStorage) DeletePolicy(namespace string, cnrID cid.ID) error {
|
|
name := getPolicyStorageName(cnrID)
|
|
return c.contract.Wait(c.contract.RemoveChain(policycontract.IAM, namespace, name))
|
|
}
|
|
|
|
func getPolicyStorageName(cnrID cid.ID) []byte {
|
|
return append([]byte{policyStoragePrefix}, cnrID[:]...)
|
|
}
|