2021-06-23 22:24:58 +02:00
|
|
|
package marks
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
2021-06-25 19:35:17 +02:00
|
|
|
|
|
|
|
"github.com/zclconf/go-cty/cty"
|
2021-06-23 22:24:58 +02:00
|
|
|
)
|
|
|
|
|
2021-06-24 23:53:43 +02:00
|
|
|
// valueMarks allow creating strictly typed values for use as cty.Value marks.
|
|
|
|
// The variable name for new values should be the title-cased format of the
|
|
|
|
// value to better match the GoString output for debugging.
|
2021-06-23 22:24:58 +02:00
|
|
|
type valueMark string
|
|
|
|
|
|
|
|
func (m valueMark) GoString() string {
|
|
|
|
return "marks." + strings.Title(string(m))
|
|
|
|
}
|
|
|
|
|
2021-06-25 19:35:17 +02:00
|
|
|
// Has returns true if and only if the cty.Value has the given mark.
|
|
|
|
func Has(val cty.Value, mark valueMark) bool {
|
|
|
|
return val.HasMark(mark)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Contains returns true if the cty.Value or any any value within it contains
|
|
|
|
// the given mark.
|
|
|
|
func Contains(val cty.Value, mark valueMark) bool {
|
|
|
|
ret := false
|
|
|
|
cty.Walk(val, func(_ cty.Path, v cty.Value) (bool, error) {
|
|
|
|
if v.HasMark(mark) {
|
|
|
|
ret = true
|
|
|
|
return false, nil
|
|
|
|
}
|
|
|
|
return true, nil
|
|
|
|
})
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
2021-06-24 23:53:43 +02:00
|
|
|
// Sensitive indicates that this value is marked as sensitive in the context of
|
|
|
|
// Terraform.
|
2021-06-23 22:24:58 +02:00
|
|
|
var Sensitive = valueMark("sensitive")
|