session

package
v0.0.0-...-c6d803e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 2, 2026 License: MIT Imports: 20 Imported by: 1

Documentation

Index

Constants

View Source
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 AddSession(httpClient *retryablehttp.Client, snServer, inKey string, k keyring.Keyring, debug bool) (res string, err error)

func GetCredentials

func GetCredentials(inServer string) (email, password, apiServer, errMsg string)

func GetSessionFromKeyring

func GetSessionFromKeyring(k keyring.Keyring) (s string, err error)

func RemoveSession

func RemoveSession(k keyring.Keyring) string

RemoveSession removes the SN Session from the keyring.

func SessionExists

func SessionExists(k keyring.Keyring) error

func SessionStatus

func SessionStatus(sKey string, k keyring.Keyring) (msg string, err error)

func UpdateSession

func UpdateSession(sess *Session, k keyring.Keyring, debug bool) error

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:

  1. Create separate Session instances for each goroutine
  2. Use mutex to serialize access to shared Session
  3. Never share HTTPClient with cookie jar across goroutines

See claudedocs/thread_safety.md for detailed guidance and examples.

func GetSession

func GetSession(httpClient *retryablehttp.Client, loadSession bool, sessionKey, server string, debug bool) (session Session, email string, err error)

func GetSessionFromUser

func GetSessionFromUser(httpClient *retryablehttp.Client, server string, debug bool) (Session, string, error)

func ParseSessionString

func ParseSessionString(ss string) (Session, error)

func (*Session) Refresh

func (sess *Session) Refresh() error

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.

func (*Session) Valid

func (sess *Session) Valid() bool

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"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL