redact sensitive output values in run logs

This commit is contained in:
UKEME BASSEY 2022-09-19 09:02:24 -04:00
parent b54017ef83
commit 7b34e3e743
5 changed files with 7 additions and 6 deletions

View File

@ -246,7 +246,6 @@ func TestApplyJSON_outputs(t *testing.T) {
}, },
"password": map[string]interface{}{ "password": map[string]interface{}{
"sensitive": true, "sensitive": true,
"value": "horse-battery",
"type": "string", "type": "string",
}, },
}, },

View File

@ -42,10 +42,15 @@ func OutputsFromMap(outputValues map[string]*states.OutputValue) (Outputs, tfdia
return nil, diags return nil, diags
} }
var redactedValue json.RawMessage
if !ov.Sensitive {
redactedValue = json.RawMessage(value)
}
outputs[name] = Output{ outputs[name] = Output{
Sensitive: ov.Sensitive, Sensitive: ov.Sensitive,
Type: json.RawMessage(valueType), Type: json.RawMessage(valueType),
Value: json.RawMessage(value), Value: redactedValue,
} }
} }

View File

@ -52,12 +52,10 @@ func TestOutputsFromMap(t *testing.T) {
"beep": { "beep": {
Sensitive: true, Sensitive: true,
Type: json.RawMessage(`"string"`), Type: json.RawMessage(`"string"`),
Value: json.RawMessage(`"horse-battery"`),
}, },
"blorp": { "blorp": {
Sensitive: true, Sensitive: true,
Type: json.RawMessage(`["object",{"a":["object",{"b":["object",{"c":"string"}]}]}]`), Type: json.RawMessage(`["object",{"a":["object",{"b":["object",{"c":"string"}]}]}]`),
Value: json.RawMessage(`{"a":{"b":{"c":"oh, hi"}}}`),
}, },
"honk": { "honk": {
Sensitive: false, Sensitive: false,

View File

@ -13,7 +13,7 @@ import (
// This version describes the schema of JSON UI messages. This version must be // This version describes the schema of JSON UI messages. This version must be
// updated after making any changes to this view, the jsonHook, or any of the // updated after making any changes to this view, the jsonHook, or any of the
// command/views/json package. // command/views/json package.
const JSON_UI_VERSION = "1.0" const JSON_UI_VERSION = "1.1"
func NewJSONView(view *View) *JSONView { func NewJSONView(view *View) *JSONView {
log := hclog.New(&hclog.LoggerOptions{ log := hclog.New(&hclog.LoggerOptions{

View File

@ -98,7 +98,6 @@ func TestRefreshJSON_outputs(t *testing.T) {
}, },
"password": map[string]interface{}{ "password": map[string]interface{}{
"sensitive": true, "sensitive": true,
"value": "horse-battery",
"type": "string", "type": "string",
}, },
}, },