Documentation
¶
Overview ¶
Package config resolves credentials and the environment they point at.
The API key prefix encodes the environment — sk_sandbox_ against sandbox, sk_live_ against production — so there is no separate --env flag that can disagree with the key actually in use. Passing a sandbox key and a production base URL is not a combination worth supporting.
Index ¶
Constants ¶
const ( SandboxBaseURL = "https://sandbox-api.bachs.io" LiveBaseURL = "https://api.bachs.io" )
Variables ¶
var ErrNoAPIKey = errors.New(
"not logged in\n" +
" run: bachs login\n" +
" CI: export BACHS_API_KEY=sk_sandbox_...",
)
ErrNoAPIKey is returned when no credential can be found anywhere.
Leads with the browser flow because that is the one that does not put a key in shell history. The env var is listed second for CI, where there is nobody to approve anything.
Functions ¶
func Dir ¶
func Dir() string
Dir is where credentials live. Honours BACHS_CONFIG_DIR for tests and for anyone who keeps config somewhere unusual.
func Save ¶
Save writes the key for later commands.
0600 in a 0700 directory. This is a plaintext secret on disk, which is worth being explicit about: the OS keychain would be better, and doing that across macOS, Linux and Windows is enough work to be its own change. Until then the file mode is the whole protection, so it is set deliberately rather than left to the process umask.
Types ¶
type Config ¶
func Load ¶
Load resolves credentials in precedence order: an explicit flag, then BACHS_API_KEY, then the config file.
The env var sits above the file so CI can run without writing one, and below the flag so a one-off invocation can target another account.
func (Config) IsSandbox ¶
IsSandbox reports whether this key targets sandbox rather than production.
func (Config) WebSocketURL ¶
WebSocketURL is the forwarding socket for this environment.