Documentation
¶
Index ¶
- Constants
- func GetAPIKey() string
- func GetPath() string
- func IsAnalyticsDisabledByEnv() bool
- func IsAnalyticsEnabled() bool
- func IsCI() bool
- type AuthMethod
- type ClientIDSource
- type Config
- func (c *Config) ClearAuthInfo()
- func (c *Config) GetClientID() string
- func (c *Config) GetClientIDWithSource() (clientID string, source ClientIDSource)
- func (c *Config) GetDistinctID() string
- func (c *Config) MarkAliased(userID string)
- func (c *Config) NeedsAlias(userID string) bool
- func (c *Config) Save() error
- func (c *Config) SetAuthInfo(userID, userName, userEmail, selectedClientID, selectedClientName string)
Constants ¶
const ( // EnvAnalyticsDisabled is the environment variable to disable analytics EnvAnalyticsDisabled = "TUSK_ANALYTICS_DISABLED" // EnvClientID is the environment variable to override client ID EnvClientID = "TUSK_CLIENT_ID" // EnvCI indicates CI environment (skip notice) EnvCI = "CI" // EnvAuthMethod is the environment variable to force a specific auth method EnvAuthMethod = "TUSK_AUTH_METHOD" // EnvAPIKey is the environment variable for API key authentication EnvAPIKey = "TUSK_API_KEY" // #nosec G101 -- This is an env var name, not a credential )
Variables ¶
This section is empty.
Functions ¶
func GetAPIKey ¶
func GetAPIKey() string
GetAPIKey returns the API key from the environment variable
func GetPath ¶
func GetPath() string
GetPath returns the path to the CLI config file. Returns empty string if no suitable config directory can be determined.
func IsAnalyticsDisabledByEnv ¶
func IsAnalyticsDisabledByEnv() bool
IsAnalyticsDisabledByEnv returns true if analytics is disabled via environment variable
func IsAnalyticsEnabled ¶
func IsAnalyticsEnabled() bool
IsAnalyticsEnabled checks if analytics is enabled (env var takes precedence)
Types ¶
type AuthMethod ¶
type AuthMethod string
AuthMethod represents the authentication method being used
const ( AuthMethodNone AuthMethod = "none" AuthMethodJWT AuthMethod = "jwt" AuthMethodAPIKey AuthMethod = "api_key" )
func GetAuthMethod ¶
func GetAuthMethod(hasJWT bool) (envValue string, effective AuthMethod)
GetAuthMethod returns the effective auth method based on TUSK_AUTH_METHOD env var and available credentials. Returns the raw env var value (normalized) and effective method. hasJWT should be true if the user has a valid JWT token (checked via authenticator.TryExistingAuth).
type ClientIDSource ¶
type ClientIDSource string
ClientIDSource indicates where the client ID came from
const ( ClientIDSourceNone ClientIDSource = "" ClientIDSourceEnvVar ClientIDSource = "TUSK_CLIENT_ID env var" ClientIDSourceSelected ClientIDSource = "selected from login" )
type Config ¶
type Config struct {
// Analytics settings
AnonymousID string `json:"anonymous_id"` // "cli-anon-<uuid>" generated on first run
AnalyticsEnabled bool `json:"analytics_enabled"` // Default true
IsTuskDeveloper bool `json:"is_tusk_developer"` // For Tusk employees
NoticeShown bool `json:"notice_shown"` // First-run notice displayed
// Cached auth info (updated on login/logout, avoids backend calls)
UserID string `json:"user_id,omitempty"` // From authInfo.User.Id
UserName string `json:"user_name,omitempty"` // From authInfo.User.Name
UserEmail string `json:"user_email,omitempty"` // From authInfo.User.Email
SelectedClientID string `json:"selected_client_id,omitempty"` // User's chosen client ID
SelectedClientName string `json:"selected_client_name,omitempty"` // User's chosen client name
AliasedToUserID string `json:"aliased_to_user_id,omitempty"` // Prevent re-aliasing
}
Config represents the user-level CLI configuration stored at ~/.config/tusk/cli.json
func (*Config) ClearAuthInfo ¶
func (c *Config) ClearAuthInfo()
ClearAuthInfo clears cached auth info on logout (keeps anonymous_id and client selection)
func (*Config) GetClientID ¶
GetClientID returns the client ID (env var takes precedence, then selected client)
func (*Config) GetClientIDWithSource ¶
func (c *Config) GetClientIDWithSource() (clientID string, source ClientIDSource)
GetClientIDWithSource returns the client ID and its source Note that if auth method is API key, we don't know the client ID and so return empty string.
func (*Config) GetDistinctID ¶
GetDistinctID returns the distinct ID for PostHog (UserID if logged in, else AnonymousID)
func (*Config) MarkAliased ¶
MarkAliased records that we've aliased to this user ID
func (*Config) NeedsAlias ¶
NeedsAlias returns true if we should alias anonymous ID to user ID
func (*Config) SetAuthInfo ¶
func (c *Config) SetAuthInfo(userID, userName, userEmail, selectedClientID, selectedClientName string)
SetAuthInfo caches auth info from login