From e74bdaa5d5999774b5d55f006374d228ca3dd161 Mon Sep 17 00:00:00 2001 From: Dmitrii Stepanov Date: Thu, 4 Apr 2024 15:42:52 +0300 Subject: [PATCH] [#1080] ape: Use value for APE request Signed-off-by: Dmitrii Stepanov --- pkg/services/object/ape/request.go | 28 +++++++++++++------------ pkg/services/object/ape/request_test.go | 4 ++-- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/pkg/services/object/ape/request.go b/pkg/services/object/ape/request.go index bdce97676..b81fe8c32 100644 --- a/pkg/services/object/ape/request.go +++ b/pkg/services/object/ape/request.go @@ -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), }, diff --git a/pkg/services/object/ape/request_test.go b/pkg/services/object/ape/request_test.go index c5b43fa8b..71e234e78 100644 --- a/pkg/services/object/ape/request_test.go +++ b/pkg/services/object/ape/request_test.go @@ -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) }) } })