2023-10-30 15:30:23 +00:00
|
|
|
package acl
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
v2 "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/acl/v2"
|
|
|
|
aclSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/acl"
|
2023-11-16 07:58:55 +00:00
|
|
|
aperesource "git.frostfs.info/TrueCloudLab/policy-engine/pkg/resource"
|
|
|
|
nativeschema "git.frostfs.info/TrueCloudLab/policy-engine/schema/native"
|
2023-10-30 15:30:23 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Request struct {
|
|
|
|
operation string
|
|
|
|
resource *resource
|
|
|
|
properties map[string]string
|
|
|
|
}
|
|
|
|
|
2023-11-16 07:58:55 +00:00
|
|
|
var _ aperesource.Request = (*Request)(nil)
|
2023-10-30 15:30:23 +00:00
|
|
|
|
|
|
|
type resource struct {
|
|
|
|
name string
|
|
|
|
properties map[string]string
|
|
|
|
}
|
|
|
|
|
2023-11-16 07:58:55 +00:00
|
|
|
var _ aperesource.Resource = (*resource)(nil)
|
2023-10-30 15:30:23 +00:00
|
|
|
|
|
|
|
func (r *resource) Name() string {
|
|
|
|
return r.name
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *resource) Property(key string) string {
|
|
|
|
return r.properties[key]
|
|
|
|
}
|
|
|
|
|
|
|
|
func getResource(reqInfo v2.RequestInfo) *resource {
|
2023-11-16 07:58:55 +00:00
|
|
|
var name string
|
2023-10-30 15:30:23 +00:00
|
|
|
cid := reqInfo.ContainerID()
|
2023-11-16 07:58:55 +00:00
|
|
|
if oid := reqInfo.ObjectID(); oid != nil {
|
|
|
|
name = fmt.Sprintf(nativeschema.ResourceFormatRootContainerObject, cid.EncodeToString(), oid.EncodeToString())
|
|
|
|
} else {
|
|
|
|
name = fmt.Sprintf(nativeschema.ResourceFormatRootContainerObjects, cid.EncodeToString())
|
2023-10-30 15:30:23 +00:00
|
|
|
}
|
|
|
|
return &resource{
|
|
|
|
name: name,
|
|
|
|
properties: make(map[string]string),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func getProperties(_ v2.RequestInfo) map[string]string {
|
|
|
|
return map[string]string{
|
2023-11-16 07:58:55 +00:00
|
|
|
nativeschema.PropertyKeyActorPublicKey: "",
|
|
|
|
nativeschema.PropertyKeyActorRole: "",
|
2023-10-30 15:30:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func getOperation(reqInfo v2.RequestInfo) string {
|
|
|
|
switch op := reqInfo.Operation(); op {
|
|
|
|
case aclSDK.OpObjectGet:
|
2023-11-16 07:58:55 +00:00
|
|
|
return nativeschema.MethodGetObject
|
2023-10-30 15:30:23 +00:00
|
|
|
case aclSDK.OpObjectHead:
|
2023-11-16 07:58:55 +00:00
|
|
|
return nativeschema.MethodHeadObject
|
2023-10-30 15:30:23 +00:00
|
|
|
case aclSDK.OpObjectPut:
|
2023-11-16 07:58:55 +00:00
|
|
|
return nativeschema.MethodPutObject
|
2023-10-30 15:30:23 +00:00
|
|
|
case aclSDK.OpObjectDelete:
|
2023-11-16 07:58:55 +00:00
|
|
|
return nativeschema.MethodDeleteObject
|
2023-10-30 15:30:23 +00:00
|
|
|
case aclSDK.OpObjectSearch:
|
2023-11-16 07:58:55 +00:00
|
|
|
return nativeschema.MethodSearchObject
|
2023-10-30 15:30:23 +00:00
|
|
|
case aclSDK.OpObjectRange:
|
2023-11-16 07:58:55 +00:00
|
|
|
return nativeschema.MethodRangeObject
|
2023-10-30 15:30:23 +00:00
|
|
|
case aclSDK.OpObjectHash:
|
2023-11-16 07:58:55 +00:00
|
|
|
return nativeschema.MethodHashObject
|
|
|
|
default:
|
|
|
|
return ""
|
2023-10-30 15:30:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewRequest() *Request {
|
|
|
|
return &Request{
|
|
|
|
resource: new(resource),
|
|
|
|
properties: map[string]string{},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *Request) FromRequestInfo(ri v2.RequestInfo) {
|
|
|
|
r.operation = getOperation(ri)
|
|
|
|
r.resource = getResource(ri)
|
|
|
|
r.properties = getProperties(ri)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *Request) Operation() string {
|
|
|
|
return r.operation
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *Request) Property(key string) string {
|
|
|
|
return r.properties[key]
|
|
|
|
}
|
|
|
|
|
2023-11-16 07:58:55 +00:00
|
|
|
func (r *Request) Resource() aperesource.Resource {
|
2023-10-30 15:30:23 +00:00
|
|
|
return r.resource
|
|
|
|
}
|