Documentation
¶
Overview ¶
Package sensecli just contains some helpers used to set up binaries that need Sense credentials.
It permits users to configure the Sense client using flags (--sense-email), environment variables (SENSE_EMAIL), or a YAML configuration file.
The easiest thing to do is:
func main() {
configFile, flagCreds := sensecli.SetupStandardFlags()
flag.Parse()
clients, err := sensecli.CreateClients(context.Background(), configFile, flagCreds)
...
}
By default, the --sense-config flag and SENSE_CONFIG environment variable overrides everything else by specifying the name of a YAML configuration file that contains the following format:
accounts:
- credentials:
email: # specify the e-mail address directly
email-from: # read the e-mail address from a file
password: # specify the password directly
password-from: # read the password from a file
mfa-from: # read the MFA code from a file
mfa-command: # read the MFA code from a command
Multiple accounts can be configured in the same file. If you specify a configuration file, flags and environment variables will be ignored.
If no configuration file is specified, the following flags will be used first to configure a single Sense client:
--sense-email --sense-email-from --sense-password --sense-password-from --sense-mfa-from --sense-mfa-command
These environment variables will be used for any flag that is not set:
SENSE_EMAIL SENSE_EMAIL_FROM SENSE_PASSWORD SENSE_PASSWORD_FROM SENSE_MFA_FROM SENSE_MFA_COMMAND
These will be blended into one set of credentials that will be used to authenticate the client.
If no flags or environment variables are set, a single unauthenticated Sense client will be created.
Index ¶
- Variables
- func CreateClients(ctx context.Context, configFile *string, flagCreds *PasswordCredentials, ...) ([]*sense.Client, error)
- type Account
- type ConfigFile
- func ConfigFromFileOrFlags(configFile *string, flagCreds *PasswordCredentials) (*ConfigFile, error)
- func GetConfig(configFile *string, accounts []*PasswordCredentials) (*ConfigFile, error)
- func ReadConfigFileYAML(path string) (*ConfigFile, error)
- func ReadConfigYAML(r io.Reader) (*ConfigFile, error)
- type PasswordCredentials
- func BlendCredentials(a, b PasswordCredentials) *PasswordCredentials
- func CredentialsFromEnv(vars varNames) *PasswordCredentials
- func CredentialsFromStandardEnv() *PasswordCredentials
- func SetupCredentialsFromFlags(flagPrefix string, names varNames, flagSuffix, descSuffix string) *PasswordCredentials
- func SetupCredentialsFromStandardFlags() *PasswordCredentials
- func SetupStandardFlags() (*string, *PasswordCredentials)
Constants ¶
This section is empty.
Variables ¶
var StandardEnvVars = varNames{ ConfigFile: "SENSE_CONFIG", Email: "SENSE_EMAIL", EmailFrom: "SENSE_EMAIL_FROM", Password: "SENSE_PASSWORD", PasswordFrom: "SENSE_PASSWORD_FROM", MfaFrom: "SENSE_MFA_FROM", MfaCommand: "SENSE_MFA_COMMAND", }
var StandardFlagVars = varNames{ ConfigFile: "sense-config", Email: "sense-email", EmailFrom: "sense-email-from", Password: "sense-password", PasswordFrom: "sense-password-from", MfaFrom: "sense-mfa-from", MfaCommand: "sense-mfa-command", }
Functions ¶
Types ¶
type Account ¶
type Account struct {
Credentials *PasswordCredentials `json:"credentials,omitempty" yaml:"credentials,omitempty"`
}
Account in the ConfigFile contains credentials for a single Sense account.
type ConfigFile ¶
type ConfigFile struct {
Accounts []Account `json:"accounts,omitempty" yaml:"accounts,omitempty"`
}
ConfigFile defines a general Sense client configuration. At the moment this is simply a list of Sense accounts.
func ConfigFromFileOrFlags ¶
func ConfigFromFileOrFlags(configFile *string, flagCreds *PasswordCredentials) (*ConfigFile, error)
func GetConfig ¶
func GetConfig(configFile *string, accounts []*PasswordCredentials) (*ConfigFile, error)
func ReadConfigFileYAML ¶
func ReadConfigFileYAML(path string) (*ConfigFile, error)
func ReadConfigYAML ¶
func ReadConfigYAML(r io.Reader) (*ConfigFile, error)
type PasswordCredentials ¶
type PasswordCredentials struct {
Email string `json:"email,omitempty" yaml:"email,omitempty"`
EmailFrom string `json:"email-from,omitempty" yaml:"email-from,omitempty"`
Password string `json:"password,omitempty" yaml:"password,omitempty"`
PasswordFrom string `json:"password-from,omitempty" yaml:"password-from,omitempty"`
MfaFrom string `json:"mfa-from,omitempty" yaml:"mfa-from,omitempty"`
MfaCommand string `json:"mfa-command,omitempty" yaml:"mfa-command,omitempty"`
}
PasswordCredentials defines the various ways to specify Sense credentials.
func BlendCredentials ¶
func BlendCredentials(a, b PasswordCredentials) *PasswordCredentials
func CredentialsFromEnv ¶
func CredentialsFromEnv(vars varNames) *PasswordCredentials
func CredentialsFromStandardEnv ¶
func CredentialsFromStandardEnv() *PasswordCredentials
func SetupCredentialsFromFlags ¶
func SetupCredentialsFromFlags(flagPrefix string, names varNames, flagSuffix, descSuffix string) *PasswordCredentials
func SetupCredentialsFromStandardFlags ¶
func SetupCredentialsFromStandardFlags() *PasswordCredentials
func SetupStandardFlags ¶
func SetupStandardFlags() (*string, *PasswordCredentials)