Documentation
¶
Index ¶
- Constants
- func AddSession(httpClient *retryablehttp.Client, snServer, inKey string, k keyring.Keyring, ...) (res string, err error)
- func GetCredentials(inServer string) (email, password, apiServer, errMsg string)
- func GetSessionFromKeyring(k keyring.Keyring) (s string, err error)
- func RemoveSession(k keyring.Keyring) string
- func SessionExists(k keyring.Keyring) error
- func SessionStatus(sKey string, k keyring.Keyring) (msg string, err error)
- func UpdateSession(sess *Session, k keyring.Keyring, debug bool) error
- type MinimalSession
- type Session
- func GetSession(httpClient *retryablehttp.Client, loadSession bool, sessionKey, server string, ...) (session Session, email string, err error)
- func GetSessionFromUser(httpClient *retryablehttp.Client, server string, debug bool) (Session, string, error)
- func ParseSessionString(ss string) (Session, error)
- type SessionItemsKey
Constants ¶
const ( SNServerURL = "https://api.standardnotes.com" KeyringApplicationName = "Session" KeyringService = "StandardNotesCLI" MsgSessionRemovalSuccess = "session removed successfully" MsgSessionRemovalFailure = "failed to remove session" DefaultSessionExpiryTime = 12 * time.Hour RefreshSessionThreshold = 10 * time.Minute )
Variables ¶
This section is empty.
Functions ¶
func AddSession ¶
func GetCredentials ¶
func RemoveSession ¶
RemoveSession removes the SN Session from the keyring.
func SessionExists ¶
Types ¶
type MinimalSession ¶
type MinimalSession struct {
Server string
Token string
MasterKey string
KeyParams auth.KeyParams `json:"keyParams"`
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token"`
AccessExpiration int64 `json:"access_expiration"`
RefreshExpiration int64 `json:"refresh_expiration"`
SchemaValidation bool
AccessTokenCookie string `json:"access_token_cookie,omitempty"`
RefreshTokenCookie string `json:"refresh_token_cookie,omitempty"`
}
type Session ¶
type Session struct {
Debug bool
HTTPClient *retryablehttp.Client
SchemaValidation bool
Server string
FilesServerUrl string `json:"filesServerUrl"`
Token string
MasterKey string
ItemsKeys []SessionItemsKey
// ImporterItemsKeys is the key used to encrypt exported items and set during import only
// ImporterItemsKeys []SessionItemsKey
DefaultItemsKey SessionItemsKey
KeyParams auth.KeyParams `json:"keyParams"`
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token"`
AccessExpiration int64 `json:"access_expiration"`
RefreshExpiration int64 `json:"refresh_expiration"`
ReadOnlyAccess bool `json:"readonly_access"`
PasswordNonce string
Schemas map[string]*jsonschema.Schema
// Cookie values extracted from Set-Cookie headers for manual cookie handling
AccessTokenCookie string `json:"access_token_cookie,omitempty"`
RefreshTokenCookie string `json:"refresh_token_cookie,omitempty"`
}
Session holds authentication and encryption parameters required to communicate with the API and process transferred data.
⚠️ THREAD-SAFETY WARNING ⚠️ Session is NOT safe for concurrent use by multiple goroutines.
Reasons:
- HTTPClient contains http.CookieJar which is not thread-safe
- Mutable fields (tokens, expiration times) can race
- Connection pool state can be corrupted
Safe concurrent usage patterns:
- Create separate Session instances for each goroutine
- Use mutex to serialize access to shared Session
- Never share HTTPClient with cookie jar across goroutines
See claudedocs/thread_safety.md for detailed guidance and examples.
func GetSession ¶
func GetSessionFromUser ¶
func ParseSessionString ¶
func (*Session) Refresh ¶
Refresh renews the access and refresh tokens for the current session.
⚠️ THREAD-SAFETY WARNING ⚠️ This method is NOT safe for concurrent calls on the same Session instance.
Race conditions can occur with:
- Reading RefreshToken while another goroutine is updating it
- HTTP cookie jar access (not thread-safe)
- Updating session fields (AccessToken, RefreshToken, etc.)
Safe usage:
- Serialize calls using a mutex if sharing Session
- Or use separate Session instances per goroutine
The items.Sync() function protects its Refresh() calls with syncMutex. If calling Refresh() directly, you must provide your own synchronization.
type SessionItemsKey ¶
type SessionItemsKey struct {
UUID string `json:"uuid"`
ItemsKey string `json:"itemsKey"`
Version string `json:"version"`
Default bool `json:"isDefault"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
CreatedAtTimestamp int64 `json:"created_at_timestamp"`
UpdatedAtTimestamp int64 `json:"updated_at_timestamp"`
Deleted bool `json:"deleted"`
}