From 9f8287dc4853d4d2d125dbd52bd864ed69a6d6d6 Mon Sep 17 00:00:00 2001 From: Vaibhav Kamra Date: Tue, 19 Jul 2022 16:42:28 -0700 Subject: [PATCH] Support specifying repo config via env (#363) This allows the user to specify repo configuration via environment variables when a config file is not available. This is a temporary fix - ideally we would leverage Viper for this but we currently only use Viper if a config file is available so that needs to be refactored a bit. [1] `TENANT_ID` (already supported) `BUCKET` `ENDPOINT` `PREFIX` --- src/cli/config/storage.go | 8 +++++--- src/pkg/storage/storage.go | 8 ++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/cli/config/storage.go b/src/cli/config/storage.go index e173a83bf..da3e96b7a 100644 --- a/src/cli/config/storage.go +++ b/src/cli/config/storage.go @@ -1,6 +1,8 @@ package config import ( + "os" + "github.com/alcionai/corso/cli/utils" "github.com/alcionai/corso/pkg/credentials" "github.com/alcionai/corso/pkg/storage" @@ -59,9 +61,9 @@ func configureStorage(vpr *viper.Viper, readConfigFromViper bool, overrides map[ s3Cfg = storage.S3Config{ AWS: aws, - Bucket: first(overrides[storage.Bucket], s3Cfg.Bucket), - Endpoint: first(overrides[storage.Endpoint], s3Cfg.Endpoint), - Prefix: first(overrides[storage.Prefix], s3Cfg.Prefix), + Bucket: first(overrides[storage.Bucket], s3Cfg.Bucket, os.Getenv(storage.BucketKey)), + Endpoint: first(overrides[storage.Endpoint], s3Cfg.Endpoint, os.Getenv(storage.EndpointKey)), + Prefix: first(overrides[storage.Prefix], s3Cfg.Prefix, os.Getenv(storage.PrefixKey)), } // compose the common config and credentials diff --git a/src/pkg/storage/storage.go b/src/pkg/storage/storage.go index 66c196e01..484df2d47 100644 --- a/src/pkg/storage/storage.go +++ b/src/pkg/storage/storage.go @@ -20,6 +20,14 @@ var ( errMissingRequired = errors.New("missing required storage configuration") ) +// envvar consts +// TODO: Remove these and leverage Viper AutomaticEnv() instead +const ( + BucketKey = "BUCKET" + EndpointKey = "ENDPOINT" + PrefixKey = "PREFIX" +) + // Storage defines a storage provider, along with any configuration // requried to set up or communicate with that provider. type Storage struct {