forked from TrueCloudLab/frostfs-sdk-go
[#307] status: Support EACL_NOT_FOUND status code
Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
parent
a0f7c903d3
commit
7a99cc916c
6 changed files with 67 additions and 1 deletions
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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{
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue