forked from TrueCloudLab/frostfs-node
[#1080] ape: Use value for APE request
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
338d8cbebd
commit
e74bdaa5d5
2 changed files with 17 additions and 15 deletions
|
@ -17,36 +17,38 @@ import (
|
||||||
|
|
||||||
type request struct {
|
type request struct {
|
||||||
operation string
|
operation string
|
||||||
resource *resource
|
resource resource
|
||||||
properties map[string]string
|
properties map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ aperesource.Request = (*request)(nil)
|
var defaultRequest = request{}
|
||||||
|
|
||||||
|
var _ aperesource.Request = request{}
|
||||||
|
|
||||||
type resource struct {
|
type resource struct {
|
||||||
name string
|
name string
|
||||||
properties map[string]string
|
properties map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ aperesource.Resource = (*resource)(nil)
|
var _ aperesource.Resource = resource{}
|
||||||
|
|
||||||
func (r *resource) Name() string {
|
func (r resource) Name() string {
|
||||||
return r.name
|
return r.name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *resource) Property(key string) string {
|
func (r resource) Property(key string) string {
|
||||||
return r.properties[key]
|
return r.properties[key]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *request) Operation() string {
|
func (r request) Operation() string {
|
||||||
return r.operation
|
return r.operation
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *request) Property(key string) string {
|
func (r request) Property(key string) string {
|
||||||
return r.properties[key]
|
return r.properties[key]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *request) Resource() aperesource.Resource {
|
func (r request) Resource() aperesource.Resource {
|
||||||
return r.resource
|
return r.resource
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,7 +125,7 @@ func objectProperties(cnr cid.ID, oid *oid.ID, cnrOwner user.ID, header *objectV
|
||||||
// newAPERequest creates an APE request to be passed to a chain router. It collects resource properties from
|
// newAPERequest creates an APE request to be passed to a chain router. It collects resource properties from
|
||||||
// header provided by headerProvider. If it cannot be found in headerProvider, then properties are
|
// header provided by headerProvider. If it cannot be found in headerProvider, then properties are
|
||||||
// initialized from header given in prm (if it is set). Otherwise, just CID and OID are set to properties.
|
// initialized from header given in prm (if it is set). Otherwise, just CID and OID are set to properties.
|
||||||
func (c *checkerImpl) newAPERequest(ctx context.Context, prm Prm) (*request, error) {
|
func (c *checkerImpl) newAPERequest(ctx context.Context, prm Prm) (request, error) {
|
||||||
switch prm.Method {
|
switch prm.Method {
|
||||||
case nativeschema.MethodGetObject,
|
case nativeschema.MethodGetObject,
|
||||||
nativeschema.MethodHeadObject,
|
nativeschema.MethodHeadObject,
|
||||||
|
@ -131,11 +133,11 @@ func (c *checkerImpl) newAPERequest(ctx context.Context, prm Prm) (*request, err
|
||||||
nativeschema.MethodHashObject,
|
nativeschema.MethodHashObject,
|
||||||
nativeschema.MethodDeleteObject:
|
nativeschema.MethodDeleteObject:
|
||||||
if prm.Object == nil {
|
if prm.Object == nil {
|
||||||
return nil, fmt.Errorf("method %s: %w", prm.Method, errMissingOID)
|
return defaultRequest, fmt.Errorf("method %s: %w", prm.Method, errMissingOID)
|
||||||
}
|
}
|
||||||
case nativeschema.MethodSearchObject, nativeschema.MethodPutObject:
|
case nativeschema.MethodSearchObject, nativeschema.MethodPutObject:
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("unknown method: %s", prm.Method)
|
return defaultRequest, fmt.Errorf("unknown method: %s", prm.Method)
|
||||||
}
|
}
|
||||||
|
|
||||||
var header *objectV2.Header
|
var header *objectV2.Header
|
||||||
|
@ -148,9 +150,9 @@ func (c *checkerImpl) newAPERequest(ctx context.Context, prm Prm) (*request, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return &request{
|
return request{
|
||||||
operation: prm.Method,
|
operation: prm.Method,
|
||||||
resource: &resource{
|
resource: resource{
|
||||||
name: resourceName(prm.Container, prm.Object, prm.Namespace),
|
name: resourceName(prm.Container, prm.Object, prm.Namespace),
|
||||||
properties: objectProperties(prm.Container, prm.Object, prm.ContainerOwner, header),
|
properties: objectProperties(prm.Container, prm.Object, prm.ContainerOwner, header),
|
||||||
},
|
},
|
||||||
|
|
|
@ -258,7 +258,7 @@ func TestNewAPERequest(t *testing.T) {
|
||||||
|
|
||||||
expectedRequest := request{
|
expectedRequest := request{
|
||||||
operation: method,
|
operation: method,
|
||||||
resource: &resource{
|
resource: resource{
|
||||||
name: resourceName(cnr, obj, prm.Namespace),
|
name: resourceName(cnr, obj, prm.Namespace),
|
||||||
properties: objectProperties(cnr, obj, testCnrOwner, func() *objectV2.Header {
|
properties: objectProperties(cnr, obj, testCnrOwner, func() *objectV2.Header {
|
||||||
if headerObjSDK != nil {
|
if headerObjSDK != nil {
|
||||||
|
@ -273,7 +273,7 @@ func TestNewAPERequest(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
require.Equal(t, expectedRequest, *r)
|
require.Equal(t, expectedRequest, r)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue