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:
parent
43c024f4b2
commit
9f8287dc48
@ -1,6 +1,8 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/alcionai/corso/cli/utils"
|
"github.com/alcionai/corso/cli/utils"
|
||||||
"github.com/alcionai/corso/pkg/credentials"
|
"github.com/alcionai/corso/pkg/credentials"
|
||||||
"github.com/alcionai/corso/pkg/storage"
|
"github.com/alcionai/corso/pkg/storage"
|
||||||
@ -59,9 +61,9 @@ func configureStorage(vpr *viper.Viper, readConfigFromViper bool, overrides map[
|
|||||||
|
|
||||||
s3Cfg = storage.S3Config{
|
s3Cfg = storage.S3Config{
|
||||||
AWS: aws,
|
AWS: aws,
|
||||||
Bucket: first(overrides[storage.Bucket], s3Cfg.Bucket),
|
Bucket: first(overrides[storage.Bucket], s3Cfg.Bucket, os.Getenv(storage.BucketKey)),
|
||||||
Endpoint: first(overrides[storage.Endpoint], s3Cfg.Endpoint),
|
Endpoint: first(overrides[storage.Endpoint], s3Cfg.Endpoint, os.Getenv(storage.EndpointKey)),
|
||||||
Prefix: first(overrides[storage.Prefix], s3Cfg.Prefix),
|
Prefix: first(overrides[storage.Prefix], s3Cfg.Prefix, os.Getenv(storage.PrefixKey)),
|
||||||
}
|
}
|
||||||
|
|
||||||
// compose the common config and credentials
|
// compose the common config and credentials
|
||||||
|
|||||||
@ -20,6 +20,14 @@ var (
|
|||||||
errMissingRequired = errors.New("missing required storage configuration")
|
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
|
// Storage defines a storage provider, along with any configuration
|
||||||
// requried to set up or communicate with that provider.
|
// requried to set up or communicate with that provider.
|
||||||
type Storage struct {
|
type Storage struct {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user