Documentation
¶
Overview ¶
Package config manages global configuration parameters. It has a data type and helpers for getting information out of the runtime environment, and making it available to commands that need it.
Index ¶
Constants ¶
const ( // EnvVarToken is the env var we look in for the Fastly API token. // gosec flagged this: // G101 (CWE-798): Potential hardcoded credentials // Disabling as we use the value in the command help output. /* #nosec */ EnvVarToken = "FASTLY_API_TOKEN" // EnvVarEndpoint is the env var we look in for the API endpoint. EnvVarEndpoint = "FASTLY_API_ENDPOINT" )
const DefaultEndpoint = "https://api.fastly.com"
DefaultEndpoint is the default Fastly API endpoint.
Variables ¶
var FilePath = func() string { if dir, err := os.UserConfigDir(); err == nil { return filepath.Join(dir, "fastly", "config.toml") } if dir, err := os.UserHomeDir(); err == nil { return filepath.Join(dir, ".fastly", "config.toml") } panic("unable to deduce user config dir or user home dir") }()
FilePath is the location of the fastly CLI application config file.
Functions ¶
This section is empty.
Types ¶
type Data ¶
type Data struct {
File File
Env Environment
Flag Flag
Client api.Interface
RTSClient api.RealtimeStatsInterface
}
Data holds global-ish configuration data from all sources: environment variables, config files, and flags. It has methods to give each parameter to the components that need it, including the place the parameter came from, which is a requirement.
If the same parameter is defined in multiple places, it is resolved according to the following priority order: the config file (lowest priority), env vars, and then explicit flags (highest priority).
This package and its types are only meant for parameters that are applicable to most/all subcommands (e.g. API token) and are consistent for a given user (e.g. an email address). Otherwise, parameters should be defined in specific command structs, and parsed as flags.
type Environment ¶
Environment represents all of the configuration parameters that can come from environment variables.
func (*Environment) Read ¶
func (e *Environment) Read(env map[string]string)
Read populates the fields from the provided environment.
type File ¶
type File struct {
Token string `toml:"token"`
Email string `toml:"email"`
Endpoint string `toml:"endpoint"`
LastVersionCheck string `toml:"last_version_check"`
}
File represents all of the configuration parameters that can end up in the config file. At some point, it may expand to include e.g. user profiles.
func (*File) Write ¶
Write the File to filename on disk.
NOTE: the expected workflow for this method is for the caller to have modified the public field(s) first so that we can write new content to the config file from the receiver object itself.
EXAMPLE: file.LastVersionCheck = time.Now().Format(time.RFC3339) file.Write(configFilePath)
type Flag ¶
Flag represents all of the configuration parameters that can be set with explicit flags. Consumers should bind their flag values to these fields directly.
type Source ¶
type Source uint8
Source enumerates where a config parameter is taken from.
const ( // SourceUndefined indicates the parameter isn't provided in any of the // available sources, similar to "not found". SourceUndefined Source = iota // SourceFile indicates the parameter came from a config file. SourceFile // SourceEnvironment indicates the parameter came from an env var. SourceEnvironment // SourceFlag indicates the parameter came from an explicit flag. SourceFlag // SourceDefault indicates the parameter came from a program default. SourceDefault // DirectoryPermissions is the default directory permissions for the config file directory. DirectoryPermissions = 0700 // FilePermissions is the default file permissions for the config file. FilePermissions = 0600 )