Skip to content

Commit

Permalink
Add a way to easily identify a secret setting value
Browse files Browse the repository at this point in the history
this adds a bool field 'IsSecret' to SettingValue struct

we'll use this field to filter out secret config  values
in the o/p of 'crc config view' command
  • Loading branch information
anjannath committed Sep 29, 2022
1 parent f956555 commit 7397181
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cmd/crc/cmd/config/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ func runConfigView(cfg map[string]config.SettingValue, tmpl *template.Template,
if v.IsDefault {
continue
}
if v.IsSecret {
continue
}
viewTmplt := configViewTemplate{k, v.AsString()}
var buffer bytes.Buffer
if err := tmpl.Execute(&buffer, viewTmplt); err != nil {
Expand Down
1 change: 1 addition & 0 deletions pkg/crc/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ func (c *Config) Get(key string) SettingValue {
return SettingValue{
Value: value,
IsDefault: reflect.DeepEqual(setting.defaultValue, value),
IsSecret: isUnderlyingTypeSecret(value),
}
}

Expand Down
3 changes: 3 additions & 0 deletions pkg/crc/config/secret_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func TestGetSecret(t *testing.T) {
assert.Equal(t, SettingValue{
Value: Secret("apples"),
IsDefault: true,
IsSecret: true,
}, cfg.Get(secret))
}

Expand All @@ -49,6 +50,7 @@ func TestSecretConfigSetAndGet(t *testing.T) {
assert.Equal(t, SettingValue{
Value: Secret("pass123"),
IsDefault: false,
IsSecret: true,
}, cfg.Get(password))
}

Expand All @@ -62,5 +64,6 @@ func TestSecretConfigUnsetAndGet(t *testing.T) {
assert.Equal(t, SettingValue{
Value: Secret("apples"),
IsDefault: true,
IsSecret: true,
}, cfg.Get(secret))
}
1 change: 1 addition & 0 deletions pkg/crc/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type SettingValue struct {
Value interface{}
Invalid bool
IsDefault bool
IsSecret bool
}

func (v SettingValue) AsBool() bool {
Expand Down

0 comments on commit 7397181

Please sign in to comment.