[#1080] ape: Use value for APE request

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2024-04-04 15:42:52 +03:00
parent 4b902be81e
commit 7809928b64
2 changed files with 17 additions and 15 deletions

View file

@ -17,36 +17,38 @@ import (
type request struct {
operation string
resource *resource
resource resource
properties map[string]string
}
var _ aperesource.Request = (*request)(nil)
var defaultRequest = request{}
var _ aperesource.Request = request{}
type resource struct {
name 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
}
func (r *resource) Property(key string) string {
func (r resource) Property(key string) string {
return r.properties[key]
}
func (r *request) Operation() string {
func (r request) Operation() string {
return r.operation
}
func (r *request) Property(key string) string {
func (r request) Property(key string) string {
return r.properties[key]
}
func (r *request) Resource() aperesource.Resource {
func (r request) Resource() aperesource.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
// 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.
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 {
case nativeschema.MethodGetObject,
nativeschema.MethodHeadObject,
@ -131,11 +133,11 @@ func (c *checkerImpl) newAPERequest(ctx context.Context, prm Prm) (*request, err
nativeschema.MethodHashObject,
nativeschema.MethodDeleteObject:
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:
default:
return nil, fmt.Errorf("unknown method: %s", prm.Method)
return defaultRequest, fmt.Errorf("unknown method: %s", prm.Method)
}
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,
resource: &resource{
resource: resource{
name: resourceName(prm.Container, prm.Object, prm.Namespace),
properties: objectProperties(prm.Container, prm.Object, prm.ContainerOwner, header),
},

View file

@ -258,7 +258,7 @@ func TestNewAPERequest(t *testing.T) {
expectedRequest := request{
operation: method,
resource: &resource{
resource: resource{
name: resourceName(cnr, obj, prm.Namespace),
properties: objectProperties(cnr, obj, testCnrOwner, func() *objectV2.Header {
if headerObjSDK != nil {
@ -273,7 +273,7 @@ func TestNewAPERequest(t *testing.T) {
},
}
require.Equal(t, expectedRequest, *r)
require.Equal(t, expectedRequest, r)
})
}
})