config file supports environment variables
This commit is contained in:
parent
a74c1c0fd6
commit
4774b67ffd
2
build.sh
2
build.sh
@ -1,7 +1,7 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
RELEASE_VERSION="1.0.3"
|
RELEASE_VERSION="1.0.4"
|
||||||
|
|
||||||
buildpath=/tmp/gh-ost
|
buildpath=/tmp/gh-ost
|
||||||
target=gh-ost
|
target=gh-ost
|
||||||
|
@ -7,6 +7,8 @@ package base
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
@ -35,6 +37,10 @@ const (
|
|||||||
CutOverTwoStep = iota
|
CutOverTwoStep = iota
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
envVariableRegexp = regexp.MustCompile("[$][{](.*)[}]")
|
||||||
|
)
|
||||||
|
|
||||||
// MigrationContext has the general, global state of migration. It is used by
|
// MigrationContext has the general, global state of migration. It is used by
|
||||||
// all components throughout the migration process.
|
// all components throughout the migration process.
|
||||||
type MigrationContext struct {
|
type MigrationContext struct {
|
||||||
@ -441,8 +447,19 @@ func (this *MigrationContext) ReadConfigFile() error {
|
|||||||
if this.ConfigFile == "" {
|
if this.ConfigFile == "" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
gcfg.RelaxedParserMode = true
|
||||||
if err := gcfg.ReadFileInto(&this.config, this.ConfigFile); err != nil {
|
if err := gcfg.ReadFileInto(&this.config, this.ConfigFile); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We accept user & password in the form "${SOME_ENV_VARIABLE}" in which case we pull
|
||||||
|
// the given variable from os env
|
||||||
|
if submatch := envVariableRegexp.FindStringSubmatch(this.config.Client.User); len(submatch) > 1 {
|
||||||
|
this.config.Client.User = os.Getenv(submatch[1])
|
||||||
|
}
|
||||||
|
if submatch := envVariableRegexp.FindStringSubmatch(this.config.Client.Password); len(submatch) > 1 {
|
||||||
|
this.config.Client.Password = os.Getenv(submatch[1])
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
8
vendor/gopkg.in/gcfg.v1/set.go
generated
vendored
8
vendor/gopkg.in/gcfg.v1/set.go
generated
vendored
@ -16,6 +16,8 @@ type tag struct {
|
|||||||
intMode string
|
intMode string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var RelaxedParserMode = false
|
||||||
|
|
||||||
func newTag(ts string) tag {
|
func newTag(ts string) tag {
|
||||||
t := tag{}
|
t := tag{}
|
||||||
s := strings.Split(ts, ",")
|
s := strings.Split(ts, ",")
|
||||||
@ -197,6 +199,9 @@ func set(cfg interface{}, sect, sub, name string, blank bool, value string) erro
|
|||||||
vCfg := vPCfg.Elem()
|
vCfg := vPCfg.Elem()
|
||||||
vSect, _ := fieldFold(vCfg, sect)
|
vSect, _ := fieldFold(vCfg, sect)
|
||||||
if !vSect.IsValid() {
|
if !vSect.IsValid() {
|
||||||
|
if RelaxedParserMode {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return fmt.Errorf("invalid section: section %q", sect)
|
return fmt.Errorf("invalid section: section %q", sect)
|
||||||
}
|
}
|
||||||
if vSect.Kind() == reflect.Map {
|
if vSect.Kind() == reflect.Map {
|
||||||
@ -232,6 +237,9 @@ func set(cfg interface{}, sect, sub, name string, blank bool, value string) erro
|
|||||||
}
|
}
|
||||||
vVar, t := fieldFold(vSect, name)
|
vVar, t := fieldFold(vSect, name)
|
||||||
if !vVar.IsValid() {
|
if !vVar.IsValid() {
|
||||||
|
if RelaxedParserMode {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return fmt.Errorf("invalid variable: "+
|
return fmt.Errorf("invalid variable: "+
|
||||||
"section %q subsection %q variable %q", sect, sub, name)
|
"section %q subsection %q variable %q", sect, sub, name)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user