cliconfig

package
v1.2.23 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
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)

func IsCI

func IsCI() bool

IsCI returns true if running in a CI environment

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 Load

func Load() (*Config, error)

Load loads the CLI config from disk, creating defaults if it doesn't exist

func (*Config) ClearAuthInfo

func (c *Config) ClearAuthInfo()

ClearAuthInfo clears cached auth info on logout (keeps anonymous_id and client selection)

func (*Config) GetClientID

func (c *Config) GetClientID() string

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

func (c *Config) GetDistinctID() string

GetDistinctID returns the distinct ID for PostHog (UserID if logged in, else AnonymousID)

func (*Config) MarkAliased

func (c *Config) MarkAliased(userID string)

MarkAliased records that we've aliased to this user ID

func (*Config) NeedsAlias

func (c *Config) NeedsAlias(userID string) bool

NeedsAlias returns true if we should alias anonymous ID to user ID

func (*Config) Save

func (c *Config) Save() error

Save persists the config to disk

func (*Config) SetAuthInfo

func (c *Config) SetAuthInfo(userID, userName, userEmail, selectedClientID, selectedClientName string)

SetAuthInfo caches auth info from login

Jump to

Keyboard shortcuts

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