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`
This commit is contained in:
Vaibhav Kamra 2022-07-19 16:42:28 -07:00 committed by GitHub
parent 43c024f4b2
commit 9f8287dc48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 3 deletions

View File

@ -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

View File

@ -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 {