github.com/khulnasoft-lab/defsec@v1.0.5-0.20230827010352-5e9f46893d95/pkg/scanners/terraform/parser/funcs/marks.go (about) 1 // Copied from github.com/hashicorp/terraform/internal/lang/marks 2 package funcs 3 4 import ( 5 "github.com/zclconf/go-cty/cty" 6 "golang.org/x/text/cases" 7 "golang.org/x/text/language" 8 ) 9 10 // valueMarks allow creating strictly typed values for use as cty.Value marks. 11 // The variable name for new values should be the title-cased format of the 12 // value to better match the GoString output for debugging. 13 type valueMark string 14 15 func (m valueMark) GoString() string { 16 return "marks." + cases.Title(language.English).String(string(m)) 17 } 18 19 // Has returns true if and only if the cty.Value has the given mark. 20 func Has(val cty.Value, mark valueMark) bool { 21 return val.HasMark(mark) 22 } 23 24 // Contains returns true if the cty.Value or any any value within it contains 25 // the given mark. 26 func Contains(val cty.Value, mark valueMark) bool { 27 ret := false 28 _ = cty.Walk(val, func(_ cty.Path, v cty.Value) (bool, error) { 29 if v.HasMark(mark) { 30 ret = true 31 return false, nil 32 } 33 return true, nil 34 }) 35 return ret 36 } 37 38 // MarkedSensitive indicates that this value is marked as sensitive in the context of 39 // Terraform. 40 var MarkedSensitive = valueMark("sensitive") 41 42 // MarkedRaw is used to indicate to the repl that the value should be written without 43 // any formatting. 44 var MarkedRaw = valueMark("raw")