Merge pull request #531 from mitchellh/521
common/config: config filter function [GH-521]
This commit is contained in:
commit
5f95e18d41
|
@ -143,7 +143,7 @@ func (b *Builder) Prepare(raws ...interface{}) error {
|
|||
return errs
|
||||
}
|
||||
|
||||
log.Printf("Config: %+v", b.config)
|
||||
log.Println(common.ScrubConfig(b.config), b.config.AccessKey, b.config.SecretKey)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -56,7 +56,7 @@ func (b *Builder) Prepare(raws ...interface{}) error {
|
|||
return errs
|
||||
}
|
||||
|
||||
log.Printf("Config: %+v", b.config)
|
||||
log.Println(common.ScrubConfig(b.config), b.config.AccessKey, b.config.SecretKey)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -159,7 +159,7 @@ func (b *Builder) Prepare(raws ...interface{}) error {
|
|||
return errs
|
||||
}
|
||||
|
||||
log.Printf("Config: %+v", b.config)
|
||||
log.Println(common.ScrubConfig(b.config), b.config.AccessKey, b.config.SecretKey)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,6 @@ import (
|
|||
"github.com/mitchellh/packer/packer"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
@ -165,10 +164,7 @@ func (b *Builder) Prepare(raws ...interface{}) error {
|
|||
return errs
|
||||
}
|
||||
|
||||
configRepr := fmt.Sprintf("Config: %+v", b.config)
|
||||
scrubbedConfig := strings.Replace(configRepr, b.config.ClientID, "CLIENT_ID", -1)
|
||||
scrubbedConfig = strings.Replace(scrubbedConfig, b.config.APIKey, "API_KEY", -1)
|
||||
log.Println(scrubbedConfig)
|
||||
common.ScrubConfig(b.config, b.config.ClientID, b.config.APIKey)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ func (b *Builder) Prepare(raws ...interface{}) error {
|
|||
return errs
|
||||
}
|
||||
|
||||
log.Printf("Config: %+v", b.config)
|
||||
log.Println(common.ScrubConfig(b.config), b.config.Password)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,16 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
// ScrubConfig is a helper that returns a string representation of
|
||||
// any struct with the given values stripped out.
|
||||
func ScrubConfig(target interface{}, values ...string) string {
|
||||
conf := fmt.Sprintf("Config: %+v", target)
|
||||
for _, value := range values {
|
||||
conf = strings.Replace(conf, value, "<Filtered>", -1)
|
||||
}
|
||||
return conf
|
||||
}
|
||||
|
||||
// CheckUnusedConfig is a helper that makes sure that the there are no
|
||||
// unused configuration keys, properly ignoring keys that don't matter.
|
||||
func CheckUnusedConfig(md *mapstructure.Metadata) *packer.MultiError {
|
||||
|
|
|
@ -159,3 +159,20 @@ func TestDownloadableURL_FilePaths(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestScrubConfig(t *testing.T) {
|
||||
type Inner struct {
|
||||
Baz string
|
||||
}
|
||||
type Local struct {
|
||||
Foo string
|
||||
Bar string
|
||||
Inner
|
||||
}
|
||||
c := Local{"foo", "bar", Inner{"bar"}}
|
||||
expect := "Config: {Foo:foo Bar:<Filtered> Inner:{Baz:<Filtered>}}"
|
||||
conf := ScrubConfig(c, c.Bar)
|
||||
if conf != expect {
|
||||
t.Fatalf("got %s, expected %s", conf, expect)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue