[#206] Add session tokens for container read operations

Signed-off-by: Denis Kirillov <d.kirillov@yadro.com>
This commit is contained in:
Denis Kirillov 2024-03-01 15:16:16 +03:00
parent a86170f53a
commit a5fab572ff
5 changed files with 83 additions and 36 deletions

View file

@ -13,6 +13,7 @@ import (
apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status" apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status"
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id" 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/eacl"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/session"
) )
// PrmContainerEACL groups parameters of ContainerEACL operation. // PrmContainerEACL groups parameters of ContainerEACL operation.
@ -21,6 +22,8 @@ type PrmContainerEACL struct {
XHeaders []string XHeaders []string
ContainerID *cid.ID ContainerID *cid.ID
Session *session.Container
} }
// SetContainer sets identifier of the FrostFS container to read the eACL table. // 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 := new(v2container.GetExtendedACLRequestBody)
reqBody.SetContainerID(&cidV2) 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 var req v2container.GetExtendedACLRequest
req.SetBody(reqBody) req.SetBody(reqBody)
c.prepareRequest(&req, new(v2session.RequestMetaHeader)) c.prepareRequest(&req, &meta)
return &req, nil return &req, nil
} }

View file

@ -14,6 +14,7 @@ import (
apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status" apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container" "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container"
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id" cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/session"
) )
// PrmContainerGet groups parameters of ContainerGet operation. // PrmContainerGet groups parameters of ContainerGet operation.
@ -22,6 +23,8 @@ type PrmContainerGet struct {
XHeaders []string XHeaders []string
ContainerID *cid.ID ContainerID *cid.ID
Session *session.Container
} }
// SetContainer sets identifier of the container to be read. // 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 := new(v2container.GetRequestBody)
reqBody.SetContainerID(&cidV2) 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 var req v2container.GetRequest
req.SetBody(reqBody) req.SetBody(reqBody)
c.prepareRequest(&req, new(v2session.RequestMetaHeader)) c.prepareRequest(&req, &meta)
return &req, nil return &req, nil
} }

View file

@ -12,6 +12,7 @@ import (
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/signature" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/signature"
apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status" apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status"
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id" 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" "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/user"
) )
@ -20,6 +21,8 @@ type PrmContainerList struct {
XHeaders []string XHeaders []string
Account user.ID Account user.ID
Session *session.Container
} }
// SetAccount sets identifier of the FrostFS account to list the containers. // 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 := new(v2container.ListRequestBody)
reqBody.SetOwnerID(&ownerV2) 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 var req v2container.ListRequest
req.SetBody(reqBody) req.SetBody(reqBody)
c.prepareRequest(&req, new(v2session.RequestMetaHeader)) c.prepareRequest(&req, &meta)
return &req, nil return &req, nil
} }

View file

@ -467,7 +467,12 @@ func (c *clientWrapper) containerPut(ctx context.Context, prm PrmContainerPut) (
idCnr := res.ID() 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 { if err = c.handleError(ctx, nil, err); err != nil {
return cid.ID{}, fmt.Errorf("wait container presence on client: %w", err) 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{ cliPrm := sdkClient.PrmContainerGet{
ContainerID: &prm.ContainerID, ContainerID: &prm.ContainerID,
Session: prm.Session,
} }
start := time.Now() start := time.Now()
@ -508,7 +514,8 @@ func (c *clientWrapper) containerList(ctx context.Context, prm PrmContainerList)
} }
cliPrm := sdkClient.PrmContainerList{ cliPrm := sdkClient.PrmContainerList{
Account: prm.ownerID, Account: prm.OwnerID,
Session: prm.Session,
} }
start := time.Now() 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 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. // 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{ cliPrm := sdkClient.PrmContainerEACL{
ContainerID: &prm.ContainerID, ContainerID: &prm.ContainerID,
Session: prm.Session,
} }
start := time.Now() start := time.Now()
@ -614,12 +627,13 @@ func (c *clientWrapper) containerSetEACL(ctx context.Context, prm PrmContainerSe
return fmt.Errorf("invalid wait parameters: %w", err) return fmt.Errorf("invalid wait parameters: %w", err)
} }
var cIDp *cid.ID cnrID, _ := prm.Table.CID()
if cID, set := prm.Table.CID(); set { eaclPrm := PrmContainerEACL{
cIDp = &cID 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 { if err = c.handleError(ctx, nil, err); err != nil {
return fmt.Errorf("wait eacl presence on client: %w", err) 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. // PrmContainerGet groups parameters of GetContainer operation.
type PrmContainerGet struct { type PrmContainerGet struct {
ContainerID cid.ID ContainerID cid.ID
Session *session.Container
} }
// SetContainerID specifies identifier of the container to be read. // 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. // PrmContainerList groups parameters of ListContainers operation.
type PrmContainerList struct { type PrmContainerList struct {
ownerID user.ID OwnerID user.ID
Session *session.Container
} }
// SetOwnerID specifies identifier of the FrostFS account to list the containers. // SetOwnerID specifies identifier of the FrostFS account to list the containers.
//
// Deprecated: Use PrmContainerList.OwnerID instead.
func (x *PrmContainerList) SetOwnerID(ownerID user.ID) { func (x *PrmContainerList) SetOwnerID(ownerID user.ID) {
x.ownerID = ownerID x.OwnerID = ownerID
} }
// PrmContainerDelete groups parameters of DeleteContainer operation. // PrmContainerDelete groups parameters of DeleteContainer operation.
@ -1679,9 +1699,13 @@ func (x *PrmContainerDelete) SetWaitParams(waitParams WaitParams) {
// PrmContainerEACL groups parameters of GetEACL operation. // PrmContainerEACL groups parameters of GetEACL operation.
type PrmContainerEACL struct { type PrmContainerEACL struct {
ContainerID cid.ID ContainerID cid.ID
Session *session.Container
} }
// SetContainerID specifies identifier of the FrostFS container to read the eACL table. // SetContainerID specifies identifier of the FrostFS container to read the eACL table.
//
// Deprecated: Use PrmContainerEACL.ContainerID instead.
func (x *PrmContainerEACL) SetContainerID(cnrID cid.ID) { func (x *PrmContainerEACL) SetContainerID(cnrID cid.ID) {
x.ContainerID = cnrID x.ContainerID = cnrID
} }
@ -2745,10 +2769,7 @@ func (p Pool) Statistic() Statistic {
} }
// waitForContainerPresence waits until the container is found on the FrostFS network. // waitForContainerPresence waits until the container is found on the FrostFS network.
func waitForContainerPresence(ctx context.Context, cli client, cnrID cid.ID, waitParams *WaitParams) error { func waitForContainerPresence(ctx context.Context, cli client, prm PrmContainerGet, waitParams *WaitParams) error {
var prm PrmContainerGet
prm.SetContainerID(cnrID)
return waitFor(ctx, waitParams, func(ctx context.Context) bool { return waitFor(ctx, waitParams, func(ctx context.Context) bool {
_, err := cli.containerGet(ctx, prm) _, err := cli.containerGet(ctx, prm)
return err == nil 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. // 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 { func waitForEACLPresence(ctx context.Context, cli client, prm PrmContainerEACL, table *eacl.Table, waitParams *WaitParams) error {
var prm PrmContainerEACL
if cnrID != nil {
prm.ContainerID = *cnrID
}
return waitFor(ctx, waitParams, func(ctx context.Context) bool { return waitFor(ctx, waitParams, func(ctx context.Context) bool {
eaclTable, err := cli.containerEACL(ctx, prm) eaclTable, err := cli.containerEACL(ctx, prm)
if err == nil { 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. // waitForContainerRemoved waits until the container is removed from the FrostFS network.
func waitForContainerRemoved(ctx context.Context, cli client, cnrID *cid.ID, waitParams *WaitParams) error { func waitForContainerRemoved(ctx context.Context, cli client, prm PrmContainerGet, waitParams *WaitParams) error {
var prm PrmContainerGet
if cnrID != nil {
prm.SetContainerID(*cnrID)
}
return waitFor(ctx, waitParams, func(ctx context.Context) bool { return waitFor(ctx, waitParams, func(ctx context.Context) bool {
_, err := cli.containerGet(ctx, prm) _, err := cli.containerGet(ctx, prm)
return sdkClient.IsErrContainerNotFound(err) return sdkClient.IsErrContainerNotFound(err)

View file

@ -9,7 +9,6 @@ import (
"time" "time"
apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status" 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" frostfsecdsa "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/crypto/ecdsa"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object" "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id" oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
@ -480,9 +479,7 @@ func TestWaitPresence(t *testing.T) {
cancel() cancel()
}() }()
var idCnr cid.ID err := waitForContainerPresence(ctx, mockCli, PrmContainerGet{}, &WaitParams{
err := waitForContainerPresence(ctx, mockCli, idCnr, &WaitParams{
Timeout: 120 * time.Second, Timeout: 120 * time.Second,
PollInterval: 5 * time.Second, PollInterval: 5 * time.Second,
}) })
@ -492,8 +489,8 @@ func TestWaitPresence(t *testing.T) {
t.Run("context deadline exceeded", func(t *testing.T) { t.Run("context deadline exceeded", func(t *testing.T) {
ctx := context.Background() ctx := context.Background()
var idCnr cid.ID
err := waitForContainerPresence(ctx, mockCli, idCnr, &WaitParams{ err := waitForContainerPresence(ctx, mockCli, PrmContainerGet{}, &WaitParams{
Timeout: 500 * time.Millisecond, Timeout: 500 * time.Millisecond,
PollInterval: 5 * time.Second, PollInterval: 5 * time.Second,
}) })
@ -503,8 +500,8 @@ func TestWaitPresence(t *testing.T) {
t.Run("ok", func(t *testing.T) { t.Run("ok", func(t *testing.T) {
ctx := context.Background() ctx := context.Background()
var idCnr cid.ID
err := waitForContainerPresence(ctx, mockCli, idCnr, &WaitParams{ err := waitForContainerPresence(ctx, mockCli, PrmContainerGet{}, &WaitParams{
Timeout: 10 * time.Second, Timeout: 10 * time.Second,
PollInterval: 500 * time.Millisecond, PollInterval: 500 * time.Millisecond,
}) })