git.frostfs.info/TrueCloudLab/frostfs-sdk-go@v0.0.0-20241022124111-5361f0ecebd3/client/container_delete.go (about) 1 package client 2 3 import ( 4 "context" 5 "fmt" 6 7 v2container "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/container" 8 "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs" 9 rpcapi "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc" 10 "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/client" 11 v2session "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session" 12 "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/signature" 13 cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id" 14 frostfscrypto "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/crypto" 15 frostfsecdsa "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/crypto/ecdsa" 16 "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/session" 17 ) 18 19 // PrmContainerDelete groups parameters of ContainerDelete operation. 20 type PrmContainerDelete struct { 21 // FrostFS request X-Headers 22 XHeaders []string 23 24 ContainerID *cid.ID 25 26 Session *session.Container 27 } 28 29 // SetContainer sets identifier of the FrostFS container to be removed. 30 // Required parameter. 31 // 32 // Deprecated: Use PrmContainerDelete.Container instead. 33 func (prm *PrmContainerDelete) SetContainer(id cid.ID) { 34 prm.ContainerID = &id 35 } 36 37 func (prm *PrmContainerDelete) buildRequest(c *Client) (*v2container.DeleteRequest, error) { 38 if prm.ContainerID == nil { 39 return nil, errorMissingContainer 40 } 41 42 if len(prm.XHeaders)%2 != 0 { 43 return nil, errorInvalidXHeaders 44 } 45 46 var cidV2 refs.ContainerID 47 prm.ContainerID.WriteToV2(&cidV2) 48 49 // Container contract expects signature of container ID value, 50 // don't get confused with stable marshaled protobuf container.ID structure. 51 data := cidV2.GetValue() 52 53 var sig frostfscrypto.Signature 54 55 err := sig.Calculate(frostfsecdsa.SignerRFC6979(c.prm.Key), data) 56 if err != nil { 57 return nil, fmt.Errorf("calculate signature: %w", err) 58 } 59 60 var sigv2 refs.Signature 61 sig.WriteToV2(&sigv2) 62 63 reqBody := new(v2container.DeleteRequestBody) 64 reqBody.SetContainerID(&cidV2) 65 reqBody.SetSignature(&sigv2) 66 67 var meta v2session.RequestMetaHeader 68 writeXHeadersToMeta(prm.XHeaders, &meta) 69 70 if prm.Session != nil { 71 var tokv2 v2session.Token 72 prm.Session.WriteToV2(&tokv2) 73 74 meta.SetSessionToken(&tokv2) 75 } 76 77 var req v2container.DeleteRequest 78 req.SetBody(reqBody) 79 c.prepareRequest(&req, &meta) 80 return &req, nil 81 } 82 83 // WithinSession specifies session within which container should be removed. 84 // 85 // Creator of the session acquires the authorship of the request. 86 // This may affect the execution of an operation (e.g. access control). 87 // 88 // Must be signed. 89 // 90 // Deprecated: Use PrmContainerDelete.Session instead. 91 func (prm *PrmContainerDelete) WithinSession(tok session.Container) { 92 prm.Session = &tok 93 } 94 95 // ResContainerDelete groups resulting values of ContainerDelete operation. 96 type ResContainerDelete struct { 97 statusRes 98 } 99 100 // ContainerDelete sends request to remove the FrostFS container. 101 // 102 // Exactly one return value is non-nil. By default, server status is returned in res structure. 103 // Any client's internal or transport errors are returned as `error`. 104 // If PrmInit.DisableFrostFSFailuresResolution has been called, unsuccessful 105 // FrostFS status codes are included in the returned result structure, 106 // otherwise, are also returned as `error`. 107 // 108 // Operation is asynchronous and no guaranteed even in the absence of errors. 109 // The required time is also not predictable. 110 // 111 // Success can be verified by reading by identifier (see GetContainer). 112 // 113 // Returns an error if parameters are set incorrectly (see PrmContainerDelete docs). 114 // Context is required and must not be nil. It is used for network communication. 115 // 116 // Exactly one return value is non-nil. Server status return is returned in ResContainerDelete. 117 // Reflects all internal errors in second return value (transport problems, response processing, etc.). 118 // 119 // Return statuses: 120 // - global (see Client docs). 121 func (c *Client) ContainerDelete(ctx context.Context, prm PrmContainerDelete) (*ResContainerDelete, error) { 122 req, err := prm.buildRequest(c) 123 if err != nil { 124 return nil, err 125 } 126 127 if err := signature.SignServiceMessage(&c.prm.Key, req); err != nil { 128 return nil, fmt.Errorf("sign request: %w", err) 129 } 130 131 resp, err := rpcapi.DeleteContainer(&c.c, req, client.WithContext(ctx)) 132 if err != nil { 133 return nil, err 134 } 135 136 var res ResContainerDelete 137 res.st, err = c.processResponse(resp) 138 return &res, err 139 }