forked from TrueCloudLab/frostfs-sdk-go
[#206] Add session tokens for container read operations
Signed-off-by: Denis Kirillov <d.kirillov@yadro.com>
This commit is contained in:
parent
a86170f53a
commit
a5fab572ff
5 changed files with 83 additions and 36 deletions
|
@ -13,6 +13,7 @@ import (
|
|||
apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status"
|
||||
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/eacl"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/session"
|
||||
)
|
||||
|
||||
// PrmContainerEACL groups parameters of ContainerEACL operation.
|
||||
|
@ -21,6 +22,8 @@ type PrmContainerEACL struct {
|
|||
XHeaders []string
|
||||
|
||||
ContainerID *cid.ID
|
||||
|
||||
Session *session.Container
|
||||
}
|
||||
|
||||
// SetContainer sets identifier of the FrostFS container to read the eACL table.
|
||||
|
@ -46,9 +49,19 @@ func (x *PrmContainerEACL) buildRequest(c *Client) (*v2container.GetExtendedACLR
|
|||
reqBody := new(v2container.GetExtendedACLRequestBody)
|
||||
reqBody.SetContainerID(&cidV2)
|
||||
|
||||
var meta v2session.RequestMetaHeader
|
||||
writeXHeadersToMeta(x.XHeaders, &meta)
|
||||
|
||||
if x.Session != nil {
|
||||
var tokv2 v2session.Token
|
||||
x.Session.WriteToV2(&tokv2)
|
||||
|
||||
meta.SetSessionToken(&tokv2)
|
||||
}
|
||||
|
||||
var req v2container.GetExtendedACLRequest
|
||||
req.SetBody(reqBody)
|
||||
c.prepareRequest(&req, new(v2session.RequestMetaHeader))
|
||||
c.prepareRequest(&req, &meta)
|
||||
return &req, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ import (
|
|||
apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container"
|
||||
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/session"
|
||||
)
|
||||
|
||||
// PrmContainerGet groups parameters of ContainerGet operation.
|
||||
|
@ -22,6 +23,8 @@ type PrmContainerGet struct {
|
|||
XHeaders []string
|
||||
|
||||
ContainerID *cid.ID
|
||||
|
||||
Session *session.Container
|
||||
}
|
||||
|
||||
// SetContainer sets identifier of the container to be read.
|
||||
|
@ -47,9 +50,19 @@ func (prm *PrmContainerGet) buildRequest(c *Client) (*v2container.GetRequest, er
|
|||
reqBody := new(v2container.GetRequestBody)
|
||||
reqBody.SetContainerID(&cidV2)
|
||||
|
||||
var meta v2session.RequestMetaHeader
|
||||
writeXHeadersToMeta(prm.XHeaders, &meta)
|
||||
|
||||
if prm.Session != nil {
|
||||
var tokv2 v2session.Token
|
||||
prm.Session.WriteToV2(&tokv2)
|
||||
|
||||
meta.SetSessionToken(&tokv2)
|
||||
}
|
||||
|
||||
var req v2container.GetRequest
|
||||
req.SetBody(reqBody)
|
||||
c.prepareRequest(&req, new(v2session.RequestMetaHeader))
|
||||
c.prepareRequest(&req, &meta)
|
||||
return &req, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ import (
|
|||
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/signature"
|
||||
apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status"
|
||||
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/session"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/user"
|
||||
)
|
||||
|
||||
|
@ -20,6 +21,8 @@ type PrmContainerList struct {
|
|||
XHeaders []string
|
||||
|
||||
Account user.ID
|
||||
|
||||
Session *session.Container
|
||||
}
|
||||
|
||||
// SetAccount sets identifier of the FrostFS account to list the containers.
|
||||
|
@ -41,9 +44,19 @@ func (x *PrmContainerList) buildRequest(c *Client) (*v2container.ListRequest, er
|
|||
reqBody := new(v2container.ListRequestBody)
|
||||
reqBody.SetOwnerID(&ownerV2)
|
||||
|
||||
var meta v2session.RequestMetaHeader
|
||||
writeXHeadersToMeta(x.XHeaders, &meta)
|
||||
|
||||
if x.Session != nil {
|
||||
var tokv2 v2session.Token
|
||||
x.Session.WriteToV2(&tokv2)
|
||||
|
||||
meta.SetSessionToken(&tokv2)
|
||||
}
|
||||
|
||||
var req v2container.ListRequest
|
||||
req.SetBody(reqBody)
|
||||
c.prepareRequest(&req, new(v2session.RequestMetaHeader))
|
||||
c.prepareRequest(&req, &meta)
|
||||
return &req, nil
|
||||
}
|
||||
|
||||
|
|
61
pool/pool.go
61
pool/pool.go
|
@ -467,7 +467,12 @@ func (c *clientWrapper) containerPut(ctx context.Context, prm PrmContainerPut) (
|
|||
|
||||
idCnr := res.ID()
|
||||
|
||||
err = waitForContainerPresence(ctx, c, idCnr, prm.WaitParams)
|
||||
getPrm := PrmContainerGet{
|
||||
ContainerID: idCnr,
|
||||
Session: prm.ClientParams.Session,
|
||||
}
|
||||
|
||||
err = waitForContainerPresence(ctx, c, getPrm, prm.WaitParams)
|
||||
if err = c.handleError(ctx, nil, err); err != nil {
|
||||
return cid.ID{}, fmt.Errorf("wait container presence on client: %w", err)
|
||||
}
|
||||
|
@ -484,6 +489,7 @@ func (c *clientWrapper) containerGet(ctx context.Context, prm PrmContainerGet) (
|
|||
|
||||
cliPrm := sdkClient.PrmContainerGet{
|
||||
ContainerID: &prm.ContainerID,
|
||||
Session: prm.Session,
|
||||
}
|
||||
|
||||
start := time.Now()
|
||||
|
@ -508,7 +514,8 @@ func (c *clientWrapper) containerList(ctx context.Context, prm PrmContainerList)
|
|||
}
|
||||
|
||||
cliPrm := sdkClient.PrmContainerList{
|
||||
Account: prm.ownerID,
|
||||
Account: prm.OwnerID,
|
||||
Session: prm.Session,
|
||||
}
|
||||
|
||||
start := time.Now()
|
||||
|
@ -555,7 +562,12 @@ func (c *clientWrapper) containerDelete(ctx context.Context, prm PrmContainerDel
|
|||
return fmt.Errorf("invalid wait parameters: %w", err)
|
||||
}
|
||||
|
||||
return waitForContainerRemoved(ctx, c, &prm.ContainerID, prm.WaitParams)
|
||||
getPrm := PrmContainerGet{
|
||||
ContainerID: prm.ContainerID,
|
||||
Session: prm.Session,
|
||||
}
|
||||
|
||||
return waitForContainerRemoved(ctx, c, getPrm, prm.WaitParams)
|
||||
}
|
||||
|
||||
// containerEACL invokes sdkClient.ContainerEACL parse response status to error and return result as is.
|
||||
|
@ -567,6 +579,7 @@ func (c *clientWrapper) containerEACL(ctx context.Context, prm PrmContainerEACL)
|
|||
|
||||
cliPrm := sdkClient.PrmContainerEACL{
|
||||
ContainerID: &prm.ContainerID,
|
||||
Session: prm.Session,
|
||||
}
|
||||
|
||||
start := time.Now()
|
||||
|
@ -614,12 +627,13 @@ func (c *clientWrapper) containerSetEACL(ctx context.Context, prm PrmContainerSe
|
|||
return fmt.Errorf("invalid wait parameters: %w", err)
|
||||
}
|
||||
|
||||
var cIDp *cid.ID
|
||||
if cID, set := prm.Table.CID(); set {
|
||||
cIDp = &cID
|
||||
cnrID, _ := prm.Table.CID()
|
||||
eaclPrm := PrmContainerEACL{
|
||||
ContainerID: cnrID,
|
||||
Session: prm.Session,
|
||||
}
|
||||
|
||||
err = waitForEACLPresence(ctx, c, cIDp, &prm.Table, prm.WaitParams)
|
||||
err = waitForEACLPresence(ctx, c, eaclPrm, &prm.Table, prm.WaitParams)
|
||||
if err = c.handleError(ctx, nil, err); err != nil {
|
||||
return fmt.Errorf("wait eacl presence on client: %w", err)
|
||||
}
|
||||
|
@ -1624,6 +1638,8 @@ func (x *PrmContainerPut) SetWaitParams(waitParams WaitParams) {
|
|||
// PrmContainerGet groups parameters of GetContainer operation.
|
||||
type PrmContainerGet struct {
|
||||
ContainerID cid.ID
|
||||
|
||||
Session *session.Container
|
||||
}
|
||||
|
||||
// SetContainerID specifies identifier of the container to be read.
|
||||
|
@ -1635,12 +1651,16 @@ func (prm *PrmContainerGet) SetContainerID(cnrID cid.ID) {
|
|||
|
||||
// PrmContainerList groups parameters of ListContainers operation.
|
||||
type PrmContainerList struct {
|
||||
ownerID user.ID
|
||||
OwnerID user.ID
|
||||
|
||||
Session *session.Container
|
||||
}
|
||||
|
||||
// SetOwnerID specifies identifier of the FrostFS account to list the containers.
|
||||
//
|
||||
// Deprecated: Use PrmContainerList.OwnerID instead.
|
||||
func (x *PrmContainerList) SetOwnerID(ownerID user.ID) {
|
||||
x.ownerID = ownerID
|
||||
x.OwnerID = ownerID
|
||||
}
|
||||
|
||||
// PrmContainerDelete groups parameters of DeleteContainer operation.
|
||||
|
@ -1679,9 +1699,13 @@ func (x *PrmContainerDelete) SetWaitParams(waitParams WaitParams) {
|
|||
// PrmContainerEACL groups parameters of GetEACL operation.
|
||||
type PrmContainerEACL struct {
|
||||
ContainerID cid.ID
|
||||
|
||||
Session *session.Container
|
||||
}
|
||||
|
||||
// SetContainerID specifies identifier of the FrostFS container to read the eACL table.
|
||||
//
|
||||
// Deprecated: Use PrmContainerEACL.ContainerID instead.
|
||||
func (x *PrmContainerEACL) SetContainerID(cnrID cid.ID) {
|
||||
x.ContainerID = cnrID
|
||||
}
|
||||
|
@ -2745,10 +2769,7 @@ func (p Pool) Statistic() Statistic {
|
|||
}
|
||||
|
||||
// waitForContainerPresence waits until the container is found on the FrostFS network.
|
||||
func waitForContainerPresence(ctx context.Context, cli client, cnrID cid.ID, waitParams *WaitParams) error {
|
||||
var prm PrmContainerGet
|
||||
prm.SetContainerID(cnrID)
|
||||
|
||||
func waitForContainerPresence(ctx context.Context, cli client, prm PrmContainerGet, waitParams *WaitParams) error {
|
||||
return waitFor(ctx, waitParams, func(ctx context.Context) bool {
|
||||
_, err := cli.containerGet(ctx, prm)
|
||||
return err == nil
|
||||
|
@ -2756,12 +2777,7 @@ func waitForContainerPresence(ctx context.Context, cli client, cnrID cid.ID, wai
|
|||
}
|
||||
|
||||
// waitForEACLPresence waits until the container eacl is applied on the FrostFS network.
|
||||
func waitForEACLPresence(ctx context.Context, cli client, cnrID *cid.ID, table *eacl.Table, waitParams *WaitParams) error {
|
||||
var prm PrmContainerEACL
|
||||
if cnrID != nil {
|
||||
prm.ContainerID = *cnrID
|
||||
}
|
||||
|
||||
func waitForEACLPresence(ctx context.Context, cli client, prm PrmContainerEACL, table *eacl.Table, waitParams *WaitParams) error {
|
||||
return waitFor(ctx, waitParams, func(ctx context.Context) bool {
|
||||
eaclTable, err := cli.containerEACL(ctx, prm)
|
||||
if err == nil {
|
||||
|
@ -2772,12 +2788,7 @@ func waitForEACLPresence(ctx context.Context, cli client, cnrID *cid.ID, table *
|
|||
}
|
||||
|
||||
// waitForContainerRemoved waits until the container is removed from the FrostFS network.
|
||||
func waitForContainerRemoved(ctx context.Context, cli client, cnrID *cid.ID, waitParams *WaitParams) error {
|
||||
var prm PrmContainerGet
|
||||
if cnrID != nil {
|
||||
prm.SetContainerID(*cnrID)
|
||||
}
|
||||
|
||||
func waitForContainerRemoved(ctx context.Context, cli client, prm PrmContainerGet, waitParams *WaitParams) error {
|
||||
return waitFor(ctx, waitParams, func(ctx context.Context) bool {
|
||||
_, err := cli.containerGet(ctx, prm)
|
||||
return sdkClient.IsErrContainerNotFound(err)
|
||||
|
|
|
@ -9,7 +9,6 @@ import (
|
|||
"time"
|
||||
|
||||
apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status"
|
||||
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
||||
frostfsecdsa "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/crypto/ecdsa"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
||||
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
||||
|
@ -480,9 +479,7 @@ func TestWaitPresence(t *testing.T) {
|
|||
cancel()
|
||||
}()
|
||||
|
||||
var idCnr cid.ID
|
||||
|
||||
err := waitForContainerPresence(ctx, mockCli, idCnr, &WaitParams{
|
||||
err := waitForContainerPresence(ctx, mockCli, PrmContainerGet{}, &WaitParams{
|
||||
Timeout: 120 * time.Second,
|
||||
PollInterval: 5 * time.Second,
|
||||
})
|
||||
|
@ -492,8 +489,8 @@ func TestWaitPresence(t *testing.T) {
|
|||
|
||||
t.Run("context deadline exceeded", func(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
var idCnr cid.ID
|
||||
err := waitForContainerPresence(ctx, mockCli, idCnr, &WaitParams{
|
||||
|
||||
err := waitForContainerPresence(ctx, mockCli, PrmContainerGet{}, &WaitParams{
|
||||
Timeout: 500 * time.Millisecond,
|
||||
PollInterval: 5 * time.Second,
|
||||
})
|
||||
|
@ -503,8 +500,8 @@ func TestWaitPresence(t *testing.T) {
|
|||
|
||||
t.Run("ok", func(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
var idCnr cid.ID
|
||||
err := waitForContainerPresence(ctx, mockCli, idCnr, &WaitParams{
|
||||
|
||||
err := waitForContainerPresence(ctx, mockCli, PrmContainerGet{}, &WaitParams{
|
||||
Timeout: 10 * time.Second,
|
||||
PollInterval: 500 * time.Millisecond,
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue