2021-05-19 12:08:56 +00:00
|
|
|
package container
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2022-12-23 17:35:35 +00:00
|
|
|
"github.com/TrueCloudLab/frostfs-node/pkg/morph/client"
|
|
|
|
"github.com/TrueCloudLab/frostfs-node/pkg/morph/event"
|
2022-07-28 16:22:32 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
2021-09-08 08:20:11 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/network/payload"
|
2021-05-19 12:08:56 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// SetEACL represents structure of notification about
|
|
|
|
// modified eACL table coming from NeoFS Container contract.
|
|
|
|
type SetEACL struct {
|
2021-09-08 08:20:11 +00:00
|
|
|
table []byte
|
2021-05-19 12:08:56 +00:00
|
|
|
signature []byte
|
|
|
|
publicKey []byte
|
2021-09-08 08:20:11 +00:00
|
|
|
token []byte
|
2021-05-25 16:30:27 +00:00
|
|
|
|
2021-09-08 08:20:11 +00:00
|
|
|
// For notary notifications only.
|
|
|
|
// Contains raw transactions of notary request.
|
|
|
|
notaryRequest *payload.P2PNotaryRequest
|
2021-05-19 12:08:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// MorphEvent implements Neo:Morph Event interface.
|
|
|
|
func (SetEACL) MorphEvent() {}
|
|
|
|
|
|
|
|
// Table returns returns eACL table in a binary NeoFS API format.
|
|
|
|
func (x SetEACL) Table() []byte {
|
|
|
|
return x.table
|
|
|
|
}
|
|
|
|
|
|
|
|
// Signature returns signature of the binary table.
|
|
|
|
func (x SetEACL) Signature() []byte {
|
|
|
|
return x.signature
|
|
|
|
}
|
|
|
|
|
|
|
|
// PublicKey returns public keys of container
|
|
|
|
// owner in a binary format.
|
|
|
|
func (x SetEACL) PublicKey() []byte {
|
|
|
|
return x.publicKey
|
|
|
|
}
|
|
|
|
|
2021-05-26 10:48:55 +00:00
|
|
|
// SessionToken returns binary token of the session
|
2021-05-25 16:30:27 +00:00
|
|
|
// within which the eACL was set.
|
|
|
|
func (x SetEACL) SessionToken() []byte {
|
|
|
|
return x.token
|
|
|
|
}
|
|
|
|
|
2021-09-08 08:20:11 +00:00
|
|
|
// NotaryRequest returns raw notary request if notification
|
|
|
|
// was received via notary service. Otherwise, returns nil.
|
|
|
|
func (x SetEACL) NotaryRequest() *payload.P2PNotaryRequest {
|
|
|
|
return x.notaryRequest
|
|
|
|
}
|
|
|
|
|
|
|
|
const expectedItemNumEACL = 4
|
|
|
|
|
2021-05-19 12:08:56 +00:00
|
|
|
// ParseSetEACL parses SetEACL notification event from list of stack items.
|
2021-05-25 14:41:20 +00:00
|
|
|
//
|
|
|
|
// Expects 4 stack items.
|
2022-07-28 16:22:32 +00:00
|
|
|
func ParseSetEACL(e *state.ContainedNotificationEvent) (event.Event, error) {
|
2021-05-19 12:08:56 +00:00
|
|
|
var (
|
|
|
|
ev SetEACL
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
|
2021-10-22 10:06:08 +00:00
|
|
|
params, err := event.ParseStackArray(e)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("could not parse stack items from notify event: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if ln := len(params); ln != expectedItemNumEACL {
|
2021-05-25 14:41:20 +00:00
|
|
|
return nil, event.WrongNumberOfParameters(expectedItemNumEACL, ln)
|
2021-05-19 12:08:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// parse table
|
2021-10-22 10:06:08 +00:00
|
|
|
ev.table, err = client.BytesFromStackItem(params[0])
|
2021-05-19 12:08:56 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("could not parse binary table: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// parse signature
|
2021-10-22 10:06:08 +00:00
|
|
|
ev.signature, err = client.BytesFromStackItem(params[1])
|
2021-05-19 12:08:56 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("could not parse table signature: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// parse public key
|
2021-10-22 10:06:08 +00:00
|
|
|
ev.publicKey, err = client.BytesFromStackItem(params[2])
|
2021-05-19 12:08:56 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("could not parse binary public key: %w", err)
|
|
|
|
}
|
|
|
|
|
2021-05-25 16:30:27 +00:00
|
|
|
// parse session token
|
2021-10-22 10:06:08 +00:00
|
|
|
ev.token, err = client.BytesFromStackItem(params[3])
|
2021-05-25 16:30:27 +00:00
|
|
|
if err != nil {
|
2021-05-26 10:53:55 +00:00
|
|
|
return nil, fmt.Errorf("could not get session token: %w", err)
|
2021-05-25 16:30:27 +00:00
|
|
|
}
|
|
|
|
|
2021-05-19 12:08:56 +00:00
|
|
|
return ev, nil
|
|
|
|
}
|