diff --git a/client/container.go b/client/container.go index 82e7c31..2cbfab5 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 d3ebdf2..fd3279c 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 2f85df0..49f11d1 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 7f71114..9501cf5 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 7fcead5..29376ff 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 8673301..5e1e5ae 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)