Allow replication without config file.
This commit changes `litestream replicate` to accept a database path and a replica URL instead of using the config file. This allows people to quickly try out the tool instead of learning the config file syntax.
This commit is contained in:
25
s3/s3.go
25
s3/s3.go
@@ -14,6 +14,7 @@ import (
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/aws/credentials"
|
||||
"github.com/aws/aws-sdk-go/aws/defaults"
|
||||
"github.com/aws/aws-sdk-go/aws/session"
|
||||
"github.com/aws/aws-sdk-go/service/s3"
|
||||
"github.com/aws/aws-sdk-go/service/s3/s3manager"
|
||||
@@ -647,10 +648,9 @@ func (r *Replica) Init(ctx context.Context) (err error) {
|
||||
}
|
||||
|
||||
// Create new AWS session.
|
||||
sess, err := session.NewSession(&aws.Config{
|
||||
Credentials: credentials.NewStaticCredentials(r.AccessKeyID, r.SecretAccessKey, ""),
|
||||
Region: aws.String(region),
|
||||
})
|
||||
config := r.config()
|
||||
config.Region = aws.String(region)
|
||||
sess, err := session.NewSession(config)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot create aws session: %w", err)
|
||||
}
|
||||
@@ -659,12 +659,21 @@ func (r *Replica) Init(ctx context.Context) (err error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
// config returns the AWS configuration. Uses the default credential chain
|
||||
// unless a key/secret are explicitly set.
|
||||
func (r *Replica) config() *aws.Config {
|
||||
config := defaults.Get().Config
|
||||
if r.AccessKeyID != "" || r.SecretAccessKey != "" {
|
||||
config.Credentials = credentials.NewStaticCredentials(r.AccessKeyID, r.SecretAccessKey, "")
|
||||
}
|
||||
return config
|
||||
}
|
||||
|
||||
func (r *Replica) findBucketRegion(ctx context.Context, bucket string) (string, error) {
|
||||
// Connect to US standard region to fetch info.
|
||||
sess, err := session.NewSession(&aws.Config{
|
||||
Credentials: credentials.NewStaticCredentials(r.AccessKeyID, r.SecretAccessKey, ""),
|
||||
Region: aws.String("us-east-1"),
|
||||
})
|
||||
config := r.config()
|
||||
config.Region = aws.String("us-east-1")
|
||||
sess, err := session.NewSession(config)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user