Documentation
¶
Overview ¶
Package config manages CLI configuration and profiles.
Index ¶
- Constants
- Variables
- func CredentialsFilePath() string
- func PluginConfigKey(scope, field string) string
- func RedactAPIKey(apiKey string) string
- type Compartment
- type Config
- func (c *Config) CopyProfile(source string, target string) error
- func (c *Config) EditConfig() error
- func (c *Config) GetConfigFolder(xdgPath string) string
- func (c *Config) GetInstalledPlugins() []string
- func (c *Config) GetProfile() *Profile
- func (c *Config) InitConfig()
- func (c *Config) ListProfiles() error
- func (c *Config) PrintConfig() error
- func (c *Config) RemoveAllAuthFields() error
- func (c *Config) RemoveAllProfiles() error
- func (c *Config) RemoveAuthFields(profileName string) error
- func (c *Config) RemoveProfile(profileName string) error
- func (c *Config) SwitchProfile(profileName string) error
- func (c *Config) WriteConfigField(field string, value interface{}) error
- type IConfig
- type Profile
- func (p *Profile) CreateProfile() error
- func (p *Profile) DeleteConfigField(field string) error
- func (p *Profile) GetAPIKey(livemode bool) (string, error)
- func (p *Profile) GetAccountID() (string, error)
- func (p *Profile) GetColor() (string, error)
- func (p *Profile) GetConfigField(field string) string
- func (p *Profile) GetDeviceName() (string, error)
- func (p *Profile) GetDisplayName() string
- func (p *Profile) GetExpiresAt(livemode bool) (time.Time, error)
- func (p *Profile) GetPublishableKey(livemode bool) (string, error)
- func (p *Profile) GetSessionCredentials() (*SessionCredentials, error)
- func (p *Profile) GetTerminalPOSDeviceID() string
- func (p *Profile) GetUserInfo() (*UserInfo, error)
- func (p *Profile) HasAPIKey(livemode bool) bool
- func (p *Profile) HasOverrideAPIKey() bool
- func (p *Profile) RegisterAlias(alias, key string)
- func (p *Profile) WriteConfigField(field, value string) error
- type SessionCredentials
- type UserInfo
Constants ¶
const ( // PluginConfigGlobalScope is used as the scope when a setting applies to all plugins. PluginConfigGlobalScope = "__global" // PluginConfigUpdatesField is the config field name controlling automatic updates. PluginConfigUpdatesField = "updates" )
const ( AccountIDName = "account_id" DeviceNameName = "device_name" DisplayNameName = "display_name" IsTermsAcceptanceValidName = "is_terms_acceptance_valid" TestModeAPIKeyName = "test_mode_api_key" TestModePubKeyName = "test_mode_pub_key" TestModeKeyExpiresAtName = "test_mode_key_expires_at" LiveModeAPIKeyName = "live_mode_api_key" LiveModePubKeyName = "live_mode_pub_key" LiveModeKeyExpiresAtName = "live_mode_key_expires_at" SandboxClaimURLName = "sandbox_claim_url" SandboxExpiresAtName = "sandbox_expires_at" UserInfoName = "user_info" )
config key names
const ( // DateStringFormat is the format for expiredAt date DateStringFormat = "2006-01-02" // KeyValidInDays is the number of days the API key is valid for KeyValidInDays = 90 // KeyManagementService is the key management service name KeyManagementService = "StripeCLI" )
const ColorAuto = "auto"
ColorAuto represents the auto-state for colors
const ColorOff = "off"
ColorOff represents the off-state for colors
const ColorOn = "on"
ColorOn represnets the on-state for colors
const UATKeychainItemKey = "uat"
Variables ¶
var KeyRing keyring.SecureStore
KeyRing is the global secure credential store.
Functions ¶
func CredentialsFilePath ¶ added in v1.43.0
func CredentialsFilePath() string
CredentialsFilePath returns the path of the plain-text credentials file used by the file fallback store when the OS keyring is unavailable.
func PluginConfigKey ¶ added in v1.40.1
PluginConfigKey returns the key for a plugin config field. Use PluginConfigGlobalScope as scope to target all plugins. Use the plugin name as scope to target a specific plugin. Example: PluginConfigKey("__global", "updates") to read or set the global updates setting Example: PluginConfigKey("apps", "updates") to read or set the updates setting for the "apps" plugin
func RedactAPIKey ¶ added in v1.10.4
RedactAPIKey returns a redacted version of API keys. The first 8 and last 4 characters are not redacted, everything else is replaced by "*" characters.
It panics if the provided string has less than 12 characters.
Types ¶
type Compartment ¶ added in v1.42.12
type Compartment struct {
CompartmentID string `json:"compartment_id" mapstructure:"compartment_id" toml:"compartment_id"`
Livemode bool `json:"livemode" mapstructure:"livemode" toml:"livemode"`
}
Compartment represents a Stripe compartment from the OIDC userinfo response.
type Config ¶
type Config struct {
Color string
LogLevel string
Profile Profile
ProfilesFile string
InstalledPlugins []string
}
Config handles all overall configuration for the CLI
func (*Config) CopyProfile ¶ added in v1.38.0
func (*Config) EditConfig ¶ added in v0.3.0
EditConfig opens the configuration file in the default editor.
func (*Config) GetConfigFolder ¶ added in v0.6.0
func (*Config) GetInstalledPlugins ¶ added in v1.9.0
GetInstalledPlugins returns a list of locally installed plugins. This does not vary by profile
func (*Config) GetProfile ¶ added in v1.8.0
GetProfile returns the Profile of the config
func (*Config) InitConfig ¶
func (c *Config) InitConfig()
InitConfig reads in profiles file and ENV variables if set.
func (*Config) ListProfiles ¶ added in v1.38.0
func (*Config) PrintConfig ¶ added in v0.3.0
PrintConfig outputs the contents of the configuration file.
func (*Config) RemoveAllAuthFields ¶ added in v1.40.1
RemoveAllAuthFields removes only auth-related fields from all profiles, preserving non-auth settings like color.
func (*Config) RemoveAllProfiles ¶ added in v1.4.0
RemoveAllProfiles removes all the profiles from the config file.
func (*Config) RemoveAuthFields ¶ added in v1.40.1
RemoveAuthFields removes only auth-related fields for the named profile, preserving non-auth settings like color.
func (*Config) RemoveProfile ¶ added in v1.4.0
RemoveProfile removes the profile whose name matches the provided profileName from the config file.
func (*Config) SwitchProfile ¶ added in v1.38.0
func (*Config) WriteConfigField ¶ added in v1.8.2
WriteConfigField updates a configuration field and writes the updated configuration to disk.
type IConfig ¶ added in v1.8.0
type IConfig interface {
GetProfile() *Profile
GetConfigFolder(xdgPath string) string
InitConfig()
EditConfig() error
PrintConfig() error
CopyProfile(source string, target string) error
ListProfiles() error
SwitchProfile(targetProfileName string) error
RemoveProfile(profileName string) error
RemoveAllProfiles() error
RemoveAuthFields(profileName string) error
RemoveAllAuthFields() error
WriteConfigField(field string, value interface{}) error
GetInstalledPlugins() []string
}
IConfig allows us to add more implementations, such as ones for unit tests
type Profile ¶
type Profile struct {
DeviceName string
ProfileName string
APIKey string
LiveModeAPIKey string
LiveModePublishableKey string
TestModeAPIKey string
TestModePublishableKey string
TerminalPOSDeviceID string
DisplayName string
AccountID string
SandboxClaimURL string
SandboxExpiresAt string
UAT string
UserInfo *UserInfo
}
Profile handles all things related to managing the project specific configurations
func (*Profile) CreateProfile ¶
CreateProfile creates a profile when logging in
func (*Profile) DeleteConfigField ¶ added in v0.3.0
DeleteConfigField deletes a configuration field.
func (*Profile) GetAPIKey ¶ added in v0.3.0
GetAPIKey will return the existing key for the given profile
func (*Profile) GetAccountID ¶ added in v1.7.4
GetAccountID returns the accountId for the given profile.
func (*Profile) GetColor ¶ added in v0.5.2
GetColor gets the color setting for the user based on the flag or the persisted color stored in the config file
func (*Profile) GetConfigField ¶
GetConfigField returns the configuration field for the specific profile
func (*Profile) GetDeviceName ¶
GetDeviceName returns the configured device name
func (*Profile) GetDisplayName ¶ added in v1.5.6
GetDisplayName returns the account display name of the user
func (*Profile) GetExpiresAt ¶ added in v1.10.4
GetExpiresAt returns the API key expirary date
func (*Profile) GetPublishableKey ¶ added in v0.6.0
GetPublishableKey returns the publishable key for the user
func (*Profile) GetSessionCredentials ¶ added in v1.14.2
func (p *Profile) GetSessionCredentials() (*SessionCredentials, error)
GetSessionCredentials retrieves the session credentials from the keyring
func (*Profile) GetTerminalPOSDeviceID ¶ added in v1.4.0
GetTerminalPOSDeviceID returns the device id from the config for Terminal quickstart to use
func (*Profile) GetUserInfo ¶ added in v1.42.12
GetUserInfo reads the stored UserInfo from the profile config. Returns nil, nil when no user_info has been saved yet.
func (*Profile) HasAPIKey ¶ added in v1.42.2
HasAPIKey reports whether an API key is available for the given mode without reading its value. For live mode this checks the keyring key list only, avoiding OS-level auth prompts (e.g. macOS Keychain) that would be required to access the secret data.
func (*Profile) HasOverrideAPIKey ¶ added in v1.42.2
HasOverrideAPIKey reports whether an in-memory API key override is active (via STRIPE_API_KEY env var or --api-key flag).
func (*Profile) RegisterAlias ¶ added in v0.3.0
RegisterAlias registers an alias for a given key.
func (*Profile) WriteConfigField ¶ added in v0.3.0
WriteConfigField updates a configuration field and writes the updated configuration to disk.
type SessionCredentials ¶ added in v1.14.2
type SessionCredentials struct {
UAT string `json:"uat"`
PrivateKey string `json:"private_key"`
AccountID string `json:"account_id"`
}
SessionCredentials are the credentials needed for this session
type UserInfo ¶ added in v1.42.12
type UserInfo struct {
Compartments []Compartment `json:"https://stripe.com/compartments" mapstructure:"compartments" toml:"compartments"`
}
UserInfo mirrors the OIDC userinfo endpoint response and is persisted as a nested table in the profile config.