forked from TrueCloudLab/frostfs-sdk-go
[#146] client: Customize private key in object HEAD/DELETE
We should provide the ability to customize private of object HEAD / DELETE ops. Implement `UseKey` method on `PrmObjectHead` / `PrmObjectDelete` types. Sign requests with the specified key if called. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
b0f7f75929
commit
e1c73fd43d
3 changed files with 40 additions and 2 deletions
|
@ -2,6 +2,7 @@ package client
|
|||
|
||||
import (
|
||||
"context"
|
||||
"crypto/ecdsa"
|
||||
|
||||
v2object "github.com/nspcc-dev/neofs-api-go/v2/object"
|
||||
v2refs "github.com/nspcc-dev/neofs-api-go/v2/refs"
|
||||
|
@ -21,6 +22,9 @@ type PrmObjectDelete struct {
|
|||
body v2object.DeleteRequestBody
|
||||
|
||||
addr v2refs.Address
|
||||
|
||||
keySet bool
|
||||
key ecdsa.PrivateKey
|
||||
}
|
||||
|
||||
// WithinSession specifies session within which object should be read.
|
||||
|
@ -54,6 +58,13 @@ func (x *PrmObjectDelete) ByID(id oid.ID) {
|
|||
x.addr.SetObjectID(id.ToV2())
|
||||
}
|
||||
|
||||
// UseKey specifies private key to sign the requests.
|
||||
// If key is not provided, then Client default key is used.
|
||||
func (x *PrmObjectDelete) UseKey(key ecdsa.PrivateKey) {
|
||||
x.keySet = true
|
||||
x.key = key
|
||||
}
|
||||
|
||||
// ResObjectDelete groups resulting values of ObjectDelete operation.
|
||||
type ResObjectDelete struct {
|
||||
statusRes
|
||||
|
@ -115,7 +126,13 @@ func (c *Client) ObjectDelete(ctx context.Context, prm PrmObjectDelete) (*ResObj
|
|||
res ResObjectDelete
|
||||
)
|
||||
|
||||
c.initCallContext(&cc)
|
||||
if prm.keySet {
|
||||
c.initCallContextWithoutKey(&cc)
|
||||
cc.key = prm.key
|
||||
} else {
|
||||
c.initCallContext(&cc)
|
||||
}
|
||||
|
||||
cc.req = &req
|
||||
cc.statusRes = &res
|
||||
cc.call = func() (responseV2, error) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue