github.com/opentofu/opentofu@v1.7.1/internal/lang/funcs/redact.go (about)

     1  // Copyright (c) The OpenTofu Authors
     2  // SPDX-License-Identifier: MPL-2.0
     3  // Copyright (c) 2023 HashiCorp, Inc.
     4  // SPDX-License-Identifier: MPL-2.0
     5  
     6  package funcs
     7  
     8  import (
     9  	"fmt"
    10  
    11  	"github.com/opentofu/opentofu/internal/lang/marks"
    12  	"github.com/zclconf/go-cty/cty"
    13  )
    14  
    15  func redactIfSensitive(value interface{}, markses ...cty.ValueMarks) string {
    16  	if marks.Has(cty.DynamicVal.WithMarks(markses...), marks.Sensitive) {
    17  		return "(sensitive value)"
    18  	}
    19  	switch v := value.(type) {
    20  	case string:
    21  		return fmt.Sprintf("%q", v)
    22  	default:
    23  		return fmt.Sprintf("%v", v)
    24  	}
    25  }