Documentation
¶
Overview ¶
Package cli provides the connection settings a takt client resolves from flags, the environment and the config file, in that order.
The file is the human path: `takt auth login` writes the token it minted here, because a child process cannot set an environment variable in its parent shell. The environment is the machine path: CI injects TAKT_TOKEN in one line. Flags are the most specific and win over both. Exported so that anyone writing their own takt client can honour the same settings.
Index ¶
Constants ¶
const DefaultAddress = "http://localhost:7373"
DefaultAddress is where a client connects when nothing names a server.
Variables ¶
This section is empty.
Functions ¶
func NewContext ¶ added in v0.6.0
NewContext returns a context that carries the resolved settings.
This is how the CLI hands the settings it resolved once, at the root command, to a subcommand that needs more than the client built from them. The login command is the reason: it connects without the stored credential and writes the settings back beside the token it mints, neither of which the shared client can do for it.
Types ¶
type Config ¶
type Config struct {
// The address of the takt server, as a URL.
Address string `toml:"address"`
// The token presented as a bearer credential. Empty sends no credential.
Token string `toml:"token"`
// The path of a PEM certificate authority file to check the server's
// certificate against instead of the system roots.
CACert string `toml:"ca_cert"`
// The file the settings were read from, and where Save writes them
// back. Not a setting itself: Load records it, and it never appears
// in the file.
File string `toml:"-"`
}
The Config type contains the settings a client connects with.
There is no flag for the token, deliberately: a token passed as a flag lands in shell history and process listings for no benefit the other sources lack.
func FromContext ¶ added in v0.6.0
FromContext returns the settings the context carries, or the zero Config when it carries none.
func Load ¶
Load reads the config file at the given path, reporting an absent file as a Config with no settings: a client that never logged in simply has no file yet. Either way the result records the path, so Save knows where the settings belong.
func Resolve ¶
Resolve returns the settings a client should connect with, taking each field from the most specific source that supplies it: the flag values in sources, then the TAKT_ADDRESS, TAKT_TOKEN and TAKT_CA_CERT environment variables, then the config file the sources name.
The address falls back to DefaultAddress when nothing supplies one, so a client on the same host as its server needs no configuration at all.
type Sources ¶ added in v0.6.0
type Sources struct {
// The --config flag value, naming the config file. Empty resolves
// the file the way Path does.
ConfigPath string
// The --address flag value.
Address string
// The --ca-cert flag value.
CACert string
}
The Sources type names the flag values Resolve folds in. An empty field means the flag was not given, so the environment and the file stay visible behind it.