2020-07-24 13:54:03 +00:00
|
|
|
package container
|
|
|
|
|
2021-05-18 08:12:51 +00:00
|
|
|
import (
|
2024-10-21 13:27:28 +00:00
|
|
|
"context"
|
2022-05-12 16:37:46 +00:00
|
|
|
"crypto/sha256"
|
2021-05-18 08:12:51 +00:00
|
|
|
"fmt"
|
2021-11-09 20:52:29 +00:00
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
core "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/container"
|
|
|
|
"git.frostfs.info/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
|
|
|
// 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.
|
2024-10-21 13:27:28 +00:00
|
|
|
func Delete(ctx context.Context, c *Client, witness core.RemovalWitness) error {
|
2022-05-12 16:37:46 +00:00
|
|
|
binCnr := make([]byte, sha256.Size)
|
2023-06-01 08:55:06 +00:00
|
|
|
witness.ContainerID.Encode(binCnr)
|
2022-05-12 16:37:46 +00:00
|
|
|
|
2022-05-18 15:20:08 +00:00
|
|
|
var prm DeletePrm
|
|
|
|
|
|
|
|
prm.SetCID(binCnr)
|
2023-06-01 08:55:06 +00:00
|
|
|
prm.SetSignature(witness.Signature.GetSign())
|
|
|
|
prm.SetKey(witness.Signature.GetKey())
|
2022-05-18 15:20:08 +00:00
|
|
|
|
2023-06-01 08:55:06 +00:00
|
|
|
if tok := witness.SessionToken; tok != nil {
|
2022-05-18 15:20:08 +00:00
|
|
|
prm.SetToken(tok.Marshal())
|
|
|
|
}
|
|
|
|
|
2024-10-21 13:27:28 +00:00
|
|
|
_, err := c.Delete(ctx, prm)
|
2023-11-08 09:05:03 +00:00
|
|
|
return err
|
2022-01-31 13:34:01 +00:00
|
|
|
}
|
2021-05-26 09:59:16 +00:00
|
|
|
|
2022-01-31 13:34:01 +00:00
|
|
|
// DeletePrm groups parameters of Delete client operation.
|
|
|
|
type DeletePrm struct {
|
2022-05-31 17:00:41 +00:00
|
|
|
cnr []byte
|
2022-01-31 13:34:01 +00:00
|
|
|
signature []byte
|
|
|
|
token []byte
|
2023-06-01 08:55:06 +00:00
|
|
|
key []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
|
|
|
// SetCID sets container ID.
|
|
|
|
func (d *DeletePrm) SetCID(cid []byte) {
|
2022-05-31 17:00:41 +00:00
|
|
|
d.cnr = cid
|
2020-07-24 13:54:03 +00:00
|
|
|
}
|
|
|
|
|
2022-01-31 13:34:01 +00:00
|
|
|
// SetSignature sets signature.
|
|
|
|
func (d *DeletePrm) SetSignature(signature []byte) {
|
|
|
|
d.signature = signature
|
2020-07-24 13:54:03 +00:00
|
|
|
}
|
|
|
|
|
2022-01-31 13:34:01 +00:00
|
|
|
// SetToken sets session token.
|
|
|
|
func (d *DeletePrm) SetToken(token []byte) {
|
|
|
|
d.token = token
|
2021-05-26 11:01:38 +00:00
|
|
|
}
|
|
|
|
|
2023-06-01 08:55:06 +00:00
|
|
|
// SetKey sets public key.
|
|
|
|
func (d *DeletePrm) SetKey(key []byte) {
|
|
|
|
d.key = key
|
|
|
|
}
|
|
|
|
|
2023-02-05 15:59:38 +00:00
|
|
|
// Delete removes the container from FrostFS system
|
2022-01-31 13:34:01 +00:00
|
|
|
// through Container contract call.
|
|
|
|
//
|
2023-11-08 09:05:03 +00:00
|
|
|
// Returns valid until block and any error encountered that caused
|
2022-01-31 13:34:01 +00:00
|
|
|
// the removal to interrupt.
|
2024-10-21 13:27:28 +00:00
|
|
|
func (c *Client) Delete(ctx context.Context, p DeletePrm) (uint32, error) {
|
2023-10-19 15:01:19 +00:00
|
|
|
if len(p.signature) == 0 && !p.IsControl() {
|
2023-11-08 09:05:03 +00:00
|
|
|
return 0, errNilArgument
|
2022-01-31 13:34:01 +00:00
|
|
|
}
|
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(deleteMethod)
|
2023-06-01 08:55:06 +00:00
|
|
|
prm.SetArgs(p.cnr, p.signature, p.key, p.token)
|
2022-01-31 13:34:01 +00:00
|
|
|
prm.InvokePrmOptional = p.InvokePrmOptional
|
2021-11-09 20:52:29 +00:00
|
|
|
|
2024-10-21 13:27:28 +00:00
|
|
|
res, err := c.client.Invoke(ctx, prm)
|
2021-05-18 08:12:51 +00:00
|
|
|
if err != nil {
|
2023-11-08 09:05:03 +00:00
|
|
|
return 0, fmt.Errorf("could not invoke method (%s): %w", deleteMethod, err)
|
2021-05-18 08:12:51 +00:00
|
|
|
}
|
2023-11-08 09:05:03 +00:00
|
|
|
return res.VUB, nil
|
2020-07-24 13:54:03 +00:00
|
|
|
}
|