marks.Has and marks.Contains
This commit is contained in:
parent
d9dfd451ea
commit
cdf7469efd
|
@ -2,6 +2,8 @@ package marks
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/zclconf/go-cty/cty"
|
||||||
)
|
)
|
||||||
|
|
||||||
// valueMarks allow creating strictly typed values for use as cty.Value marks.
|
// valueMarks allow creating strictly typed values for use as cty.Value marks.
|
||||||
|
@ -13,6 +15,25 @@ func (m valueMark) GoString() string {
|
||||||
return "marks." + strings.Title(string(m))
|
return "marks." + strings.Title(string(m))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
}
|
||||||
|
|
||||||
// Sensitive indicates that this value is marked as sensitive in the context of
|
// Sensitive indicates that this value is marked as sensitive in the context of
|
||||||
// Terraform.
|
// Terraform.
|
||||||
var Sensitive = valueMark("sensitive")
|
var Sensitive = valueMark("sensitive")
|
||||||
|
|
Loading…
Reference in New Issue