From 7f4325e814554dde1bd1ab696ea626fee2759554 Mon Sep 17 00:00:00 2001 From: Ben Johnson Date: Thu, 22 Apr 2021 15:58:17 -0600 Subject: [PATCH] Allow use of LITESTREAM prefixed environment variables This commit adds optional `LITESTREAM_ACCESS_KEY_ID` and `LITESTREAM_SECRET_ACCESS_KEY` environment variables that can be used instead of their `AWS` counterparts. The AWS-prefixed variables have caused some confusion with users who were not using AWS S3. --- cmd/litestream/main.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/cmd/litestream/main.go b/cmd/litestream/main.go index 9d5d67e..4ff0085 100644 --- a/cmd/litestream/main.go +++ b/cmd/litestream/main.go @@ -61,6 +61,9 @@ func (m *Main) Run(ctx context.Context, args []string) (err error) { return runWindowsService(ctx) } + // Copy "LITESTEAM" environment credentials. + applyLitestreamEnv() + // Extract command name. var cmd string if len(args) > 0 { @@ -427,6 +430,22 @@ func newS3ReplicaFromConfig(c *ReplicaConfig, db *litestream.DB) (_ *s3.Replica, return r, nil } +// applyLitestreamEnv copies "LITESTREAM" prefixed environment variables to +// their AWS counterparts as the "AWS" prefix can be confusing when using a +// non-AWS S3-compatible service. +func applyLitestreamEnv() { + if v, ok := os.LookupEnv("LITESTREAM_ACCESS_KEY_ID"); ok { + if _, ok := os.LookupEnv("AWS_ACCESS_KEY_ID"); !ok { + os.Setenv("AWS_ACCESS_KEY_ID", v) + } + } + if v, ok := os.LookupEnv("LITESTREAM_SECRET_ACCESS_KEY"); ok { + if _, ok := os.LookupEnv("AWS_SECRET_ACCESS_KEY"); !ok { + os.Setenv("AWS_SECRET_ACCESS_KEY", v) + } + } +} + // ParseReplicaURL parses a replica URL. func ParseReplicaURL(s string) (scheme, host, urlpath string, err error) { u, err := url.Parse(s)