-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pool: Add option to disable auto session on object operations
close #449 Signed-off-by: Evgenii Baidakov <[email protected]>
- Loading branch information
Showing
7 changed files
with
73 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package client | ||
|
||
import ( | ||
v2session "github.com/nspcc-dev/neofs-api-go/v2/session" | ||
"github.com/nspcc-dev/neofs-sdk-go/session" | ||
) | ||
|
||
// sessionContainer is a special type which unifies session logic management for client parameters. | ||
// All methods make public, because sessionContainer is included in Prm* structs. | ||
type sessionContainer struct { | ||
isSessionIgnored bool | ||
meta v2session.RequestMetaHeader | ||
} | ||
|
||
// GetSession returns session object. | ||
// | ||
// Returns: | ||
// - [ErrNoSession] err if session wasn't set. | ||
// - [ErrNoSessionExplicitly] if IgnoreSession was used. | ||
func (x *sessionContainer) GetSession() (*session.Object, error) { | ||
if x.isSessionIgnored { | ||
return nil, ErrNoSessionExplicitly | ||
} | ||
|
||
token := x.meta.GetSessionToken() | ||
if token == nil { | ||
return nil, ErrNoSession | ||
} | ||
|
||
var sess session.Object | ||
if err := sess.ReadFromV2(*token); err != nil { | ||
return nil, err | ||
} | ||
|
||
return &sess, nil | ||
} | ||
|
||
// WithinSession specifies session within which the query must be executed. | ||
// | ||
// Creator of the session acquires the authorship of the request. | ||
// This may affect the execution of an operation (e.g. access control). | ||
// | ||
// See also IgnoreSession. | ||
// | ||
// Must be signed. | ||
func (x *sessionContainer) WithinSession(t session.Object) { | ||
var tokv2 v2session.Token | ||
t.WriteToV2(&tokv2) | ||
x.meta.SetSessionToken(&tokv2) | ||
x.isSessionIgnored = false | ||
} | ||
|
||
// IgnoreSession disables auto-session creation. | ||
// | ||
// See also WithinSession. | ||
func (x *sessionContainer) IgnoreSession() { | ||
x.isSessionIgnored = true | ||
x.meta.SetSessionToken(nil) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters