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
|
@ -262,6 +262,11 @@ func (x *contextCall) processCall() bool {
|
||||||
// initializes static cross-call parameters inherited from client.
|
// initializes static cross-call parameters inherited from client.
|
||||||
func (c *Client) initCallContext(ctx *contextCall) {
|
func (c *Client) initCallContext(ctx *contextCall) {
|
||||||
ctx.key = *c.opts.key
|
ctx.key = *c.opts.key
|
||||||
|
c.initCallContextWithoutKey(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// initializes static cross-call parameters inherited from client except private key.
|
||||||
|
func (c *Client) initCallContextWithoutKey(ctx *contextCall) {
|
||||||
ctx.resolveAPIFailures = c.opts.parseNeoFSErrors
|
ctx.resolveAPIFailures = c.opts.parseNeoFSErrors
|
||||||
ctx.callbackResp = c.opts.cbRespInfo
|
ctx.callbackResp = c.opts.cbRespInfo
|
||||||
ctx.netMagic = c.opts.netMagic
|
ctx.netMagic = c.opts.netMagic
|
||||||
|
|
|
@ -2,6 +2,7 @@ package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"crypto/ecdsa"
|
||||||
|
|
||||||
v2object "github.com/nspcc-dev/neofs-api-go/v2/object"
|
v2object "github.com/nspcc-dev/neofs-api-go/v2/object"
|
||||||
v2refs "github.com/nspcc-dev/neofs-api-go/v2/refs"
|
v2refs "github.com/nspcc-dev/neofs-api-go/v2/refs"
|
||||||
|
@ -21,6 +22,9 @@ type PrmObjectDelete struct {
|
||||||
body v2object.DeleteRequestBody
|
body v2object.DeleteRequestBody
|
||||||
|
|
||||||
addr v2refs.Address
|
addr v2refs.Address
|
||||||
|
|
||||||
|
keySet bool
|
||||||
|
key ecdsa.PrivateKey
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithinSession specifies session within which object should be read.
|
// 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())
|
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.
|
// ResObjectDelete groups resulting values of ObjectDelete operation.
|
||||||
type ResObjectDelete struct {
|
type ResObjectDelete struct {
|
||||||
statusRes
|
statusRes
|
||||||
|
@ -115,7 +126,13 @@ func (c *Client) ObjectDelete(ctx context.Context, prm PrmObjectDelete) (*ResObj
|
||||||
res ResObjectDelete
|
res ResObjectDelete
|
||||||
)
|
)
|
||||||
|
|
||||||
c.initCallContext(&cc)
|
if prm.keySet {
|
||||||
|
c.initCallContextWithoutKey(&cc)
|
||||||
|
cc.key = prm.key
|
||||||
|
} else {
|
||||||
|
c.initCallContext(&cc)
|
||||||
|
}
|
||||||
|
|
||||||
cc.req = &req
|
cc.req = &req
|
||||||
cc.statusRes = &res
|
cc.statusRes = &res
|
||||||
cc.call = func() (responseV2, error) {
|
cc.call = func() (responseV2, error) {
|
||||||
|
|
|
@ -383,6 +383,16 @@ func GetFullObject(ctx context.Context, c *Client, idCnr cid.ID, idObj oid.ID) (
|
||||||
// PrmObjectHead groups parameters of ObjectHead operation.
|
// PrmObjectHead groups parameters of ObjectHead operation.
|
||||||
type PrmObjectHead struct {
|
type PrmObjectHead struct {
|
||||||
prmObjectRead
|
prmObjectRead
|
||||||
|
|
||||||
|
keySet bool
|
||||||
|
key ecdsa.PrivateKey
|
||||||
|
}
|
||||||
|
|
||||||
|
// UseKey specifies private key to sign the requests.
|
||||||
|
// If key is not provided, then Client default key is used.
|
||||||
|
func (x *PrmObjectHead) UseKey(key ecdsa.PrivateKey) {
|
||||||
|
x.keySet = true
|
||||||
|
x.key = key
|
||||||
}
|
}
|
||||||
|
|
||||||
// ResObjectHead groups resulting values of ObjectHead operation.
|
// ResObjectHead groups resulting values of ObjectHead operation.
|
||||||
|
@ -482,7 +492,13 @@ func (c *Client) ObjectHead(ctx context.Context, prm PrmObjectHead) (*ResObjectH
|
||||||
|
|
||||||
res.idObj = prm.obj
|
res.idObj = prm.obj
|
||||||
|
|
||||||
c.initCallContext(&cc)
|
if prm.keySet {
|
||||||
|
c.initCallContextWithoutKey(&cc)
|
||||||
|
cc.key = prm.key
|
||||||
|
} else {
|
||||||
|
c.initCallContext(&cc)
|
||||||
|
}
|
||||||
|
|
||||||
cc.req = &req
|
cc.req = &req
|
||||||
cc.statusRes = &res
|
cc.statusRes = &res
|
||||||
cc.call = func() (responseV2, error) {
|
cc.call = func() (responseV2, error) {
|
||||||
|
|
Loading…
Reference in a new issue