Skip to content

Commit a75912d

Browse files
author
Shlomi Noach
authored
Merge pull request #105 from github/credentials-env-variables
config file supports environment variables
2 parents 071817a + 4774b67 commit a75912d

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22
#
33
#
4-
RELEASE_VERSION="1.0.3"
4+
RELEASE_VERSION="1.0.4"
55

66
buildpath=/tmp/gh-ost
77
target=gh-ost

go/base/context.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ package base
77

88
import (
99
"fmt"
10+
"os"
11+
"regexp"
1012
"strings"
1113
"sync"
1214
"sync/atomic"
@@ -35,6 +37,10 @@ const (
3537
CutOverTwoStep = iota
3638
)
3739

40+
var (
41+
envVariableRegexp = regexp.MustCompile("[$][{](.*)[}]")
42+
)
43+
3844
// MigrationContext has the general, global state of migration. It is used by
3945
// all components throughout the migration process.
4046
type MigrationContext struct {
@@ -441,8 +447,19 @@ func (this *MigrationContext) ReadConfigFile() error {
441447
if this.ConfigFile == "" {
442448
return nil
443449
}
450+
gcfg.RelaxedParserMode = true
444451
if err := gcfg.ReadFileInto(&this.config, this.ConfigFile); err != nil {
445452
return err
446453
}
454+
455+
// We accept user & password in the form "${SOME_ENV_VARIABLE}" in which case we pull
456+
// the given variable from os env
457+
if submatch := envVariableRegexp.FindStringSubmatch(this.config.Client.User); len(submatch) > 1 {
458+
this.config.Client.User = os.Getenv(submatch[1])
459+
}
460+
if submatch := envVariableRegexp.FindStringSubmatch(this.config.Client.Password); len(submatch) > 1 {
461+
this.config.Client.Password = os.Getenv(submatch[1])
462+
}
463+
447464
return nil
448465
}

vendor/gopkg.in/gcfg.v1/set.go

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)