Dmitrii Stepanov
eac61fe9b2
Some checks failed
DCO action / DCO (pull_request) Successful in 1m14s
Vulncheck / Vulncheck (pull_request) Failing after 3m22s
Build / Build Components (1.20) (pull_request) Successful in 3m16s
Build / Build Components (1.21) (pull_request) Successful in 3m13s
Tests and linters / Tests (1.21) (pull_request) Successful in 5m2s
Tests and linters / Tests (1.20) (pull_request) Successful in 5m8s
Tests and linters / Staticcheck (pull_request) Successful in 4m57s
Tests and linters / Tests with -race (pull_request) Successful in 5m3s
Tests and linters / Lint (pull_request) Successful in 5m24s
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
84 lines
1.9 KiB
Go
84 lines
1.9 KiB
Go
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"
|
|
)
|
|
|
|
// 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.GetSign())
|
|
prm.SetKey(witness.Signature.GetKey())
|
|
|
|
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
|
|
key []byte
|
|
|
|
client.InvokePrmOptional
|
|
}
|
|
|
|
// SetCID sets container ID.
|
|
func (d *DeletePrm) SetCID(cid []byte) {
|
|
d.cnr = cid
|
|
}
|
|
|
|
// SetSignature sets signature.
|
|
func (d *DeletePrm) SetSignature(signature []byte) {
|
|
d.signature = signature
|
|
}
|
|
|
|
// SetToken sets session token.
|
|
func (d *DeletePrm) SetToken(token []byte) {
|
|
d.token = token
|
|
}
|
|
|
|
// SetKey sets public key.
|
|
func (d *DeletePrm) SetKey(key []byte) {
|
|
d.key = key
|
|
}
|
|
|
|
// 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 && !p.IsControl() {
|
|
return errNilArgument
|
|
}
|
|
|
|
prm := client.InvokePrm{}
|
|
prm.SetMethod(deleteMethod)
|
|
prm.SetArgs(p.cnr, p.signature, p.key, 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
|
|
}
|