2020-07-24 13:54:03 +00:00
|
|
|
package container
|
|
|
|
|
2021-05-18 08:12:51 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
2021-11-09 20:52:29 +00:00
|
|
|
|
2022-12-23 17:35:35 +00:00
|
|
|
"github.com/TrueCloudLab/frostfs-api-go/v2/refs"
|
|
|
|
containercore "github.com/TrueCloudLab/frostfs-node/pkg/core/container"
|
|
|
|
"github.com/TrueCloudLab/frostfs-node/pkg/morph/client"
|
2021-05-18 08:12:51 +00:00
|
|
|
)
|
2020-07-24 13:54:03 +00:00
|
|
|
|
2022-01-31 13:34:01 +00:00
|
|
|
// PutEACL marshals table, and passes it to Wrapper's PutEACLBinary method
|
|
|
|
// along with sig.Key() and sig.Sign().
|
|
|
|
//
|
|
|
|
// Returns error if table is nil.
|
|
|
|
//
|
|
|
|
// If TryNotary is provided, calls notary contract.
|
2022-06-22 10:55:31 +00:00
|
|
|
func PutEACL(c *Client, eaclInfo containercore.EACL) error {
|
|
|
|
if eaclInfo.Value == nil {
|
2022-01-31 13:34:01 +00:00
|
|
|
return errNilArgument
|
|
|
|
}
|
|
|
|
|
2022-06-22 10:55:31 +00:00
|
|
|
data, err := eaclInfo.Value.Marshal()
|
2022-01-31 13:34:01 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("can't marshal eacl table: %w", err)
|
|
|
|
}
|
|
|
|
|
2022-05-16 13:15:31 +00:00
|
|
|
var prm PutEACLPrm
|
|
|
|
prm.SetTable(data)
|
2022-05-18 15:20:08 +00:00
|
|
|
|
2022-06-22 10:55:31 +00:00
|
|
|
if eaclInfo.Session != nil {
|
|
|
|
prm.SetToken(eaclInfo.Session.Marshal())
|
2022-05-18 15:20:08 +00:00
|
|
|
}
|
2021-05-19 11:55:37 +00:00
|
|
|
|
2022-06-22 10:55:31 +00:00
|
|
|
// TODO(@cthulhu-rider): #1387 implement and use another approach to avoid conversion
|
|
|
|
var sigV2 refs.Signature
|
|
|
|
eaclInfo.Signature.WriteToV2(&sigV2)
|
2022-05-16 13:15:31 +00:00
|
|
|
|
2022-06-22 10:55:31 +00:00
|
|
|
prm.SetKey(sigV2.GetKey())
|
|
|
|
prm.SetSignature(sigV2.GetSign())
|
2022-05-16 13:15:31 +00:00
|
|
|
|
|
|
|
return c.PutEACL(prm)
|
2022-01-31 13:34:01 +00:00
|
|
|
}
|
2021-05-25 14:15:27 +00:00
|
|
|
|
2022-01-31 13:34:01 +00:00
|
|
|
// PutEACLPrm groups parameters of PutEACL operation.
|
|
|
|
type PutEACLPrm struct {
|
|
|
|
table []byte
|
|
|
|
key []byte
|
|
|
|
sig []byte
|
|
|
|
token []byte
|
2021-11-12 15:14:55 +00:00
|
|
|
|
|
|
|
client.InvokePrmOptional
|
2020-07-24 13:54:03 +00:00
|
|
|
}
|
|
|
|
|
2022-01-31 13:34:01 +00:00
|
|
|
// SetTable sets table.
|
|
|
|
func (p *PutEACLPrm) SetTable(table []byte) {
|
|
|
|
p.table = table
|
2020-07-24 13:54:03 +00:00
|
|
|
}
|
|
|
|
|
2022-01-31 13:34:01 +00:00
|
|
|
// SetKey sets key.
|
|
|
|
func (p *PutEACLPrm) SetKey(key []byte) {
|
|
|
|
p.key = key
|
2020-07-24 13:54:03 +00:00
|
|
|
}
|
|
|
|
|
2022-01-31 13:34:01 +00:00
|
|
|
// SetSignature sets signature.
|
|
|
|
func (p *PutEACLPrm) SetSignature(sig []byte) {
|
|
|
|
p.sig = sig
|
2021-05-19 11:55:37 +00:00
|
|
|
}
|
|
|
|
|
2022-01-31 13:34:01 +00:00
|
|
|
// SetToken sets session token.
|
|
|
|
func (p *PutEACLPrm) SetToken(token []byte) {
|
|
|
|
p.token = token
|
2021-05-25 16:16:57 +00:00
|
|
|
}
|
|
|
|
|
2022-01-31 13:34:01 +00:00
|
|
|
// PutEACL saves binary eACL table with its session token, key and signature
|
|
|
|
// in NeoFS system through Container contract call.
|
|
|
|
//
|
|
|
|
// Returns any error encountered that caused the saving to interrupt.
|
|
|
|
func (c *Client) PutEACL(p PutEACLPrm) error {
|
|
|
|
if len(p.sig) == 0 || len(p.key) == 0 {
|
|
|
|
return errNilArgument
|
|
|
|
}
|
2021-11-09 20:52:29 +00:00
|
|
|
|
2022-01-31 13:34:01 +00:00
|
|
|
prm := client.InvokePrm{}
|
2022-01-29 13:06:36 +00:00
|
|
|
prm.SetMethod(setEACLMethod)
|
2022-01-31 13:34:01 +00:00
|
|
|
prm.SetArgs(p.table, p.sig, p.key, p.token)
|
|
|
|
prm.InvokePrmOptional = p.InvokePrmOptional
|
2021-11-09 20:52:29 +00:00
|
|
|
|
|
|
|
err := c.client.Invoke(prm)
|
2021-05-18 08:12:51 +00:00
|
|
|
if err != nil {
|
2022-01-29 13:06:36 +00:00
|
|
|
return fmt.Errorf("could not invoke method (%s): %w", setEACLMethod, err)
|
2021-05-18 08:12:51 +00:00
|
|
|
}
|
|
|
|
return nil
|
2020-07-24 13:54:03 +00:00
|
|
|
}
|