frostfs-node/pkg/morph/client/container/delete.go

78 lines
1.7 KiB
Go
Raw Permalink Normal View History

2020-07-24 13:54:03 +00:00
package container
import (
"crypto/sha256"
"fmt"
core "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/container"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client"
)
2020-07-24 13:54:03 +00:00
// Delete marshals container ID, and passes it to Wrapper's Delete method
// along with signature and session token.
//
// Returns error if container ID is nil.
func Delete(c *Client, witness core.RemovalWitness) error {
binCnr := make([]byte, sha256.Size)
witness.ContainerID().Encode(binCnr)
var prm DeletePrm
prm.SetCID(binCnr)
prm.SetSignature(witness.Signature())
if tok := witness.SessionToken(); tok != nil {
prm.SetToken(tok.Marshal())
}
return c.Delete(prm)
}
// DeletePrm groups parameters of Delete client operation.
type DeletePrm struct {
cnr []byte
signature []byte
token []byte
client.InvokePrmOptional
2020-07-24 13:54:03 +00:00
}
// SetCID sets container ID.
func (d *DeletePrm) SetCID(cid []byte) {
d.cnr = cid
2020-07-24 13:54:03 +00:00
}
// SetSignature sets signature.
func (d *DeletePrm) SetSignature(signature []byte) {
d.signature = signature
2020-07-24 13:54:03 +00:00
}
// SetToken sets session token.
func (d *DeletePrm) SetToken(token []byte) {
d.token = token
}
// Delete removes the container from FrostFS system
// through Container contract call.
//
// Returns any error encountered that caused
// the removal to interrupt.
//
// If TryNotary is provided, calls notary contract.
func (c *Client) Delete(p DeletePrm) error {
if len(p.signature) == 0 {
return errNilArgument
}
prm := client.InvokePrm{}
prm.SetMethod(deleteMethod)
prm.SetArgs(p.cnr, p.signature, p.token)
prm.InvokePrmOptional = p.InvokePrmOptional
err := c.client.Invoke(prm)
if err != nil {
return fmt.Errorf("could not invoke method (%s): %w", deleteMethod, err)
}
return nil
2020-07-24 13:54:03 +00:00
}