Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Commit

Permalink
Interpolate environment variable
Browse files Browse the repository at this point in the history
In task manifest and global config
  • Loading branch information
kindermoumoute committed Dec 9, 2016
1 parent 4c4e133 commit 891564c
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cmd/snaptel/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ func createTaskUsingTaskManifest(ctx *cli.Context) error {
if e != nil {
return fmt.Errorf("File error [%s] - %v\n", ext, e)
}

file = []byte(os.ExpandEnv(string(file)))
// create an empty task struct and unmarshal the contents of the file into that object
t := task{}
switch ext {
Expand Down
2 changes: 2 additions & 0 deletions control/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ limitations under the License.
package control

import (
"os"
"testing"
"time"

Expand Down Expand Up @@ -215,6 +216,7 @@ func TestControlConfigYaml(t *testing.T) {
config := &mockConfig{
Control: GetDefaultConfig(),
}
os.Setenv("password", "$password")
path := "../examples/configs/snap-config-sample.yaml"
err := cfgfile.Read(path, &config, MOCK_CONSTRAINTS)
var cfg *Config
Expand Down
3 changes: 2 additions & 1 deletion core/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"fmt"
"io"
"io/ioutil"
"os"
"time"

log "github.com/Sirupsen/logrus"
Expand Down Expand Up @@ -283,7 +284,7 @@ func UnmarshalBody(in interface{}, body io.ReadCloser) (int, error) {
if err != nil {
return 500, err
}
err = json.Unmarshal(b, in)
err = json.Unmarshal([]byte(os.ExpandEnv(string(b))), in)
if err != nil {
return 400, err
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/cfgfile/cfgfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"errors"
"fmt"
"io/ioutil"
"os"
"strings"

"github.com/ghodss/yaml"
Expand Down Expand Up @@ -104,6 +105,7 @@ func Read(path string, v interface{}, schema string) []serror.SnapError {
if err != nil {
return []serror.SnapError{serror.New(err)}
}
b = []byte(os.ExpandEnv(string(b)))
// convert from YAML to JSON (remember, JSON is actually valid YAML)
jb, err := yaml.YAMLToJSON(b)
if err != nil {
Expand Down

0 comments on commit 891564c

Please sign in to comment.