Documentation
¶
Index ¶
- Variables
- func AdminAPIKey(input string) error
- type ApplicationState
- type Config
- func (c *Config) APIKeyUUID(appID string) (string, bool)
- func (c *Config) ActiveApplicationID() string
- func (c *Config) ApplicationIDByAlias(alias string) (string, bool)
- func (c *Config) ApplicationIDExists(appID string) (bool, string)
- func (c *Config) ApplicationIDForProfile(profileName string) (bool, string)
- func (c *Config) ApplicationInState(appID string) bool
- func (c *Config) ConfiguredProfiles() []*Profile
- func (c *Config) Default() *Profile
- func (c *Config) GetConfigFolder(xdgPath string) string
- func (c *Config) InitConfig()
- func (c *Config) Migrate() error
- func (c *Config) Profile() *Profile
- func (c *Config) ProfileExists(appName string) bool
- func (c *Config) ProfileNames() []string
- func (c *Config) RemoveProfile(name string) error
- func (c *Config) SaveApplication(appID, alias, apiKeyUUID, apiKey string, setCurrent bool) error
- func (c *Config) SetCrawlerAPIKey(appID, crawlerAPIKey string) error
- func (c *Config) SetCrawlerAuth(profile, crawlerUserID, crawlerAPIKey string) error
- func (c *Config) SetDefaultProfile(name string) error
- func (c *Config) ShouldMigrate() bool
- func (c *Config) StateFileExists() bool
- type IConfig
- type Profile
- func (p *Profile) Add() error
- func (p *Profile) GetAPIKey() (string, error)
- func (p *Profile) GetAdminAPIKey() (string, error)
- func (p *Profile) GetApplicationID() (string, error)
- func (p *Profile) GetCrawlerAPIKey() (string, error)
- func (p *Profile) GetCrawlerUserID() (string, error)
- func (p *Profile) GetFieldName(field string) string
- func (p *Profile) GetSearchHosts() []string
- func (p *Profile) LoadDefault()
- type State
Constants ¶
This section is empty.
Variables ¶
var ( // ErrAPIKeyNotConfigured is the error returned when the loaded profile is missing the api_key property ErrAPIKeyNotConfigured = errors.New("you have not configured your API key yet") // ErrApplicationIDNotConfigured is the error returned when the loaded profile is missing the application_id property ErrApplicationIDNotConfigured = errors.New("you have not configured your Application ID yet") // ErrAPIKeyMissingFromKeychain is the error returned when the current application has no API key in the OS keychain ErrAPIKeyMissingFromKeychain = errors.New("no API key stored in your keychain for the current application") // ErrCrawlerAPIKeyNotConfigured is the error returned when the loaded profile is missing the crawler_api_key property ErrCrawlerAPIKeyNotConfigured = errors.New("you have not configured your Crawler API key yet") // ErrCrawlerUserIDNotConfigured is the error returned when the loaded profile is missing the crawler_user_id property ErrCrawlerUserIDNotConfigured = errors.New("you have not configured your Crawler user ID yet") )
var DefaultSearchHosts string
DefaultSearchHosts can be set at build time via ldflags, e.g. -X github.com/algolia/cli/pkg/config.DefaultSearchHosts=host1,host2
Functions ¶
func AdminAPIKey ¶
AdminAPIKey validates that a string looks like an Admin API key.
Types ¶
type ApplicationState ¶ added in v1.12.0
type ApplicationState struct {
APIKeyUUID string `toml:"api_key_uuid,omitempty"`
Alias string `toml:"alias"`
SearchHosts []string `toml:"search_hosts,omitempty"`
CrawlerUserID string `toml:"crawler_user_id,omitempty"`
}
ApplicationState holds the non-secret, per-application data persisted in state.toml. Secrets (API keys) live in the OS keychain, not here.
type Config ¶
type Config struct {
ApplicationName string
CurrentProfile Profile
File string
StateFile string
// contains filtered or unexported fields
}
Config handles all overall configuration for the CLI.
It must not be copied after InitConfig: it holds sync primitives (govet copylocks) and CurrentProfile holds a back-pointer to it. Pass it by pointer.
func (*Config) APIKeyUUID ¶ added in v1.12.0
APIKeyUUID returns the CLI-managed API key UUID recorded in state.toml for the given application, and whether one is stored. A configured application with no UUID (a legacy setup) returns ("", false).
func (*Config) ActiveApplicationID ¶ added in v1.12.0
ActiveApplicationID exposes the application resolved by the new model (env → flag → state.toml alias → current application). Empty when only the legacy config.toml could answer.
func (*Config) ApplicationIDByAlias ¶ added in v1.12.0
ApplicationIDByAlias returns the application ID carrying the given alias in state.toml, and whether one was found.
func (*Config) ApplicationIDExists ¶
ApplicationIDExists check if an application ID exists in any profiles
func (*Config) ApplicationIDForProfile ¶ added in v1.8.0
ApplicationIDForProfile returns the application ID for a given profile name.
func (*Config) ApplicationInState ¶ added in v1.12.0
ApplicationInState reports whether state.toml already holds an entry for the given application, i.e. the application has been configured under the new storage model.
func (*Config) ConfiguredProfiles ¶
ConfiguredProfiles return the profiles in the configuration file
func (*Config) GetConfigFolder ¶
GetConfigFolder retrieves the folder where the configuration file is stored It searches for the xdg environment path first and will secondarily place it in the home directory
func (*Config) InitConfig ¶
func (c *Config) InitConfig()
InitConfig reads in profiles file and ENV variables if set.
func (*Config) Migrate ¶ added in v1.12.0
Migrate moves the legacy config.toml profiles into the new model (state.toml + OS keychain); config.toml is never modified. Keychain first, state.toml last (atomic): a failure leaves state.toml absent, so the migration retries on the next run.
func (*Config) ProfileExists ¶
ProfileExists check if a profile with the given name exists
func (*Config) ProfileNames ¶
ProfileNames returns the list of name of the configured profiles
func (*Config) RemoveProfile ¶
RemoveProfile remove a profile from the configuration
func (*Config) SaveApplication ¶ added in v1.12.0
SaveApplication persists an application's credentials in the new model. The keychain is written first so a failure never leaves state.toml pointing at a key that was not stored. Empty alias/apiKeyUUID preserve the values already in state.toml, and an existing crawler key is preserved.
Note: a command that already resolved its active application keeps that resolution for the rest of the command (per-command cache).
func (*Config) SetCrawlerAPIKey ¶ added in v1.12.0
SetCrawlerAPIKey stores the crawler API key in the keychain entry of the given application, preserving the search API key (load-modify-save).
func (*Config) SetCrawlerAuth ¶ added in v1.8.3
SetCrawlerAuth sets the config properties for crawler public api
func (*Config) SetDefaultProfile ¶
SetDefaultProfile set the default profile
func (*Config) ShouldMigrate ¶ added in v1.12.0
ShouldMigrate reports whether the one-time config.toml → state.toml + keychain migration still has to run: config.toml exists and state.toml (only written on success, so doubling as the "migrated" marker) does not.
The state.toml check comes first so an already-migrated machine — the steady state, hit on every command — settles in a single stat instead of also stat-ing config.toml.
func (*Config) StateFileExists ¶ added in v1.12.0
StateFileExists reports whether state.toml exists on disk, i.e. the new storage model (state.toml + OS keychain) is already in use on this machine.
type IConfig ¶
type IConfig interface {
InitConfig()
ConfiguredProfiles() []*Profile
ProfileNames() []string
ProfileExists(name string) bool
RemoveProfile(name string) error
SetDefaultProfile(name string) error
ApplicationIDExists(appID string) (bool, string)
ApplicationIDForProfile(profileName string) (bool, string)
SetCrawlerAuth(profileName, crawlerUserID, crawlerAPIKey string) error
// New model (state.toml + OS keychain).
ActiveApplicationID() string
APIKeyUUID(appID string) (string, bool)
ApplicationInState(appID string) bool
ApplicationIDByAlias(alias string) (string, bool)
SaveApplication(appID, alias, apiKeyUUID, apiKey string, setCurrent bool) error
SetCrawlerAPIKey(appID, crawlerAPIKey string) error
StateFileExists() bool
Profile() *Profile
Default() *Profile
}
type Profile ¶
type Profile struct {
Name string
ApplicationID string `mapstructure:"application_id"`
APIKey string `mapstructure:"api_key"`
AdminAPIKey string `mapstructure:"admin_api_key"`
SearchHosts []string `mapstructure:"search_hosts"`
Default bool `mapstructure:"default"`
// contains filtered or unexported fields
}
func (*Profile) GetAdminAPIKey ¶
func (*Profile) GetApplicationID ¶
func (*Profile) GetCrawlerAPIKey ¶ added in v1.4.0
GetCrawlerAPIKey returns the Crawler API key.
func (*Profile) GetCrawlerUserID ¶ added in v1.4.0
GetCrawlerUserID returns the Crawler user ID.
func (*Profile) GetFieldName ¶
func (*Profile) GetSearchHosts ¶ added in v1.3.5
func (*Profile) LoadDefault ¶
func (p *Profile) LoadDefault()
type State ¶ added in v1.12.0
type State struct {
CurrentApplicationID string `toml:"current_application_id"`
Applications map[string]ApplicationState `toml:"applications"`
}
State is the in-memory representation of state.toml, the new source of truth for non-secret CLI configuration.
func LoadState ¶ added in v1.12.0
LoadState reads state.toml from path. A missing file is not an error: it returns an empty, ready-to-use State.
func (*State) ApplicationByAlias ¶ added in v1.12.0
ApplicationByAlias returns the application ID whose entry carries the given alias, and whether such an entry was found.
func (*State) Save ¶ added in v1.12.0
Save writes the State to path atomically: it encodes to a temporary file in the same directory, then renames it over the target so a crash mid-write can never leave a half-written state.toml.
func (*State) SetCurrentApplication ¶ added in v1.12.0
SetCurrentApplication records appID as the currently selected application.
func (*State) UpsertApplication ¶ added in v1.12.0
func (s *State) UpsertApplication(appID string, app ApplicationState)
UpsertApplication inserts or replaces the state for a given application ID.