[#943] service/object: Refactor private key fetching during execution

`CommonPrm` structure has private key for remote operations.
It obtained in the beginning of request processing. However,
not every operation triggers remote calls. Therefore, key
might not be used. It is important to avoid early key fetching
because `TokenStore` now returns error if session token does not
exist. This is valid case when container nodes receive request with
session token (for ACL pass) and they should process request locally.

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2021-10-26 15:07:28 +03:00 committed by Alex Vanin
parent 2fbdcbdee1
commit c30aa20b04
7 changed files with 57 additions and 58 deletions

View file

@ -20,7 +20,7 @@ type CommonPrm struct {
bearer *token.BearerToken
key *ecdsa.PrivateKey
keyStor *KeyStorage
callOpts []client.CallOption
}
@ -63,19 +63,19 @@ func (p *CommonPrm) WithBearerToken(token *token.BearerToken) *CommonPrm {
return p
}
// WithPrivateKey sets private key to use during execution.
func (p *CommonPrm) WithPrivateKey(key *ecdsa.PrivateKey) *CommonPrm {
// WithKeyStorage sets private key storage to use during execution.
func (p *CommonPrm) WithKeyStorage(stor *KeyStorage) *CommonPrm {
if p != nil {
p.key = key
p.keyStor = stor
}
return p
}
// PrivateKey returns private key to use during execution.
func (p *CommonPrm) PrivateKey() *ecdsa.PrivateKey {
// KeyStorage returns private key storage to use during execution.
func (p *CommonPrm) KeyStorage() *KeyStorage {
if p != nil {
return p.key
return p.keyStor
}
return nil