Merge pull request #70 from benbjohnson/fix-global-settings
Fix global settings propagation
This commit is contained in:
@@ -149,10 +149,10 @@ type Config struct {
|
|||||||
func (c *Config) propagateGlobalSettings() {
|
func (c *Config) propagateGlobalSettings() {
|
||||||
for _, dbc := range c.DBs {
|
for _, dbc := range c.DBs {
|
||||||
for _, rc := range dbc.Replicas {
|
for _, rc := range dbc.Replicas {
|
||||||
if rc.AccessKeyID != "" {
|
if rc.AccessKeyID == "" {
|
||||||
rc.AccessKeyID = c.AccessKeyID
|
rc.AccessKeyID = c.AccessKeyID
|
||||||
}
|
}
|
||||||
if rc.SecretAccessKey != "" {
|
if rc.SecretAccessKey == "" {
|
||||||
rc.SecretAccessKey = c.SecretAccessKey
|
rc.SecretAccessKey = c.SecretAccessKey
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package main_test
|
package main_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io/ioutil"
|
||||||
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/benbjohnson/litestream"
|
"github.com/benbjohnson/litestream"
|
||||||
@@ -8,6 +10,37 @@ import (
|
|||||||
"github.com/benbjohnson/litestream/s3"
|
"github.com/benbjohnson/litestream/s3"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestReadConfigFile(t *testing.T) {
|
||||||
|
// Ensure global AWS settings are propagated down to replica configurations.
|
||||||
|
t.Run("PropagateGlobalSettings", func(t *testing.T) {
|
||||||
|
filename := filepath.Join(t.TempDir(), "litestream.yml")
|
||||||
|
if err := ioutil.WriteFile(filename, []byte(`
|
||||||
|
access-key-id: XXX
|
||||||
|
secret-access-key: YYY
|
||||||
|
|
||||||
|
dbs:
|
||||||
|
- path: /path/to/db
|
||||||
|
replicas:
|
||||||
|
- url: s3://foo/bar
|
||||||
|
`[1:]), 0666); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
config, err := main.ReadConfigFile(filename)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
} else if got, want := config.AccessKeyID, `XXX`; got != want {
|
||||||
|
t.Fatalf("AccessKeyID=%v, want %v", got, want)
|
||||||
|
} else if got, want := config.SecretAccessKey, `YYY`; got != want {
|
||||||
|
t.Fatalf("SecretAccessKey=%v, want %v", got, want)
|
||||||
|
} else if got, want := config.DBs[0].Replicas[0].AccessKeyID, `XXX`; got != want {
|
||||||
|
t.Fatalf("Replica.AccessKeyID=%v, want %v", got, want)
|
||||||
|
} else if got, want := config.DBs[0].Replicas[0].SecretAccessKey, `YYY`; got != want {
|
||||||
|
t.Fatalf("Replica.SecretAccessKey=%v, want %v", got, want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func TestNewFileReplicaFromConfig(t *testing.T) {
|
func TestNewFileReplicaFromConfig(t *testing.T) {
|
||||||
r, err := main.NewReplicaFromConfig(&main.ReplicaConfig{Path: "/foo"}, nil)
|
r, err := main.NewReplicaFromConfig(&main.ReplicaConfig{Path: "/foo"}, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user