[#525] morph/container: Accept container session token in Delete
`Delete` method of latest `Container` contract accepts binary session token as an argument. Provide `DeleteArgs.SetSessionToken` method. Accept session token as a `[]byte` in `Wrapper.Put` method and attach it to `PutArgs`. Marshal session token from `RemovalWitness` in `wrapper.Delete` function and pass it to the method. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
166e5440ab
commit
631d7b0e07
3 changed files with 17 additions and 4 deletions
|
@ -124,7 +124,7 @@ func (cp *Processor) checkDeleteContainer(e *containerEvent.Delete) error {
|
||||||
|
|
||||||
func (cp *Processor) approveDeleteContainer(e *containerEvent.Delete) {
|
func (cp *Processor) approveDeleteContainer(e *containerEvent.Delete) {
|
||||||
// FIXME: here we should try notary invoke
|
// FIXME: here we should try notary invoke
|
||||||
err := cp.cnrClient.Delete(e.ContainerID(), e.Signature())
|
err := cp.cnrClient.Delete(e.ContainerID(), e.Signature(), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cp.log.Error("could not approve delete container",
|
cp.log.Error("could not approve delete container",
|
||||||
zap.String("error", err.Error()),
|
zap.String("error", err.Error()),
|
||||||
|
|
|
@ -26,6 +26,13 @@ func (p *DeleteArgs) SetSignature(v []byte) {
|
||||||
p.sig = v
|
p.sig = v
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetSessionToken sets token of the session
|
||||||
|
// within which the container was removed
|
||||||
|
// in a NeoFS API binary format.
|
||||||
|
func (p *DeleteArgs) SetSessionToken(v []byte) {
|
||||||
|
p.token = v
|
||||||
|
}
|
||||||
|
|
||||||
// Delete invokes the call of delete container
|
// Delete invokes the call of delete container
|
||||||
// method of NeoFS Container contract.
|
// method of NeoFS Container contract.
|
||||||
func (c *Client) Delete(args DeleteArgs) error {
|
func (c *Client) Delete(args DeleteArgs) error {
|
||||||
|
|
|
@ -150,7 +150,7 @@ func (w *Wrapper) Get(cid []byte) (*container.Container, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete marshals container ID, and passes it to Wrapper's Delete method
|
// Delete marshals container ID, and passes it to Wrapper's Delete method
|
||||||
// along with signature.
|
// along with signature and session token.
|
||||||
//
|
//
|
||||||
// Returns error if container ID is nil.
|
// Returns error if container ID is nil.
|
||||||
func Delete(w *Wrapper, witness core.RemovalWitness) error {
|
func Delete(w *Wrapper, witness core.RemovalWitness) error {
|
||||||
|
@ -159,7 +159,12 @@ func Delete(w *Wrapper, witness core.RemovalWitness) error {
|
||||||
return errNilArgument
|
return errNilArgument
|
||||||
}
|
}
|
||||||
|
|
||||||
return w.Delete(id.ToV2().GetValue(), witness.Signature())
|
binToken, err := witness.SessionToken().Marshal()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("could not marshal session token: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return w.Delete(id.ToV2().GetValue(), witness.Signature(), binToken)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete removes the container from NeoFS system
|
// Delete removes the container from NeoFS system
|
||||||
|
@ -169,7 +174,7 @@ func Delete(w *Wrapper, witness core.RemovalWitness) error {
|
||||||
// the removal to interrupt.
|
// the removal to interrupt.
|
||||||
//
|
//
|
||||||
// If TryNotary is provided, calls notary contract.
|
// If TryNotary is provided, calls notary contract.
|
||||||
func (w *Wrapper) Delete(cid, signature []byte) error {
|
func (w *Wrapper) Delete(cid, signature, token []byte) error {
|
||||||
if len(signature) == 0 {
|
if len(signature) == 0 {
|
||||||
return errNilArgument
|
return errNilArgument
|
||||||
}
|
}
|
||||||
|
@ -178,6 +183,7 @@ func (w *Wrapper) Delete(cid, signature []byte) error {
|
||||||
|
|
||||||
args.SetSignature(signature)
|
args.SetSignature(signature)
|
||||||
args.SetCID(cid)
|
args.SetCID(cid)
|
||||||
|
args.SetSessionToken(token)
|
||||||
|
|
||||||
return w.client.Delete(args)
|
return w.client.Delete(args)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue