[#165] pool: drop prmCommon from container params

Signed-off-by: Denis Kirillov <denis@nspcc.ru>
This commit is contained in:
Denis Kirillov 2022-03-17 12:53:04 +03:00 committed by Alex Vanin
parent 59b49dd7e6
commit 030bbce2cf
2 changed files with 24 additions and 62 deletions

View file

@ -218,7 +218,7 @@ func (x *prmCommon) UseBearer(token *token.BearerToken) {
x.btoken = token x.btoken = token
} }
// UseSession specifies session within which object should be read. // UseSession specifies session within which operation should be performed.
func (x *prmCommon) UseSession(token *session.Token) { func (x *prmCommon) UseSession(token *session.Token) {
x.stoken = token x.stoken = token
} }
@ -321,8 +321,6 @@ func (x *PrmObjectSearch) SetFilters(filters object.SearchFilters) {
// PrmContainerPut groups parameters of PutContainer operation. // PrmContainerPut groups parameters of PutContainer operation.
type PrmContainerPut struct { type PrmContainerPut struct {
prmCommon
cnr container.Container cnr container.Container
} }
@ -333,8 +331,6 @@ func (x *PrmContainerPut) SetContainer(cnr container.Container) {
// PrmContainerGet groups parameters of GetContainer operation. // PrmContainerGet groups parameters of GetContainer operation.
type PrmContainerGet struct { type PrmContainerGet struct {
prmCommon
cnrID cid.ID cnrID cid.ID
} }
@ -345,8 +341,6 @@ func (x *PrmContainerGet) SetContainerID(cnrID cid.ID) {
// PrmContainerList groups parameters of ListContainers operation. // PrmContainerList groups parameters of ListContainers operation.
type PrmContainerList struct { type PrmContainerList struct {
prmCommon
ownerID owner.ID ownerID owner.ID
} }
@ -357,9 +351,8 @@ func (x *PrmContainerList) SetOwnerID(ownerID owner.ID) {
// PrmContainerDelete groups parameters of DeleteContainer operation. // PrmContainerDelete groups parameters of DeleteContainer operation.
type PrmContainerDelete struct { type PrmContainerDelete struct {
prmCommon stoken session.Token
cnrID cid.ID
cnrID cid.ID
} }
// SetContainerID specifies identifier of the NeoFS container to be removed. // SetContainerID specifies identifier of the NeoFS container to be removed.
@ -367,10 +360,13 @@ func (x *PrmContainerDelete) SetContainerID(cnrID cid.ID) {
x.cnrID = cnrID x.cnrID = cnrID
} }
// SetSessionToken specifies session within which operation should be performed.
func (x *PrmContainerDelete) SetSessionToken(token session.Token) {
x.stoken = token
}
// PrmContainerEACL groups parameters of GetEACL operation. // PrmContainerEACL groups parameters of GetEACL operation.
type PrmContainerEACL struct { type PrmContainerEACL struct {
prmCommon
cnrID cid.ID cnrID cid.ID
} }
@ -381,8 +377,6 @@ func (x *PrmContainerEACL) SetContainerID(cnrID cid.ID) {
// PrmContainerSetEACL groups parameters of SetEACL operation. // PrmContainerSetEACL groups parameters of SetEACL operation.
type PrmContainerSetEACL struct { type PrmContainerSetEACL struct {
prmCommon
table eacl.Table table eacl.Table
} }
@ -393,8 +387,6 @@ func (x *PrmContainerSetEACL) SetTable(table eacl.Table) {
// PrmBalanceGet groups parameters of Balance operation. // PrmBalanceGet groups parameters of Balance operation.
type PrmBalanceGet struct { type PrmBalanceGet struct {
prmCommon
ownerID owner.ID ownerID owner.ID
} }
@ -761,39 +753,6 @@ func formCacheKey(address string, key *ecdsa.PrivateKey) string {
return address + k.String() return address + k.String()
} }
func (p *Pool) conn(ctx context.Context, cfg prmCommon) (*clientPack, error) {
cp, err := p.connection()
if err != nil {
return nil, err
}
key := p.key
if cfg.key != nil {
key = cfg.key
}
sessionToken := cfg.stoken
if sessionToken == nil && cfg.defaultSession {
cacheKey := formCacheKey(cp.address, key)
sessionToken = p.cache.Get(cacheKey)
if sessionToken == nil {
cliRes, err := createSessionTokenForDuration(ctx, cp.client, p.stokenDuration)
if err != nil {
return nil, err
}
ownerID := owner.NewIDFromPublicKey(&key.PublicKey)
sessionToken = sessionTokenForOwner(ownerID, cliRes)
cfg.stoken = sessionToken
_ = p.cache.Put(cacheKey, sessionToken)
}
}
return cp, nil
}
func (p *Pool) checkSessionTokenErr(err error, address string) bool { func (p *Pool) checkSessionTokenErr(err error, address string) bool {
if err == nil { if err == nil {
return false return false
@ -1399,7 +1358,7 @@ func (p *Pool) SearchObjects(ctx context.Context, prm PrmObjectSearch) (*ResObje
// //
// Success can be verified by reading by identifier (see GetContainer). // Success can be verified by reading by identifier (see GetContainer).
func (p *Pool) PutContainer(ctx context.Context, prm PrmContainerPut) (*cid.ID, error) { func (p *Pool) PutContainer(ctx context.Context, prm PrmContainerPut) (*cid.ID, error) {
cp, err := p.conn(ctx, prm.prmCommon) cp, err := p.connection()
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -1417,7 +1376,7 @@ func (p *Pool) PutContainer(ctx context.Context, prm PrmContainerPut) (*cid.ID,
// GetContainer reads NeoFS container by ID. // GetContainer reads NeoFS container by ID.
func (p *Pool) GetContainer(ctx context.Context, prm PrmContainerGet) (*container.Container, error) { func (p *Pool) GetContainer(ctx context.Context, prm PrmContainerGet) (*container.Container, error) {
cp, err := p.conn(ctx, prm.prmCommon) cp, err := p.connection()
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -1435,7 +1394,7 @@ func (p *Pool) GetContainer(ctx context.Context, prm PrmContainerGet) (*containe
// ListContainers requests identifiers of the account-owned containers. // ListContainers requests identifiers of the account-owned containers.
func (p *Pool) ListContainers(ctx context.Context, prm PrmContainerList) ([]cid.ID, error) { func (p *Pool) ListContainers(ctx context.Context, prm PrmContainerList) ([]cid.ID, error) {
cp, err := p.conn(ctx, prm.prmCommon) cp, err := p.connection()
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -1458,17 +1417,14 @@ func (p *Pool) ListContainers(ctx context.Context, prm PrmContainerList) ([]cid.
// //
// Success can be verified by reading by identifier (see GetContainer). // Success can be verified by reading by identifier (see GetContainer).
func (p *Pool) DeleteContainer(ctx context.Context, prm PrmContainerDelete) error { func (p *Pool) DeleteContainer(ctx context.Context, prm PrmContainerDelete) error {
cp, err := p.conn(ctx, prm.prmCommon) cp, err := p.connection()
if err != nil { if err != nil {
return err return err
} }
var cliPrm sdkClient.PrmContainerDelete var cliPrm sdkClient.PrmContainerDelete
cliPrm.SetContainer(prm.cnrID) cliPrm.SetContainer(prm.cnrID)
cliPrm.SetSessionToken(prm.stoken)
if prm.stoken != nil {
cliPrm.SetSessionToken(*prm.stoken)
}
_, err = cp.client.ContainerDelete(ctx, cliPrm) _, err = cp.client.ContainerDelete(ctx, cliPrm)
@ -1479,7 +1435,7 @@ func (p *Pool) DeleteContainer(ctx context.Context, prm PrmContainerDelete) erro
// GetEACL reads eACL table of the NeoFS container. // GetEACL reads eACL table of the NeoFS container.
func (p *Pool) GetEACL(ctx context.Context, prm PrmContainerEACL) (*eacl.Table, error) { func (p *Pool) GetEACL(ctx context.Context, prm PrmContainerEACL) (*eacl.Table, error) {
cp, err := p.conn(ctx, prm.prmCommon) cp, err := p.connection()
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -1502,7 +1458,7 @@ func (p *Pool) GetEACL(ctx context.Context, prm PrmContainerEACL) (*eacl.Table,
// //
// Success can be verified by reading by identifier (see GetEACL). // Success can be verified by reading by identifier (see GetEACL).
func (p *Pool) SetEACL(ctx context.Context, prm PrmContainerSetEACL) error { func (p *Pool) SetEACL(ctx context.Context, prm PrmContainerSetEACL) error {
cp, err := p.conn(ctx, prm.prmCommon) cp, err := p.connection()
if err != nil { if err != nil {
return err return err
} }
@ -1519,7 +1475,7 @@ func (p *Pool) SetEACL(ctx context.Context, prm PrmContainerSetEACL) error {
// Balance requests current balance of the NeoFS account. // Balance requests current balance of the NeoFS account.
func (p *Pool) Balance(ctx context.Context, prm PrmBalanceGet) (*accounting.Decimal, error) { func (p *Pool) Balance(ctx context.Context, prm PrmBalanceGet) (*accounting.Decimal, error) {
cp, err := p.conn(ctx, prm.prmCommon) cp, err := p.connection()
if err != nil { if err != nil {
return nil, err return nil, err
} }

View file

@ -569,10 +569,16 @@ func TestSessionTokenOwner(t *testing.T) {
var prm prmCommon var prm prmCommon
prm.UseKey(anonKey) prm.UseKey(anonKey)
prm.useDefaultSession() prm.useDefaultSession()
cp, err := p.conn(ctx, prm) var cc callContext
cc.Context = ctx
cc.sessionTarget = func(session.Token) {}
err = p.initCallContext(&cc, prm)
require.NoError(t, err) require.NoError(t, err)
tkn := p.cache.Get(formCacheKey(cp.address, anonKey)) err = p.openDefaultSession(&cc)
require.NoError(t, err)
tkn := p.cache.Get(formCacheKey("peer0", anonKey))
require.True(t, anonOwner.Equal(tkn.OwnerID())) require.True(t, anonOwner.Equal(tkn.OwnerID()))
} }