144 lines
3.9 KiB
Go
144 lines
3.9 KiB
Go
|
package client
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"fmt"
|
||
|
|
||
|
v2container "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/container"
|
||
|
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs"
|
||
|
rpcapi "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc"
|
||
|
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/client"
|
||
|
v2session "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session"
|
||
|
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
||
|
frostfscrypto "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/crypto"
|
||
|
frostfsecdsa "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/crypto/ecdsa"
|
||
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/session"
|
||
|
)
|
||
|
|
||
|
// PrmContainerDelete groups parameters of ContainerDelete operation.
|
||
|
type PrmContainerDelete struct {
|
||
|
prmCommonMeta
|
||
|
|
||
|
idSet bool
|
||
|
id cid.ID
|
||
|
|
||
|
tokSet bool
|
||
|
tok session.Container
|
||
|
}
|
||
|
|
||
|
// SetContainer sets identifier of the FrostFS container to be removed.
|
||
|
// Required parameter.
|
||
|
func (x *PrmContainerDelete) SetContainer(id cid.ID) {
|
||
|
x.id = id
|
||
|
x.idSet = true
|
||
|
}
|
||
|
|
||
|
// WithinSession specifies session within which container should be removed.
|
||
|
//
|
||
|
// Creator of the session acquires the authorship of the request.
|
||
|
// This may affect the execution of an operation (e.g. access control).
|
||
|
//
|
||
|
// Must be signed.
|
||
|
func (x *PrmContainerDelete) WithinSession(tok session.Container) {
|
||
|
x.tok = tok
|
||
|
x.tokSet = true
|
||
|
}
|
||
|
|
||
|
// ResContainerDelete groups resulting values of ContainerDelete operation.
|
||
|
type ResContainerDelete struct {
|
||
|
statusRes
|
||
|
}
|
||
|
|
||
|
// ContainerDelete sends request to remove the FrostFS container.
|
||
|
//
|
||
|
// Exactly one return value is non-nil. By default, server status is returned in res structure.
|
||
|
// Any client's internal or transport errors are returned as `error`.
|
||
|
// If PrmInit.ResolveFrostFSFailures has been called, unsuccessful
|
||
|
// FrostFS status codes are returned as `error`, otherwise, are included
|
||
|
// in the returned result structure.
|
||
|
//
|
||
|
// Operation is asynchronous and no guaranteed even in the absence of errors.
|
||
|
// The required time is also not predictable.
|
||
|
//
|
||
|
// Success can be verified by reading by identifier (see GetContainer).
|
||
|
//
|
||
|
// Returns an error if parameters are set incorrectly (see PrmContainerDelete docs).
|
||
|
// Context is required and must not be nil. It is used for network communication.
|
||
|
//
|
||
|
// Exactly one return value is non-nil. Server status return is returned in ResContainerDelete.
|
||
|
// Reflects all internal errors in second return value (transport problems, response processing, etc.).
|
||
|
//
|
||
|
// Return statuses:
|
||
|
// - global (see Client docs).
|
||
|
func (c *Client) ContainerDelete(ctx context.Context, prm PrmContainerDelete) (*ResContainerDelete, error) {
|
||
|
// check parameters
|
||
|
switch {
|
||
|
case ctx == nil:
|
||
|
return nil, errorMissingContext
|
||
|
case !prm.idSet:
|
||
|
return nil, errorMissingContainer
|
||
|
}
|
||
|
|
||
|
// sign container ID
|
||
|
var cidV2 refs.ContainerID
|
||
|
prm.id.WriteToV2(&cidV2)
|
||
|
|
||
|
// container contract expects signature of container ID value
|
||
|
// don't get confused with stable marshaled protobuf container.ID structure
|
||
|
data := cidV2.GetValue()
|
||
|
|
||
|
var sig frostfscrypto.Signature
|
||
|
|
||
|
err := sig.Calculate(frostfsecdsa.SignerRFC6979(c.prm.key), data)
|
||
|
if err != nil {
|
||
|
return nil, fmt.Errorf("calculate signature: %w", err)
|
||
|
}
|
||
|
|
||
|
var sigv2 refs.Signature
|
||
|
|
||
|
sig.WriteToV2(&sigv2)
|
||
|
|
||
|
// form request body
|
||
|
reqBody := new(v2container.DeleteRequestBody)
|
||
|
reqBody.SetContainerID(&cidV2)
|
||
|
reqBody.SetSignature(&sigv2)
|
||
|
|
||
|
// form meta header
|
||
|
var meta v2session.RequestMetaHeader
|
||
|
writeXHeadersToMeta(prm.prmCommonMeta.xHeaders, &meta)
|
||
|
|
||
|
if prm.tokSet {
|
||
|
var tokv2 v2session.Token
|
||
|
prm.tok.WriteToV2(&tokv2)
|
||
|
|
||
|
meta.SetSessionToken(&tokv2)
|
||
|
}
|
||
|
|
||
|
// form request
|
||
|
var req v2container.DeleteRequest
|
||
|
|
||
|
req.SetBody(reqBody)
|
||
|
req.SetMetaHeader(&meta)
|
||
|
|
||
|
// init call context
|
||
|
|
||
|
var (
|
||
|
cc contextCall
|
||
|
res ResContainerDelete
|
||
|
)
|
||
|
|
||
|
c.initCallContext(&cc)
|
||
|
cc.req = &req
|
||
|
cc.statusRes = &res
|
||
|
cc.call = func() (responseV2, error) {
|
||
|
return rpcapi.DeleteContainer(&c.c, &req, client.WithContext(ctx))
|
||
|
}
|
||
|
|
||
|
// process call
|
||
|
if !cc.processCall() {
|
||
|
return nil, cc.err
|
||
|
}
|
||
|
|
||
|
return &res, nil
|
||
|
}
|