2020-07-24 13:54:03 +00:00
|
|
|
package wrapper
|
|
|
|
|
2020-09-22 14:10:01 +00:00
|
|
|
import (
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/acl/eacl"
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/container"
|
|
|
|
client "github.com/nspcc-dev/neofs-node/pkg/morph/client/container"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
2020-07-24 13:54:03 +00:00
|
|
|
|
2020-11-24 09:45:27 +00:00
|
|
|
var errEACLNotFound = errors.New("extended ACL table is not set for this container")
|
|
|
|
|
2020-07-24 13:54:03 +00:00
|
|
|
// GetEACL reads the extended ACL table from NeoFS system
|
|
|
|
// through Container contract call.
|
2020-09-22 14:10:01 +00:00
|
|
|
func (w *Wrapper) GetEACL(cid *container.ID) (*eacl.Table, []byte, error) {
|
|
|
|
if cid == nil {
|
|
|
|
return nil, nil, errNilArgument
|
|
|
|
}
|
|
|
|
|
|
|
|
args := client.EACLArgs{}
|
|
|
|
|
|
|
|
if v2 := cid.ToV2(); v2 == nil {
|
|
|
|
return nil, nil, errUnsupported // use other major version if there any
|
|
|
|
} else {
|
|
|
|
args.SetCID(v2.GetValue())
|
|
|
|
}
|
|
|
|
|
|
|
|
rpcAnswer, err := w.client.EACL(args)
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
|
2020-11-24 09:45:27 +00:00
|
|
|
// Client may not return errors if the table is missing, so check this case additionally.
|
|
|
|
// The absence of a signature in the response can be taken as an eACL absence criterion,
|
|
|
|
// since unsigned table cannot be approved in the storage by design.
|
|
|
|
sig := rpcAnswer.Signature()
|
|
|
|
if len(sig) == 0 {
|
|
|
|
return nil, nil, errEACLNotFound
|
|
|
|
}
|
|
|
|
|
2020-11-16 10:26:35 +00:00
|
|
|
table := eacl.NewTable()
|
|
|
|
if err = table.Unmarshal(rpcAnswer.EACL()); err != nil {
|
2020-09-22 14:10:01 +00:00
|
|
|
// use other major version if there any
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
|
2020-11-24 09:45:27 +00:00
|
|
|
return table, sig, nil
|
2020-07-24 13:54:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// PutEACL saves the extended ACL table in NeoFS system
|
|
|
|
// through Container contract call.
|
|
|
|
//
|
|
|
|
// Returns any error encountered that caused the saving to interrupt.
|
2020-09-22 14:10:01 +00:00
|
|
|
func (w *Wrapper) PutEACL(table *eacl.Table, signature []byte) error {
|
|
|
|
if table == nil || len(signature) == 0 {
|
|
|
|
return errNilArgument
|
|
|
|
}
|
|
|
|
|
|
|
|
args := client.SetEACLArgs{}
|
|
|
|
args.SetSignature(signature)
|
|
|
|
|
2020-11-16 10:26:35 +00:00
|
|
|
data, err := table.Marshal()
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "can't marshal eacl table")
|
2020-09-22 14:10:01 +00:00
|
|
|
}
|
|
|
|
|
2020-11-16 10:26:35 +00:00
|
|
|
args.SetEACL(data)
|
|
|
|
|
2020-09-22 14:10:01 +00:00
|
|
|
return w.client.SetEACL(args)
|
2020-07-24 13:54:03 +00:00
|
|
|
}
|