From 7a99cc916c8e436e99bb501ff5ee6a8e5307d1d9 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Mon, 1 Aug 2022 17:17:48 +0300 Subject: [PATCH] [#307] status: Support EACL_NOT_FOUND status code Signed-off-by: Pavel Karpy --- client/container.go | 3 ++- client/errors.go | 13 +++++++++++++ client/errors_test.go | 7 +++++++ client/status/container.go | 31 +++++++++++++++++++++++++++++++ client/status/v2.go | 2 ++ client/status/v2_test.go | 12 ++++++++++++ 6 files changed, 67 insertions(+), 1 deletion(-) diff --git a/client/container.go b/client/container.go index 82e7c317..2cbfab5c 100644 --- a/client/container.go +++ b/client/container.go @@ -554,7 +554,8 @@ func (x *ResContainerEACL) setTable(table *eacl.Table) { // // Return statuses: // - global (see Client docs); -// - *apistatus.ContainerNotFound. +// - *apistatus.ContainerNotFound; +// - *apistatus.EACLNotFound. func (c *Client) ContainerEACL(ctx context.Context, prm PrmContainerEACL) (*ResContainerEACL, error) { // check parameters switch { diff --git a/client/errors.go b/client/errors.go index d3ebdf25..fd3279c4 100644 --- a/client/errors.go +++ b/client/errors.go @@ -28,6 +28,19 @@ func IsErrContainerNotFound(err error) bool { } } +// IsErrEACLNotFound checks if err corresponds to NeoFS status +// return corresponding to missing eACL table. Supports wrapped errors. +func IsErrEACLNotFound(err error) bool { + switch unwrapErr(err).(type) { + default: + return false + case + apistatus.EACLNotFound, + *apistatus.EACLNotFound: + return true + } +} + // IsErrObjectNotFound checks if err corresponds to NeoFS status // return corresponding to missing object. Supports wrapped errors. func IsErrObjectNotFound(err error) bool { diff --git a/client/errors_test.go b/client/errors_test.go index 2f85df0c..49f11d11 100644 --- a/client/errors_test.go +++ b/client/errors_test.go @@ -21,6 +21,13 @@ func TestErrors(t *testing.T) { new(apistatus.ContainerNotFound), }, }, + { + check: client.IsErrEACLNotFound, + errs: []error{ + apistatus.EACLNotFound{}, + new(apistatus.EACLNotFound), + }, + }, { check: client.IsErrObjectNotFound, errs: []error{ diff --git a/client/status/container.go b/client/status/container.go index 7f71114b..9501cf54 100644 --- a/client/status/container.go +++ b/client/status/container.go @@ -34,3 +34,34 @@ func (x ContainerNotFound) ToStatusV2() *status.Status { x.v2.SetMessage("container not found") return &x.v2 } + +// EACLNotFound describes status of the failure because of the missing eACL +// table. +// Instances provide Status and StatusV2 interfaces. +type EACLNotFound struct { + v2 status.Status +} + +func (x EACLNotFound) Error() string { + return errMessageStatusV2( + globalizeCodeV2(container.StatusEACLNotFound, container.GlobalizeFail), + x.v2.Message(), + ) +} + +// implements local interface defined in FromStatusV2 func. +func (x *EACLNotFound) fromStatusV2(st *status.Status) { + x.v2 = *st +} + +// ToStatusV2 implements StatusV2 interface method. +// If the value was returned by FromStatusV2, returns the source message. +// Otherwise, returns message with +// * code: EACL_NOT_FOUND; +// * string message: "eACL not found"; +// * details: empty. +func (x EACLNotFound) ToStatusV2() *status.Status { + x.v2.SetCode(globalizeCodeV2(container.StatusEACLNotFound, container.GlobalizeFail)) + x.v2.SetMessage("eACL not found") + return &x.v2 +} diff --git a/client/status/v2.go b/client/status/v2.go index 7fcead50..29376ff9 100644 --- a/client/status/v2.go +++ b/client/status/v2.go @@ -79,6 +79,8 @@ func FromStatusV2(st *status.Status) Status { switch code { case container.StatusNotFound: decoder = new(ContainerNotFound) + case container.StatusEACLNotFound: + decoder = new(EACLNotFound) } case session.LocalizeFailStatus(&code): //nolint:exhaustive diff --git a/client/status/v2_test.go b/client/status/v2_test.go index 86733011..5e1e5aee 100644 --- a/client/status/v2_test.go +++ b/client/status/v2_test.go @@ -107,6 +107,12 @@ func TestToStatusV2(t *testing.T) { }), codeV2: 3072, }, + { + status: (statusConstructor)(func() apistatus.Status { + return new(apistatus.EACLNotFound) + }), + codeV2: 3073, + }, { status: (statusConstructor)(func() apistatus.Status { return new(apistatus.SessionTokenNotFound) @@ -248,6 +254,12 @@ func TestFromStatusV2(t *testing.T) { }), codeV2: 3072, }, + { + status: (statusConstructor)(func() apistatus.Status { + return new(apistatus.EACLNotFound) + }), + codeV2: 3073, + }, { status: (statusConstructor)(func() apistatus.Status { return new(apistatus.SessionTokenNotFound)