[#307] status: Support EACL_NOT_FOUND status code

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2022-08-01 17:17:48 +03:00 committed by Stanislav Bogatyrev
parent a0f7c903d3
commit 7a99cc916c
6 changed files with 67 additions and 1 deletions

View file

@ -554,7 +554,8 @@ func (x *ResContainerEACL) setTable(table *eacl.Table) {
// //
// Return statuses: // Return statuses:
// - global (see Client docs); // - global (see Client docs);
// - *apistatus.ContainerNotFound. // - *apistatus.ContainerNotFound;
// - *apistatus.EACLNotFound.
func (c *Client) ContainerEACL(ctx context.Context, prm PrmContainerEACL) (*ResContainerEACL, error) { func (c *Client) ContainerEACL(ctx context.Context, prm PrmContainerEACL) (*ResContainerEACL, error) {
// check parameters // check parameters
switch { switch {

View file

@ -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 // IsErrObjectNotFound checks if err corresponds to NeoFS status
// return corresponding to missing object. Supports wrapped errors. // return corresponding to missing object. Supports wrapped errors.
func IsErrObjectNotFound(err error) bool { func IsErrObjectNotFound(err error) bool {

View file

@ -21,6 +21,13 @@ func TestErrors(t *testing.T) {
new(apistatus.ContainerNotFound), new(apistatus.ContainerNotFound),
}, },
}, },
{
check: client.IsErrEACLNotFound,
errs: []error{
apistatus.EACLNotFound{},
new(apistatus.EACLNotFound),
},
},
{ {
check: client.IsErrObjectNotFound, check: client.IsErrObjectNotFound,
errs: []error{ errs: []error{

View file

@ -34,3 +34,34 @@ func (x ContainerNotFound) ToStatusV2() *status.Status {
x.v2.SetMessage("container not found") x.v2.SetMessage("container not found")
return &x.v2 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
}

View file

@ -79,6 +79,8 @@ func FromStatusV2(st *status.Status) Status {
switch code { switch code {
case container.StatusNotFound: case container.StatusNotFound:
decoder = new(ContainerNotFound) decoder = new(ContainerNotFound)
case container.StatusEACLNotFound:
decoder = new(EACLNotFound)
} }
case session.LocalizeFailStatus(&code): case session.LocalizeFailStatus(&code):
//nolint:exhaustive //nolint:exhaustive

View file

@ -107,6 +107,12 @@ func TestToStatusV2(t *testing.T) {
}), }),
codeV2: 3072, codeV2: 3072,
}, },
{
status: (statusConstructor)(func() apistatus.Status {
return new(apistatus.EACLNotFound)
}),
codeV2: 3073,
},
{ {
status: (statusConstructor)(func() apistatus.Status { status: (statusConstructor)(func() apistatus.Status {
return new(apistatus.SessionTokenNotFound) return new(apistatus.SessionTokenNotFound)
@ -248,6 +254,12 @@ func TestFromStatusV2(t *testing.T) {
}), }),
codeV2: 3072, codeV2: 3072,
}, },
{
status: (statusConstructor)(func() apistatus.Status {
return new(apistatus.EACLNotFound)
}),
codeV2: 3073,
},
{ {
status: (statusConstructor)(func() apistatus.Status { status: (statusConstructor)(func() apistatus.Status {
return new(apistatus.SessionTokenNotFound) return new(apistatus.SessionTokenNotFound)