code
stringlengths 11
335k
| docstring
stringlengths 20
11.8k
| func_name
stringlengths 1
100
| language
stringclasses 1
value | repo
stringclasses 245
values | path
stringlengths 4
144
| url
stringlengths 43
214
| license
stringclasses 4
values |
---|---|---|---|---|---|---|---|
func formatStripIndexSegment(rawVerb string) string {
// We assume the string has already been validated here, since we should
// only be using this function with strings that were accepted by our
// scanner in formatFSM.
start := strings.Index(rawVerb, "[")
end := strings.Index(rawVerb, "]")
if start == -1 || end == -1 {
return rawVerb
}
return rawVerb[:start] + rawVerb[end+1:]
} | formatStripIndexSegment strips out any [nnn] segment present in a verb
string so that we can pass it through to Go's fmt.Sprintf with a single
argument. This is used in cases where we're just leaning on Go's formatter
because it's a superset of ours. | formatStripIndexSegment | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/format.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/format.go | MIT |
func CSVDecode(str cty.Value) (cty.Value, error) {
return CSVDecodeFunc.Call([]cty.Value{str})
} | CSVDecode parses the given CSV (RFC 4180) string and, if it is valid,
returns a list of objects representing the rows.
The result is always a list of some object type. The first row of the
input is used to determine the object attributes, and subsequent rows
determine the values of those attributes. | CSVDecode | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/csv.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/csv.go | MIT |
func SetHasElement(set cty.Value, elem cty.Value) (cty.Value, error) {
return SetHasElementFunc.Call([]cty.Value{set, elem})
} | SetHasElement determines whether the given set contains the given value as an
element. | SetHasElement | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/set.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/set.go | MIT |
func SetUnion(sets ...cty.Value) (cty.Value, error) {
return SetUnionFunc.Call(sets)
} | SetUnion returns a new set containing all of the elements from the given
sets, which must have element types that can all be converted to some
common type using the standard type unification rules. If conversion
is not possible, an error is returned.
The union operation is performed after type conversion, which may result
in some previously-distinct values being conflated.
At least one set must be provided. | SetUnion | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/set.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/set.go | MIT |
func SetIntersection(sets ...cty.Value) (cty.Value, error) {
return SetIntersectionFunc.Call(sets)
} | Intersection returns a new set containing the elements that exist
in all of the given sets, which must have element types that can all be
converted to some common type using the standard type unification rules.
If conversion is not possible, an error is returned.
The intersection operation is performed after type conversion, which may
result in some previously-distinct values being conflated.
At least one set must be provided. | SetIntersection | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/set.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/set.go | MIT |
func SetSubtract(a, b cty.Value) (cty.Value, error) {
return SetSubtractFunc.Call([]cty.Value{a, b})
} | SetSubtract returns a new set containing the elements from the
first set that are not present in the second set. The sets must have
element types that can both be converted to some common type using the
standard type unification rules. If conversion is not possible, an error
is returned.
The subtract operation is performed after type conversion, which may
result in some previously-distinct values being conflated. | SetSubtract | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/set.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/set.go | MIT |
func SetSymmetricDifference(sets ...cty.Value) (cty.Value, error) {
return SetSymmetricDifferenceFunc.Call(sets)
} | SetSymmetricDifference returns a new set containing elements that appear
in any of the given sets but not multiple. The sets must have
element types that can all be converted to some common type using the
standard type unification rules. If conversion is not possible, an error
is returned.
The difference operation is performed after type conversion, which may
result in some previously-distinct values being conflated. | SetSymmetricDifference | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/set.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/set.go | MIT |
func BytesVal(buf []byte) cty.Value {
if buf == nil {
panic("can't make Bytes value from nil slice")
}
return cty.CapsuleVal(Bytes, &buf)
} | BytesVal creates a new Bytes value from the given buffer, which must be
non-nil or this function will panic.
Once a byte slice has been wrapped in a Bytes capsule, its underlying array
must be considered immutable. | BytesVal | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/bytes.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/bytes.go | MIT |
func Equal(a cty.Value, b cty.Value) (cty.Value, error) {
return EqualFunc.Call([]cty.Value{a, b})
} | Equal determines whether the two given values are equal, returning a
bool value. | Equal | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/general.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/general.go | MIT |
func Coalesce(vals ...cty.Value) (cty.Value, error) {
return CoalesceFunc.Call(vals)
} | Coalesce returns the first of the given arguments that is not null. If
all arguments are null, an error is produced. | Coalesce | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/general.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/general.go | MIT |
func Replace(str, substr, replace cty.Value) (cty.Value, error) {
return ReplaceFunc.Call([]cty.Value{str, substr, replace})
} | Replace searches a given string for another given substring,
and replaces all occurrences with a given replacement string. | Replace | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/string_replace.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/string_replace.go | MIT |
func FormatDate(format cty.Value, timestamp cty.Value) (cty.Value, error) {
return FormatDateFunc.Call([]cty.Value{format, timestamp})
} | FormatDate reformats a timestamp given in RFC3339 syntax into another time
syntax defined by a given format string.
The format string uses letter mnemonics to represent portions of the
timestamp, with repetition signifying length variants of each portion.
Single quote characters ' can be used to quote sequences of literal letters
that should not be interpreted as formatting mnemonics.
The full set of supported mnemonic sequences is listed below:
YY Year modulo 100 zero-padded to two digits, like "06".
YYYY Four (or more) digit year, like "2006".
M Month number, like "1" for January.
MM Month number zero-padded to two digits, like "01".
MMM English month name abbreviated to three letters, like "Jan".
MMMM English month name unabbreviated, like "January".
D Day of month number, like "2".
DD Day of month number zero-padded to two digits, like "02".
EEE English day of week name abbreviated to three letters, like "Mon".
EEEE English day of week name unabbreviated, like "Monday".
h 24-hour number, like "2".
hh 24-hour number zero-padded to two digits, like "02".
H 12-hour number, like "2".
HH 12-hour number zero-padded to two digits, like "02".
AA Hour AM/PM marker in uppercase, like "AM".
aa Hour AM/PM marker in lowercase, like "am".
m Minute within hour, like "5".
mm Minute within hour zero-padded to two digits, like "05".
s Second within minute, like "9".
ss Second within minute zero-padded to two digits, like "09".
ZZZZ Timezone offset with just sign and digit, like "-0800".
ZZZZZ Timezone offset with colon separating hours and minutes, like "-08:00".
Z Like ZZZZZ but with a special case "Z" for UTC.
ZZZ Like ZZZZ but with a special case "UTC" for UTC.
The format syntax is optimized mainly for generating machine-oriented
timestamps rather than human-oriented timestamps; the English language
portions of the output reflect the use of English names in a number of
machine-readable date formatting standards. For presentation to humans,
a locale-aware time formatter (not included in this package) is a better
choice.
The format syntax is not compatible with that of any other language, but
is optimized so that patterns for common standard date formats can be
recognized quickly even by a reader unfamiliar with the format syntax. | FormatDate | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/datetime.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/datetime.go | MIT |
func splitDateFormat(data []byte, atEOF bool) (advance int, token []byte, err error) {
if len(data) == 0 {
return 0, nil, nil
}
const esc = '\''
switch {
case data[0] == esc:
// If we have another quote immediately after then this is a single
// escaped escape.
if len(data) > 1 && data[1] == esc {
return 2, data[:2], nil
}
// Beginning of quoted sequence, so we will seek forward until we find
// the closing quote, ignoring escaped quotes along the way.
for i := 1; i < len(data); i++ {
if data[i] == esc {
if (i + 1) == len(data) {
if atEOF {
// We have a closing quote and are at the end of our input
return len(data), data, nil
} else {
// We need at least one more byte to decide if this is an
// escape or a terminator.
return 0, nil, nil
}
}
if data[i+1] == esc {
i++ // doubled-up quotes are an escape sequence
continue
}
// We've found the closing quote
return i + 1, data[:i+1], nil
}
}
// If we fall out here then we need more bytes to find the end,
// unless we're already at the end with an unclosed quote.
if atEOF {
return len(data), data, nil
}
return 0, nil, nil
case startsDateFormatVerb(data[0]):
rep := data[0]
for i := 1; i < len(data); i++ {
if data[i] != rep {
return i, data[:i], nil
}
}
if atEOF {
return len(data), data, nil
}
// We need more data to decide if we've found the end
return 0, nil, nil
default:
for i := 1; i < len(data); i++ {
if data[i] == esc || startsDateFormatVerb(data[i]) {
return i, data[:i], nil
}
}
// We might not actually be at the end of a literal sequence,
// but that doesn't matter since we'll concat them back together
// anyway.
return len(data), data, nil
}
} | splitDataFormat is a bufio.SplitFunc used to tokenize a date format. | splitDateFormat | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/datetime.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/datetime.go | MIT |
func TimeAdd(timestamp cty.Value, duration cty.Value) (cty.Value, error) {
return TimeAddFunc.Call([]cty.Value{timestamp, duration})
} | TimeAdd adds a duration to a timestamp, returning a new timestamp.
In the HCL language, timestamps are conventionally represented as
strings using RFC 3339 "Date and Time format" syntax. Timeadd requires
the timestamp argument to be a string conforming to this syntax.
`duration` is a string representation of a time difference, consisting of
sequences of number and unit pairs, like `"1.5h"` or `1h30m`. The accepted
units are `ns`, `us` (or `µs`), `"ms"`, `"s"`, `"m"`, and `"h"`. The first
number may be negative to indicate a negative duration, like `"-2h5m"`.
The result is a string, also in RFC 3339 format, representing the result
of adding the given direction to the given timestamp. | TimeAdd | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/datetime.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/datetime.go | MIT |
func MakeToFunc(wantTy cty.Type) function.Function {
return function.New(&function.Spec{
Description: fmt.Sprintf("Converts the given value to %s, or raises an error if that conversion is impossible.", wantTy.FriendlyName()),
Params: []function.Parameter{
{
Name: "v",
// We use DynamicPseudoType rather than wantTy here so that
// all values will pass through the function API verbatim and
// we can handle the conversion logic within the Type and
// Impl functions. This allows us to customize the error
// messages to be more appropriate for an explicit type
// conversion, whereas the cty function system produces
// messages aimed at _implicit_ type conversions.
Type: cty.DynamicPseudoType,
AllowNull: true,
AllowDynamicType: true,
},
},
Type: func(args []cty.Value) (cty.Type, error) {
gotTy := args[0].Type()
if gotTy.Equals(wantTy) {
return wantTy, nil
}
conv := convert.GetConversionUnsafe(args[0].Type(), wantTy)
if conv == nil {
// We'll use some specialized errors for some trickier cases,
// but most we can handle in a simple way.
switch {
case gotTy.IsTupleType() && wantTy.IsTupleType():
return cty.NilType, function.NewArgErrorf(0, "incompatible tuple type for conversion: %s", convert.MismatchMessage(gotTy, wantTy))
case gotTy.IsObjectType() && wantTy.IsObjectType():
return cty.NilType, function.NewArgErrorf(0, "incompatible object type for conversion: %s", convert.MismatchMessage(gotTy, wantTy))
default:
return cty.NilType, function.NewArgErrorf(0, "cannot convert %s to %s", gotTy.FriendlyName(), wantTy.FriendlyNameForConstraint())
}
}
// If a conversion is available then everything is fine.
return wantTy, nil
},
Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) {
// We didn't set "AllowUnknown" on our argument, so it is guaranteed
// to be known here but may still be null.
ret, err := convert.Convert(args[0], retType)
if err != nil {
// Because we used GetConversionUnsafe above, conversion can
// still potentially fail in here. For example, if the user
// asks to convert the string "a" to bool then we'll
// optimistically permit it during type checking but fail here
// once we note that the value isn't either "true" or "false".
gotTy := args[0].Type()
switch {
case gotTy == cty.String && wantTy == cty.Bool:
what := "string"
if !args[0].IsNull() {
what = strconv.Quote(args[0].AsString())
}
return cty.NilVal, function.NewArgErrorf(0, `cannot convert %s to bool; only the strings "true" or "false" are allowed`, what)
case gotTy == cty.String && wantTy == cty.Number:
what := "string"
if !args[0].IsNull() {
what = strconv.Quote(args[0].AsString())
}
return cty.NilVal, function.NewArgErrorf(0, `cannot convert %s to number; given string must be a decimal representation of a number`, what)
default:
return cty.NilVal, function.NewArgErrorf(0, "cannot convert %s to %s", gotTy.FriendlyName(), wantTy.FriendlyNameForConstraint())
}
}
return ret, nil
},
})
} | MakeToFunc constructs a "to..." function, like "tostring", which converts
its argument to a specific type or type kind.
The given type wantTy can be any type constraint that cty's "convert" package
would accept. In particular, this means that you can pass
cty.List(cty.DynamicPseudoType) to mean "list of any single type", which
will then cause cty to attempt to unify all of the element types when given
a tuple. | MakeToFunc | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/conversion.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/conversion.go | MIT |
func JSONEncode(val cty.Value) (cty.Value, error) {
return JSONEncodeFunc.Call([]cty.Value{val})
} | JSONEncode returns a JSON serialization of the given value. | JSONEncode | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/json.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/json.go | MIT |
func JSONDecode(str cty.Value) (cty.Value, error) {
return JSONDecodeFunc.Call([]cty.Value{str})
} | JSONDecode parses the given JSON string and, if it is valid, returns the
value it represents.
Note that applying JSONDecode to the result of JSONEncode may not produce
an identically-typed result, since JSON encoding is lossy for cty Types.
The resulting value will consist only of primitive types, object types, and
tuple types. | JSONDecode | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/json.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/json.go | MIT |
func Not(num cty.Value) (cty.Value, error) {
return NotFunc.Call([]cty.Value{num})
} | Not returns the logical complement of the given boolean value. | Not | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/bool.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/bool.go | MIT |
func And(a, b cty.Value) (cty.Value, error) {
return AndFunc.Call([]cty.Value{a, b})
} | And returns true if and only if both of the given boolean values are true. | And | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/bool.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/bool.go | MIT |
func Or(a, b cty.Value) (cty.Value, error) {
return OrFunc.Call([]cty.Value{a, b})
} | Or returns true if either of the given boolean values are true. | Or | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/bool.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/bool.go | MIT |
func Regex(pattern, str cty.Value) (cty.Value, error) {
return RegexFunc.Call([]cty.Value{pattern, str})
} | Regex is a function that extracts one or more substrings from a given
string by applying a regular expression pattern, describing the first
match.
The return type depends on the composition of the capture groups (if any)
in the pattern:
- If there are no capture groups at all, the result is a single string
representing the entire matched pattern.
- If all of the capture groups are named, the result is an object whose
keys are the named groups and whose values are their sub-matches, or
null if a particular sub-group was inside another group that didn't
match.
- If none of the capture groups are named, the result is a tuple whose
elements are the sub-groups in order and whose values are their
sub-matches, or null if a particular sub-group was inside another group
that didn't match.
- It is invalid to use both named and un-named capture groups together in
the same pattern.
If the pattern doesn't match, this function returns an error. To test for
a match, call RegexAll and check if the length of the result is greater
than zero. | Regex | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/regexp.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/regexp.go | MIT |
func RegexAll(pattern, str cty.Value) (cty.Value, error) {
return RegexAllFunc.Call([]cty.Value{pattern, str})
} | RegexAll is similar to Regex but it finds all of the non-overlapping matches
in the given string and returns a list of them.
The result type is always a list, whose element type is deduced from the
pattern in the same way as the return type for Regex is decided.
If the pattern doesn't match at all, this function returns an empty list. | RegexAll | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/regexp.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/regexp.go | MIT |
func regexPatternResultType(pattern string) (cty.Type, error) {
re, rawErr := regexp.Compile(pattern)
switch err := rawErr.(type) {
case *resyntax.Error:
return cty.NilType, fmt.Errorf("invalid regexp pattern: %s in %s", err.Code, err.Expr)
case error:
// Should never happen, since all regexp compile errors should
// be resyntax.Error, but just in case...
return cty.NilType, fmt.Errorf("error parsing pattern: %s", err)
} | regexPatternResultType parses the given regular expression pattern and
returns the structural type that would be returned to represent its
capture groups.
Returns an error if parsing fails or if the pattern uses a mixture of
named and unnamed capture groups, which is not permitted. | regexPatternResultType | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/regexp.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/regexp.go | MIT |
func Concat(seqs ...cty.Value) (cty.Value, error) {
return ConcatFunc.Call(seqs)
} | Concat takes one or more sequences (lists or tuples) and returns the single
sequence that results from concatenating them together in order.
If all of the given sequences are lists of the same element type then the
result is a list of that type. Otherwise, the result is a of a tuple type
constructed from the given sequence types. | Concat | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/sequence.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/sequence.go | MIT |
func Range(params ...cty.Value) (cty.Value, error) {
return RangeFunc.Call(params)
} | Range creates a list of numbers by starting from the given starting value,
then adding the given step value until the result is greater than or
equal to the given stopping value. Each intermediate result becomes an
element in the resulting list.
When all three parameters are set, the order is (start, end, step). If
only two parameters are set, they are the start and end respectively and
step defaults to 1. If only one argument is set, it gives the end value
with start defaulting to 0 and step defaulting to 1.
Because the resulting list must be fully buffered in memory, there is an
artificial cap of 1024 elements, after which this function will return
an error to avoid consuming unbounded amounts of memory. The Range function
is primarily intended for creating small lists of indices to iterate over,
so there should be no reason to generate huge lists with it. | Range | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/sequence.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/sequence.go | MIT |
func flattener(flattenList cty.Value) ([]cty.Value, []cty.ValueMarks, bool) {
var markses []cty.ValueMarks
flattenList, flattenListMarks := flattenList.Unmark()
if len(flattenListMarks) > 0 {
markses = append(markses, flattenListMarks)
}
if !flattenList.Length().IsKnown() {
// If we don't know the length of what we're flattening then we can't
// predict the length of our result yet either.
return nil, markses, false
}
out := make([]cty.Value, 0)
isKnown := true
for it := flattenList.ElementIterator(); it.Next(); {
_, val := it.Element()
// Any dynamic types could result in more collections that need to be
// flattened, so the type cannot be known.
if val == cty.DynamicVal {
isKnown = false
}
if !val.IsNull() && (val.Type().IsListType() || val.Type().IsSetType() || val.Type().IsTupleType()) {
if !val.IsKnown() {
isKnown = false
_, unknownMarks := val.Unmark()
markses = append(markses, unknownMarks)
continue
}
res, resMarks, known := flattener(val)
markses = append(markses, resMarks...)
if known {
out = append(out, res...)
} else {
isKnown = false
}
} else {
out = append(out, val)
}
}
return out, markses, isKnown
} | Flatten until it's not a cty.List, and return whether the value is known.
We can flatten lists with unknown values, as long as they are not
lists themselves. | flattener | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/collection.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/collection.go | MIT |
func appendIfMissing(slice []cty.Value, element cty.Value) ([]cty.Value, error) {
for _, ele := range slice {
eq, err := Equal(ele, element)
if err != nil {
return slice, err
}
if eq.True() {
return slice, nil
}
}
return append(slice, element), nil
} | helper function to add an element to a list, if it does not already exist | appendIfMissing | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/collection.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/collection.go | MIT |
func HasIndex(collection cty.Value, key cty.Value) (cty.Value, error) {
return HasIndexFunc.Call([]cty.Value{collection, key})
} | HasIndex determines whether the given collection can be indexed with the
given key. | HasIndex | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/collection.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/collection.go | MIT |
func Index(collection cty.Value, key cty.Value) (cty.Value, error) {
return IndexFunc.Call([]cty.Value{collection, key})
} | Index returns an element from the given collection using the given key,
or returns an error if there is no element for the given key. | Index | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/collection.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/collection.go | MIT |
func Length(collection cty.Value) (cty.Value, error) {
return LengthFunc.Call([]cty.Value{collection})
} | Length returns the number of elements in the given collection. | Length | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/collection.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/collection.go | MIT |
func Element(list, index cty.Value) (cty.Value, error) {
return ElementFunc.Call([]cty.Value{list, index})
} | Element returns a single element from a given list at the given index. If
index is greater than the length of the list then it is wrapped modulo
the list length. | Element | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/collection.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/collection.go | MIT |
func CoalesceList(args ...cty.Value) (cty.Value, error) {
return CoalesceListFunc.Call(args)
} | CoalesceList takes any number of list arguments and returns the first one that isn't empty. | CoalesceList | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/collection.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/collection.go | MIT |
func Compact(list cty.Value) (cty.Value, error) {
return CompactFunc.Call([]cty.Value{list})
} | Compact takes a list of strings and returns a new list
with any empty string elements removed. | Compact | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/collection.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/collection.go | MIT |
func Contains(list, value cty.Value) (cty.Value, error) {
return ContainsFunc.Call([]cty.Value{list, value})
} | Contains determines whether a given list contains a given single value
as one of its elements. | Contains | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/collection.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/collection.go | MIT |
func Distinct(list cty.Value) (cty.Value, error) {
return DistinctFunc.Call([]cty.Value{list})
} | Distinct takes a list and returns a new list with any duplicate elements removed. | Distinct | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/collection.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/collection.go | MIT |
func Chunklist(list, size cty.Value) (cty.Value, error) {
return ChunklistFunc.Call([]cty.Value{list, size})
} | Chunklist splits a single list into fixed-size chunks, returning a list of lists. | Chunklist | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/collection.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/collection.go | MIT |
func Flatten(list cty.Value) (cty.Value, error) {
return FlattenFunc.Call([]cty.Value{list})
} | Flatten takes a list and replaces any elements that are lists with a flattened
sequence of the list contents. | Flatten | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/collection.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/collection.go | MIT |
func Keys(inputMap cty.Value) (cty.Value, error) {
return KeysFunc.Call([]cty.Value{inputMap})
} | Keys takes a map and returns a sorted list of the map keys. | Keys | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/collection.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/collection.go | MIT |
func Lookup(inputMap, key, defaultValue cty.Value) (cty.Value, error) {
return LookupFunc.Call([]cty.Value{inputMap, key, defaultValue})
} | Lookup performs a dynamic lookup into a map.
There are three required arguments, inputMap and key, plus a defaultValue,
which is a value to return if the given key is not found in the inputMap. | Lookup | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/collection.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/collection.go | MIT |
func Merge(maps ...cty.Value) (cty.Value, error) {
return MergeFunc.Call(maps)
} | Merge takes an arbitrary number of maps and returns a single map that contains
a merged set of elements from all of the maps.
If more than one given map defines the same key then the one that is later in
the argument sequence takes precedence. | Merge | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/collection.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/collection.go | MIT |
func ReverseList(list cty.Value) (cty.Value, error) {
return ReverseListFunc.Call([]cty.Value{list})
} | ReverseList takes a sequence and produces a new sequence of the same length
with all of the same elements as the given sequence but in reverse order. | ReverseList | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/collection.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/collection.go | MIT |
func SetProduct(sets ...cty.Value) (cty.Value, error) {
return SetProductFunc.Call(sets)
} | SetProduct computes the Cartesian product of sets or sequences. | SetProduct | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/collection.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/collection.go | MIT |
func Slice(list, start, end cty.Value) (cty.Value, error) {
return SliceFunc.Call([]cty.Value{list, start, end})
} | Slice extracts some consecutive elements from within a list. | Slice | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/collection.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/collection.go | MIT |
func Values(values cty.Value) (cty.Value, error) {
return ValuesFunc.Call([]cty.Value{values})
} | Values returns a list of the map values, in the order of the sorted keys.
This function only works on flat maps. | Values | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/collection.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/collection.go | MIT |
func Zipmap(keys, values cty.Value) (cty.Value, error) {
return ZipmapFunc.Call([]cty.Value{keys, values})
} | Zipmap constructs a map from a list of keys and a corresponding list of values. | Zipmap | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/collection.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/collection.go | MIT |
func Absolute(num cty.Value) (cty.Value, error) {
return AbsoluteFunc.Call([]cty.Value{num})
} | Absolute returns the magnitude of the given number, without its sign.
That is, it turns negative values into positive values. | Absolute | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/number.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/number.go | MIT |
func Add(a cty.Value, b cty.Value) (cty.Value, error) {
return AddFunc.Call([]cty.Value{a, b})
} | Add returns the sum of the two given numbers. | Add | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/number.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/number.go | MIT |
func Subtract(a cty.Value, b cty.Value) (cty.Value, error) {
return SubtractFunc.Call([]cty.Value{a, b})
} | Subtract returns the difference between the two given numbers. | Subtract | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/number.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/number.go | MIT |
func Multiply(a cty.Value, b cty.Value) (cty.Value, error) {
return MultiplyFunc.Call([]cty.Value{a, b})
} | Multiply returns the product of the two given numbers. | Multiply | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/number.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/number.go | MIT |
func Divide(a cty.Value, b cty.Value) (cty.Value, error) {
return DivideFunc.Call([]cty.Value{a, b})
} | Divide returns a divided by b, where both a and b are numbers. | Divide | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/number.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/number.go | MIT |
func Negate(num cty.Value) (cty.Value, error) {
return NegateFunc.Call([]cty.Value{num})
} | Negate returns the given number multipled by -1. | Negate | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/number.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/number.go | MIT |
func LessThan(a cty.Value, b cty.Value) (cty.Value, error) {
return LessThanFunc.Call([]cty.Value{a, b})
} | LessThan returns true if a is less than b. | LessThan | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/number.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/number.go | MIT |
func LessThanOrEqualTo(a cty.Value, b cty.Value) (cty.Value, error) {
return LessThanOrEqualToFunc.Call([]cty.Value{a, b})
} | LessThanOrEqualTo returns true if a is less than b. | LessThanOrEqualTo | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/number.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/number.go | MIT |
func GreaterThan(a cty.Value, b cty.Value) (cty.Value, error) {
return GreaterThanFunc.Call([]cty.Value{a, b})
} | GreaterThan returns true if a is less than b. | GreaterThan | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/number.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/number.go | MIT |
func GreaterThanOrEqualTo(a cty.Value, b cty.Value) (cty.Value, error) {
return GreaterThanOrEqualToFunc.Call([]cty.Value{a, b})
} | GreaterThanOrEqualTo returns true if a is less than b. | GreaterThanOrEqualTo | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/number.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/number.go | MIT |
func Modulo(a cty.Value, b cty.Value) (cty.Value, error) {
return ModuloFunc.Call([]cty.Value{a, b})
} | Modulo returns the remainder of a divided by b under integer division,
where both a and b are numbers. | Modulo | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/number.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/number.go | MIT |
func Min(numbers ...cty.Value) (cty.Value, error) {
return MinFunc.Call(numbers)
} | Min returns the minimum number from the given numbers. | Min | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/number.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/number.go | MIT |
func Max(numbers ...cty.Value) (cty.Value, error) {
return MaxFunc.Call(numbers)
} | Max returns the maximum number from the given numbers. | Max | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/number.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/number.go | MIT |
func Int(num cty.Value) (cty.Value, error) {
if num == cty.PositiveInfinity || num == cty.NegativeInfinity {
return cty.NilVal, fmt.Errorf("can't truncate infinity to an integer")
}
return IntFunc.Call([]cty.Value{num})
} | Int removes the fractional component of the given number returning an
integer representing the whole number component, rounding towards zero.
For example, -1.5 becomes -1.
If an infinity is passed to Int, an error is returned. | Int | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/number.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/number.go | MIT |
func Ceil(num cty.Value) (cty.Value, error) {
return CeilFunc.Call([]cty.Value{num})
} | Ceil returns the closest whole number greater than or equal to the given value. | Ceil | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/number.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/number.go | MIT |
func Floor(num cty.Value) (cty.Value, error) {
return FloorFunc.Call([]cty.Value{num})
} | Floor returns the closest whole number lesser than or equal to the given value. | Floor | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/number.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/number.go | MIT |
func Log(num, base cty.Value) (cty.Value, error) {
return LogFunc.Call([]cty.Value{num, base})
} | Log returns returns the logarithm of a given number in a given base. | Log | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/number.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/number.go | MIT |
func Pow(num, power cty.Value) (cty.Value, error) {
return PowFunc.Call([]cty.Value{num, power})
} | Pow returns the logarithm of a given number in a given base. | Pow | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/number.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/number.go | MIT |
func Signum(num cty.Value) (cty.Value, error) {
return SignumFunc.Call([]cty.Value{num})
} | Signum determines the sign of a number, returning a number between -1 and
1 to represent the sign. | Signum | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/number.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/number.go | MIT |
func ParseInt(num cty.Value, base cty.Value) (cty.Value, error) {
return ParseIntFunc.Call([]cty.Value{num, base})
} | ParseInt parses a string argument and returns an integer of the specified base. | ParseInt | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/number.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/number.go | MIT |
func Upper(str cty.Value) (cty.Value, error) {
return UpperFunc.Call([]cty.Value{str})
} | Upper is a Function that converts a given string to uppercase. | Upper | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/string.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/string.go | MIT |
func Lower(str cty.Value) (cty.Value, error) {
return LowerFunc.Call([]cty.Value{str})
} | Lower is a Function that converts a given string to lowercase. | Lower | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/string.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/string.go | MIT |
func Reverse(str cty.Value) (cty.Value, error) {
return ReverseFunc.Call([]cty.Value{str})
} | Reverse is a Function that reverses the order of the characters in the
given string.
As usual, "character" for the sake of this function is a grapheme cluster,
so combining diacritics (for example) will be considered together as a
single character. | Reverse | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/string.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/string.go | MIT |
func Strlen(str cty.Value) (cty.Value, error) {
return StrlenFunc.Call([]cty.Value{str})
} | Strlen is a Function that returns the length of the given string in
characters.
As usual, "character" for the sake of this function is a grapheme cluster,
so combining diacritics (for example) will be considered together as a
single character. | Strlen | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/string.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/string.go | MIT |
func Substr(str cty.Value, offset cty.Value, length cty.Value) (cty.Value, error) {
return SubstrFunc.Call([]cty.Value{str, offset, length})
} | Substr is a Function that extracts a sequence of characters from another
string and creates a new string.
As usual, "character" for the sake of this function is a grapheme cluster,
so combining diacritics (for example) will be considered together as a
single character.
The "offset" index may be negative, in which case it is relative to the
end of the given string.
The "length" may be -1, in which case the remainder of the string after
the given offset will be returned. | Substr | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/string.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/string.go | MIT |
func Join(sep cty.Value, lists ...cty.Value) (cty.Value, error) {
args := make([]cty.Value, len(lists)+1)
args[0] = sep
copy(args[1:], lists)
return JoinFunc.Call(args)
} | Join concatenates together the string elements of one or more lists with a
given separator. | Join | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/string.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/string.go | MIT |
func Sort(list cty.Value) (cty.Value, error) {
return SortFunc.Call([]cty.Value{list})
} | Sort re-orders the elements of a given list of strings so that they are
in ascending lexicographical order. | Sort | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/string.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/string.go | MIT |
func Split(sep, str cty.Value) (cty.Value, error) {
return SplitFunc.Call([]cty.Value{sep, str})
} | Split divides a given string by a given separator, returning a list of
strings containing the characters between the separator sequences. | Split | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/string.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/string.go | MIT |
func Chomp(str cty.Value) (cty.Value, error) {
return ChompFunc.Call([]cty.Value{str})
} | Chomp removes newline characters at the end of a string. | Chomp | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/string.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/string.go | MIT |
func Indent(spaces, str cty.Value) (cty.Value, error) {
return IndentFunc.Call([]cty.Value{spaces, str})
} | Indent adds a given number of spaces to the beginnings of all but the first
line in a given multi-line string. | Indent | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/string.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/string.go | MIT |
func Title(str cty.Value) (cty.Value, error) {
return TitleFunc.Call([]cty.Value{str})
} | Title converts the first letter of each word in the given string to uppercase. | Title | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/string.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/string.go | MIT |
func TrimSpace(str cty.Value) (cty.Value, error) {
return TrimSpaceFunc.Call([]cty.Value{str})
} | TrimSpace removes any space characters from the start and end of the given string. | TrimSpace | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/string.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/string.go | MIT |
func Trim(str, cutset cty.Value) (cty.Value, error) {
return TrimFunc.Call([]cty.Value{str, cutset})
} | Trim removes the specified characters from the start and end of the given string. | Trim | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/string.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/string.go | MIT |
func TrimPrefix(str, prefix cty.Value) (cty.Value, error) {
return TrimPrefixFunc.Call([]cty.Value{str, prefix})
} | TrimPrefix removes the specified prefix from the start of the given string. | TrimPrefix | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/string.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/string.go | MIT |
func TrimSuffix(str, suffix cty.Value) (cty.Value, error) {
return TrimSuffixFunc.Call([]cty.Value{str, suffix})
} | TrimSuffix removes the specified suffix from the end of the given string. | TrimSuffix | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/function/stdlib/string.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/function/stdlib/string.go | MIT |
func GetConversion(in cty.Type, out cty.Type) Conversion {
return retConversion(getConversion(in, out, false))
} | GetConversion returns a Conversion between the given in and out Types if
a safe one is available, or returns nil otherwise. | GetConversion | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/convert/public.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/convert/public.go | MIT |
func GetConversionUnsafe(in cty.Type, out cty.Type) Conversion {
return retConversion(getConversion(in, out, true))
} | GetConversionUnsafe returns a Conversion between the given in and out Types
if either a safe or unsafe one is available, or returns nil otherwise. | GetConversionUnsafe | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/convert/public.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/convert/public.go | MIT |
func Convert(in cty.Value, want cty.Type) (cty.Value, error) {
if in.Type().Equals(want.WithoutOptionalAttributesDeep()) {
return in, nil
}
conv := GetConversionUnsafe(in.Type(), want)
if conv == nil {
return cty.NilVal, errors.New(MismatchMessage(in.Type(), want))
}
return conv(in)
} | Convert returns the result of converting the given value to the given type
if an safe or unsafe conversion is available, or returns an error if such a
conversion is impossible.
This is a convenience wrapper around calling GetConversionUnsafe and then
immediately passing the given value to the resulting function. | Convert | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/convert/public.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/convert/public.go | MIT |
func Unify(types []cty.Type) (cty.Type, []Conversion) {
return unify(types, false)
} | Unify attempts to find the most general type that can be converted from
all of the given types. If this is possible, that type is returned along
with a slice of necessary conversions for some of the given types.
If no common supertype can be found, this function returns cty.NilType and
a nil slice.
If a common supertype *can* be found, the returned slice will always be
non-nil and will contain a non-nil conversion for each given type that
needs to be converted, with indices corresponding to the input slice.
Any given type that does *not* need conversion (because it is already of
the appropriate type) will have a nil Conversion.
cty.DynamicPseudoType is, as usual, a special case. If the given type list
contains a mixture of dynamic and non-dynamic types, the dynamic types are
disregarded for type selection and a conversion is returned for them that
will attempt a late conversion of the given value to the target type,
failing with a conversion error if the eventual concrete type is not
compatible. If *all* given types are DynamicPseudoType, or in the
degenerate case of an empty slice of types, the returned type is itself
cty.DynamicPseudoType and no conversions are attempted. | Unify | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/convert/public.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/convert/public.go | MIT |
func UnifyUnsafe(types []cty.Type) (cty.Type, []Conversion) {
return unify(types, true)
} | UnifyUnsafe is the same as Unify except that it may return unsafe
conversions in situations where a safe conversion isn't also available. | UnifyUnsafe | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/convert/public.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/convert/public.go | MIT |
func MismatchMessage(got, want cty.Type) string {
switch {
case got.IsObjectType() && want.IsObjectType():
// If both types are object types then we may be able to say something
// about their respective attributes.
return mismatchMessageObjects(got, want)
case got.IsTupleType() && want.IsListType() && want.ElementType() == cty.DynamicPseudoType:
// If conversion from tuple to list failed then it's because we couldn't
// find a common type to convert all of the tuple elements to.
return "all list elements must have the same type"
case got.IsTupleType() && want.IsSetType() && want.ElementType() == cty.DynamicPseudoType:
// If conversion from tuple to set failed then it's because we couldn't
// find a common type to convert all of the tuple elements to.
return "all set elements must have the same type"
case got.IsObjectType() && want.IsMapType() && want.ElementType() == cty.DynamicPseudoType:
// If conversion from object to map failed then it's because we couldn't
// find a common type to convert all of the object attributes to.
return "all map elements must have the same type"
case (got.IsTupleType() || got.IsObjectType()) && want.IsCollectionType():
return mismatchMessageCollectionsFromStructural(got, want)
case got.IsCollectionType() && want.IsCollectionType():
return mismatchMessageCollectionsFromCollections(got, want)
default:
// If we have nothing better to say, we'll just state what was required.
return want.FriendlyNameForConstraint() + " required"
}
} | MismatchMessage is a helper to return an English-language description of
the differences between got and want, phrased as a reason why got does
not conform to want.
This function does not itself attempt conversion, and so it should generally
be used only after a conversion has failed, to report the conversion failure
to an English-speaking user. The result will be confusing got is actually
conforming to or convertable to want.
The shorthand helper function Convert uses this function internally to
produce its error messages, so callers of that function do not need to
also use MismatchMessage.
This function is similar to Type.TestConformance, but it is tailored to
describing conversion failures and so the messages it generates relate
specifically to the conversion rules implemented in this package. | MismatchMessage | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/convert/mismatch_msg.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/convert/mismatch_msg.go | MIT |
func conversionTupleToTuple(in, out cty.Type, unsafe bool) conversion {
inEtys := in.TupleElementTypes()
outEtys := out.TupleElementTypes()
if len(inEtys) != len(outEtys) {
return nil // no conversion is possible
}
elemConvs := make([]conversion, len(inEtys))
for i, outEty := range outEtys {
inEty := inEtys[i]
if inEty.Equals(outEty) {
// No conversion needed, so we can leave this one nil.
continue
}
elemConvs[i] = getConversion(inEty, outEty, unsafe)
if elemConvs[i] == nil {
// If a recursive conversion isn't available, then our top-level
// configuration is impossible too.
return nil
}
}
// If we get here then a conversion is possible, using the element
// conversions given in elemConvs.
return func(val cty.Value, path cty.Path) (cty.Value, error) {
elemVals := make([]cty.Value, len(elemConvs))
path = append(path, nil)
pathStep := &path[len(path)-1]
i := 0
for it := val.ElementIterator(); it.Next(); i++ {
_, val := it.Element()
var err error
*pathStep = cty.IndexStep{
Key: cty.NumberIntVal(int64(i)),
}
conv := elemConvs[i]
if conv != nil {
val, err = conv(val, path)
if err != nil {
return cty.NilVal, err
}
}
elemVals[i] = val
}
return cty.TupleVal(elemVals), nil
}
} | conversionTupleToTuple returns a conversion that will make the input
tuple type conform to the output tuple type, if possible.
Conversion is possible only if the two tuple types have the same number
of elements and the corresponding elements by index can be converted.
Shallow tuple conversions work the same for both safe and unsafe modes,
but the safety flag is passed on to recursive conversions and may thus
limit which element type conversions are possible. | conversionTupleToTuple | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/convert/conversion_tuple.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/convert/conversion_tuple.go | MIT |
func retConversion(conv conversion) Conversion {
if conv == nil {
return nil
}
return func(in cty.Value) (cty.Value, error) {
return conv(in, cty.Path(nil))
}
} | retConversion wraps a conversion (internal type) so it can be returned
as a Conversion (public type). | retConversion | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/convert/conversion.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/convert/conversion.go | MIT |
func prepareUnknownResult(sourceRange cty.ValueRange, targetTy cty.Type) cty.Value {
sourceTy := sourceRange.TypeConstraint()
ret := cty.UnknownVal(targetTy)
if sourceRange.DefinitelyNotNull() {
ret = ret.RefineNotNull()
}
switch {
case sourceTy.IsObjectType() && targetTy.IsMapType():
// A map built from an object type always has the same number of
// elements as the source type has attributes.
return ret.Refine().CollectionLength(len(sourceTy.AttributeTypes())).NewValue()
case sourceTy.IsTupleType() && targetTy.IsListType():
// A list built from a typle type always has the same number of
// elements as the source type has elements.
return ret.Refine().CollectionLength(sourceTy.Length()).NewValue()
case sourceTy.IsTupleType() && targetTy.IsSetType():
// When building a set from a tuple type we can't exactly constrain
// the length because some elements might coalesce, but we can
// guarantee an upper limit. We can also guarantee at least one
// element if the tuple isn't empty.
switch l := sourceTy.Length(); l {
case 0, 1:
return ret.Refine().CollectionLength(l).NewValue()
default:
return ret.Refine().
CollectionLengthLowerBound(1).
CollectionLengthUpperBound(sourceTy.Length()).
NewValue()
}
case sourceTy.IsCollectionType() && targetTy.IsCollectionType():
// NOTE: We only reach this function if there is an available
// conversion between the source and target type, so we don't
// need to repeat element type compatibility checks and such here.
//
// If the source value already has a refined length then we'll
// transfer those refinements to the result, because conversion
// does not change length (aside from set element coalescing).
b := ret.Refine()
if targetTy.IsSetType() {
if sourceRange.LengthLowerBound() > 0 {
// If the source has at least one element then the result
// must always have at least one too, because value coalescing
// cannot totally empty the set.
b = b.CollectionLengthLowerBound(1)
}
} else {
b = b.CollectionLengthLowerBound(sourceRange.LengthLowerBound())
}
b = b.CollectionLengthUpperBound(sourceRange.LengthUpperBound())
return b.NewValue()
default:
return ret
}
} | prepareUnknownResult can apply value refinements to a returned unknown value
in certain cases where characteristics of the source value or type can
transfer into range constraints on the result value. | prepareUnknownResult | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/convert/conversion.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/convert/conversion.go | MIT |
func conversionCollectionToList(ety cty.Type, conv conversion) conversion {
return func(val cty.Value, path cty.Path) (cty.Value, error) {
if !val.Length().IsKnown() {
// If the input collection has an unknown length (which is true
// for a set containing unknown values) then our result must be
// an unknown list, because we can't predict how many elements
// the resulting list should have.
return cty.UnknownVal(cty.List(val.Type().ElementType())), nil
}
elems := make([]cty.Value, 0, val.LengthInt())
i := int64(0)
elemPath := append(path.Copy(), nil)
it := val.ElementIterator()
for it.Next() {
_, val := it.Element()
var err error
elemPath[len(elemPath)-1] = cty.IndexStep{
Key: cty.NumberIntVal(i),
}
if conv != nil {
val, err = conv(val, elemPath)
if err != nil {
return cty.NilVal, err
}
}
if val.IsNull() {
val = cty.NullVal(val.Type().WithoutOptionalAttributesDeep())
}
elems = append(elems, val)
i++
}
if len(elems) == 0 {
// Prefer a concrete type over a dynamic type when returning an
// empty list
if ety == cty.DynamicPseudoType {
return cty.ListValEmpty(val.Type().ElementType()), nil
}
return cty.ListValEmpty(ety.WithoutOptionalAttributesDeep()), nil
}
if !cty.CanListVal(elems) {
return cty.NilVal, path.NewErrorf("element types must all match for conversion to list")
}
return cty.ListVal(elems), nil
}
} | conversionCollectionToList returns a conversion that will apply the given
conversion to all of the elements of a collection (something that supports
ForEachElement and LengthInt) and then returns the result as a list.
"conv" can be nil if the elements are expected to already be of the
correct type and just need to be re-wrapped into a list. (For example,
if we're converting from a set into a list of the same element type.) | conversionCollectionToList | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/convert/conversion_collection.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/convert/conversion_collection.go | MIT |
func conversionCollectionToSet(ety cty.Type, conv conversion) conversion {
return func(val cty.Value, path cty.Path) (cty.Value, error) {
elems := make([]cty.Value, 0, val.LengthInt())
i := int64(0)
elemPath := append(path.Copy(), nil)
it := val.ElementIterator()
for it.Next() {
_, val := it.Element()
var err error
elemPath[len(elemPath)-1] = cty.IndexStep{
Key: cty.NumberIntVal(i),
}
if conv != nil {
val, err = conv(val, elemPath)
if err != nil {
return cty.NilVal, err
}
}
if val.IsNull() {
val = cty.NullVal(val.Type().WithoutOptionalAttributesDeep())
}
elems = append(elems, val)
i++
}
if len(elems) == 0 {
// Prefer a concrete type over a dynamic type when returning an
// empty set
if ety == cty.DynamicPseudoType {
return cty.SetValEmpty(val.Type().ElementType()), nil
}
return cty.SetValEmpty(ety.WithoutOptionalAttributesDeep()), nil
}
if !cty.CanSetVal(elems) {
return cty.NilVal, path.NewErrorf("element types must all match for conversion to set")
}
return cty.SetVal(elems), nil
}
} | conversionCollectionToSet returns a conversion that will apply the given
conversion to all of the elements of a collection (something that supports
ForEachElement and LengthInt) and then returns the result as a set.
"conv" can be nil if the elements are expected to already be of the
correct type and just need to be re-wrapped into a set. (For example,
if we're converting from a list into a set of the same element type.) | conversionCollectionToSet | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/convert/conversion_collection.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/convert/conversion_collection.go | MIT |
func conversionCollectionToMap(ety cty.Type, conv conversion) conversion {
return func(val cty.Value, path cty.Path) (cty.Value, error) {
elems := make(map[string]cty.Value, 0)
elemPath := append(path.Copy(), nil)
it := val.ElementIterator()
for it.Next() {
key, val := it.Element()
var err error
elemPath[len(elemPath)-1] = cty.IndexStep{
Key: key,
}
keyStr, err := Convert(key, cty.String)
if err != nil {
// Should never happen, because keys can only be numbers or
// strings and both can convert to string.
return cty.DynamicVal, elemPath.NewErrorf("cannot convert key type %s to string for map", key.Type().FriendlyName())
}
if conv != nil {
val, err = conv(val, elemPath)
if err != nil {
return cty.NilVal, err
}
}
elems[keyStr.AsString()] = val
}
if len(elems) == 0 {
// Prefer a concrete type over a dynamic type when returning an
// empty map
if ety == cty.DynamicPseudoType {
return cty.MapValEmpty(val.Type().ElementType()), nil
}
return cty.MapValEmpty(ety), nil
}
if ety.IsCollectionType() || ety.IsObjectType() {
var err error
if elems, err = conversionUnifyCollectionElements(elems, path, false); err != nil {
return cty.NilVal, err
}
}
if !cty.CanMapVal(elems) {
return cty.NilVal, path.NewErrorf("element types must all match for conversion to map")
}
return cty.MapVal(elems), nil
}
} | conversionCollectionToMap returns a conversion that will apply the given
conversion to all of the elements of a collection (something that supports
ForEachElement and LengthInt) and then returns the result as a map.
"conv" can be nil if the elements are expected to already be of the
correct type and just need to be re-wrapped into a map. | conversionCollectionToMap | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/convert/conversion_collection.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/convert/conversion_collection.go | MIT |
func conversionTupleToSet(tupleType cty.Type, setEty cty.Type, unsafe bool) conversion {
tupleEtys := tupleType.TupleElementTypes()
if len(tupleEtys) == 0 {
// Empty tuple short-circuit
return func(val cty.Value, path cty.Path) (cty.Value, error) {
return cty.SetValEmpty(setEty.WithoutOptionalAttributesDeep()), nil
}
}
if setEty == cty.DynamicPseudoType {
// This is a special case where the caller wants us to find
// a suitable single type that all elements can convert to, if
// possible.
setEty, _ = unify(tupleEtys, unsafe)
if setEty == cty.NilType {
return nil
}
// If the set element type after unification is still the dynamic
// type, the only way this can result in a valid set is if all values
// are of dynamic type
if setEty == cty.DynamicPseudoType {
for _, tupleEty := range tupleEtys {
if !tupleEty.Equals(cty.DynamicPseudoType) {
return nil
}
}
}
}
elemConvs := make([]conversion, len(tupleEtys))
for i, tupleEty := range tupleEtys {
if tupleEty.Equals(setEty) {
// no conversion required
continue
}
elemConvs[i] = getConversion(tupleEty, setEty, unsafe)
if elemConvs[i] == nil {
// If any of our element conversions are impossible, then the our
// whole conversion is impossible.
return nil
}
}
// If we fall out here then a conversion is possible, using the
// element conversions in elemConvs
return func(val cty.Value, path cty.Path) (cty.Value, error) {
elems := make([]cty.Value, 0, len(elemConvs))
elemPath := append(path.Copy(), nil)
i := int64(0)
it := val.ElementIterator()
for it.Next() {
_, val := it.Element()
var err error
elemPath[len(elemPath)-1] = cty.IndexStep{
Key: cty.NumberIntVal(i),
}
conv := elemConvs[i]
if conv != nil {
val, err = conv(val, elemPath)
if err != nil {
return cty.NilVal, err
}
}
if val.IsNull() {
val = cty.NullVal(val.Type().WithoutOptionalAttributesDeep())
}
elems = append(elems, val)
i++
}
if !cty.CanSetVal(elems) {
return cty.NilVal, path.NewErrorf("element types must all match for conversion to set")
}
return cty.SetVal(elems), nil
}
} | conversionTupleToSet returns a conversion that will take a value of the
given tuple type and return a set of the given element type.
Will panic if the given tupleType isn't actually a tuple type. | conversionTupleToSet | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/convert/conversion_collection.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/convert/conversion_collection.go | MIT |
func conversionTupleToList(tupleType cty.Type, listEty cty.Type, unsafe bool) conversion {
tupleEtys := tupleType.TupleElementTypes()
if len(tupleEtys) == 0 {
// Empty tuple short-circuit
return func(val cty.Value, path cty.Path) (cty.Value, error) {
return cty.ListValEmpty(listEty.WithoutOptionalAttributesDeep()), nil
}
}
if listEty == cty.DynamicPseudoType {
// This is a special case where the caller wants us to find
// a suitable single type that all elements can convert to, if
// possible.
listEty, _ = unify(tupleEtys, unsafe)
if listEty == cty.NilType {
return nil
}
// If the list element type after unification is still the dynamic
// type, the only way this can result in a valid list is if all values
// are of dynamic type
if listEty == cty.DynamicPseudoType {
for _, tupleEty := range tupleEtys {
if !tupleEty.Equals(cty.DynamicPseudoType) {
return nil
}
}
}
}
elemConvs := make([]conversion, len(tupleEtys))
for i, tupleEty := range tupleEtys {
if tupleEty.Equals(listEty) {
// no conversion required
continue
}
elemConvs[i] = getConversion(tupleEty, listEty, unsafe)
if elemConvs[i] == nil {
// If any of our element conversions are impossible, then the our
// whole conversion is impossible.
return nil
}
}
// If we fall out here then a conversion is possible, using the
// element conversions in elemConvs
return func(val cty.Value, path cty.Path) (cty.Value, error) {
elems := make([]cty.Value, 0, len(elemConvs))
elemTys := make([]cty.Type, 0, len(elems))
elemPath := append(path.Copy(), nil)
i := int64(0)
it := val.ElementIterator()
for it.Next() {
_, val := it.Element()
var err error
elemPath[len(elemPath)-1] = cty.IndexStep{
Key: cty.NumberIntVal(i),
}
conv := elemConvs[i]
if conv != nil {
val, err = conv(val, elemPath)
if err != nil {
return cty.NilVal, err
}
}
elems = append(elems, val)
elemTys = append(elemTys, val.Type())
i++
}
elems, err := conversionUnifyListElements(elems, elemPath, unsafe)
if err != nil {
return cty.NilVal, err
}
if !cty.CanListVal(elems) {
return cty.NilVal, path.NewErrorf("element types must all match for conversion to list")
}
return cty.ListVal(elems), nil
}
} | conversionTupleToList returns a conversion that will take a value of the
given tuple type and return a list of the given element type.
Will panic if the given tupleType isn't actually a tuple type. | conversionTupleToList | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/convert/conversion_collection.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/convert/conversion_collection.go | MIT |
func conversionObjectToMap(objectType cty.Type, mapEty cty.Type, unsafe bool) conversion {
objectAtys := objectType.AttributeTypes()
if len(objectAtys) == 0 {
// Empty object short-circuit
return func(val cty.Value, path cty.Path) (cty.Value, error) {
return cty.MapValEmpty(mapEty.WithoutOptionalAttributesDeep()), nil
}
}
if mapEty == cty.DynamicPseudoType {
// This is a special case where the caller wants us to find
// a suitable single type that all elements can convert to, if
// possible.
objectAtysList := make([]cty.Type, 0, len(objectAtys))
for _, aty := range objectAtys {
objectAtysList = append(objectAtysList, aty)
}
mapEty, _ = unify(objectAtysList, unsafe)
if mapEty == cty.NilType {
return nil
}
}
elemConvs := make(map[string]conversion, len(objectAtys))
for name, objectAty := range objectAtys {
if objectAty.Equals(mapEty) {
// no conversion required
continue
}
elemConvs[name] = getConversion(objectAty, mapEty, unsafe)
if elemConvs[name] == nil {
// If any of our element conversions are impossible, then the our
// whole conversion is impossible.
return nil
}
}
// If we fall out here then a conversion is possible, using the
// element conversions in elemConvs
return func(val cty.Value, path cty.Path) (cty.Value, error) {
elems := make(map[string]cty.Value, len(elemConvs))
elemPath := append(path.Copy(), nil)
it := val.ElementIterator()
for it.Next() {
name, val := it.Element()
var err error
elemPath[len(elemPath)-1] = cty.IndexStep{
Key: name,
}
conv := elemConvs[name.AsString()]
if conv != nil {
val, err = conv(val, elemPath)
if err != nil {
return cty.NilVal, err
}
}
elems[name.AsString()] = val
}
if mapEty.IsCollectionType() || mapEty.IsObjectType() {
var err error
if elems, err = conversionUnifyCollectionElements(elems, path, unsafe); err != nil {
return cty.NilVal, err
}
}
if !cty.CanMapVal(elems) {
return cty.NilVal, path.NewErrorf("attribute types must all match for conversion to map")
}
return cty.MapVal(elems), nil
}
} | conversionObjectToMap returns a conversion that will take a value of the
given object type and return a map of the given element type.
Will panic if the given objectType isn't actually an object type. | conversionObjectToMap | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/convert/conversion_collection.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/convert/conversion_collection.go | MIT |
func conversionMapToObject(mapType cty.Type, objType cty.Type, unsafe bool) conversion {
objectAtys := objType.AttributeTypes()
mapEty := mapType.ElementType()
elemConvs := make(map[string]conversion, len(objectAtys))
for name, objectAty := range objectAtys {
if objectAty.Equals(mapEty) {
// no conversion required
continue
}
elemConvs[name] = getConversion(mapEty, objectAty, unsafe)
if elemConvs[name] == nil {
// This means that this conversion is impossible. Typically, we
// would give up at this point and declare the whole conversion
// impossible. But, if this attribute is optional then maybe we will
// be able to do this conversion anyway provided the actual concrete
// map doesn't have this value set.
//
// We only do this in "unsafe" mode, because we cannot guarantee
// that the returned conversion will actually succeed once applied.
if objType.AttributeOptional(name) && unsafe {
// This attribute is optional, so let's leave this conversion in
// as a nil, and we can error later if we actually have to
// convert this.
continue
}
// Otherwise, give up. This conversion is impossible as we have a
// required attribute that doesn't match the map's inner type.
return nil
}
}
// If we fall out here then a conversion may be possible, using the
// element conversions in elemConvs
return func(val cty.Value, path cty.Path) (cty.Value, error) {
elems := make(map[string]cty.Value, len(elemConvs))
elemPath := append(path.Copy(), nil)
it := val.ElementIterator()
for it.Next() {
name, val := it.Element()
// if there is no corresponding attribute, we skip this key
if _, ok := objectAtys[name.AsString()]; !ok {
continue
}
var err error
elemPath[len(elemPath)-1] = cty.IndexStep{
Key: name,
}
// There are 3 cases here:
// 1. This attribute is not in elemConvs
// 2. This attribute is in elemConvs and is not nil
// 3. This attribute is in elemConvs and is nil.
// In case 1, we do not enter any of the branches below. This case
// means the attribute type is the same between the map and the
// object, and we don't need to do any conversion.
if conv, ok := elemConvs[name.AsString()]; conv != nil {
// This is case 2. The attribute type is different between the
// map and the object, and we know how to convert between them.
// So, we reset val to be the converted value and carry on.
val, err = conv(val, elemPath)
if err != nil {
return cty.NilVal, err
}
} else if ok {
// This is case 3 and it is an error. The attribute types are
// different between the map and the object, but we cannot
// convert between them.
//
// Now typically, this would be picked earlier on when we were
// building elemConvs. However, in the case of optional
// attributes there was a chance we could still convert the
// overall object even if this particular attribute was not
// convertable. This is because it could have not been set in
// the map, and we could skip over it here and set a null value.
//
// Since we reached this branch, we know that map did actually
// contain a non-convertable optional attribute. This means we
// error.
return cty.NilVal, path.NewErrorf("map element type is incompatible with attribute %q: %s", name.AsString(), MismatchMessage(val.Type(), objType.AttributeType(name.AsString())))
}
if val.IsNull() {
val = cty.NullVal(val.Type().WithoutOptionalAttributesDeep())
}
elems[name.AsString()] = val
}
for name, aty := range objectAtys {
if _, exists := elems[name]; !exists {
if optional := objType.AttributeOptional(name); optional {
elems[name] = cty.NullVal(aty)
} else {
return cty.NilVal, path.NewErrorf("map has no element for required attribute %q", name)
}
}
}
return cty.ObjectVal(elems), nil
}
} | conversionMapToObject returns a conversion that will take a value of the
given map type and return an object of the given type. The object attribute
types must all be compatible with the map element type.
Will panic if the given mapType and objType are not maps and objects
respectively. | conversionMapToObject | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/convert/conversion_collection.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/convert/conversion_collection.go | MIT |
func dynamicFixup(wantType cty.Type) conversion {
return func(in cty.Value, path cty.Path) (cty.Value, error) {
ret, err := Convert(in, wantType)
if err != nil {
// Re-wrap this error so that the returned path is relative
// to the caller's original value, rather than relative to our
// conversion value here.
return cty.NilVal, path.NewError(err)
}
return ret, nil
}
} | dynamicFixup deals with just-in-time conversions of values that were
input-typed as cty.DynamicPseudoType during analysis, ensuring that
we end up with the desired output type once the value is known, or
failing with an error if that is not possible.
This is in the spirit of the cty philosophy of optimistically assuming that
DynamicPseudoType values will become the intended value eventually, and
dealing with any inconsistencies during final evaluation. | dynamicFixup | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/convert/conversion_dynamic.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/convert/conversion_dynamic.go | MIT |
func dynamicPassthrough(in cty.Value, path cty.Path) (cty.Value, error) {
return in, nil
} | dynamicPassthrough is an identity conversion that is used when the
target type is DynamicPseudoType, indicating that the caller doesn't care
which type is returned. | dynamicPassthrough | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/convert/conversion_dynamic.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/convert/conversion_dynamic.go | MIT |
func dynamicReplace(in, out cty.Type) cty.Type {
if in == cty.DynamicPseudoType || in == cty.NilType {
// Short circuit this case, there's no point worrying about this if in
// is a dynamic type or a nil type. Out is the best we can do.
return out
}
switch {
case out == cty.DynamicPseudoType:
// So replace out with in.
return in
case out.IsPrimitiveType(), out.IsCapsuleType():
// out is not dynamic and it doesn't contain descendent elements so just
// return it unchanged.
return out
case out.IsMapType():
// Maps are compatible with other maps or objects.
if in.IsMapType() {
return cty.Map(dynamicReplace(in.ElementType(), out.ElementType()))
}
if in.IsObjectType() {
var types []cty.Type
for _, t := range in.AttributeTypes() {
types = append(types, t)
}
unifiedType, _ := unify(types, true)
return cty.Map(dynamicReplace(unifiedType, out.ElementType()))
}
return out
case out.IsObjectType():
// Objects are compatible with other objects and maps.
outTypes := map[string]cty.Type{}
if in.IsMapType() {
for attr, attrType := range out.AttributeTypes() {
outTypes[attr] = dynamicReplace(in.ElementType(), attrType)
}
}
if in.IsObjectType() {
for attr, attrType := range out.AttributeTypes() {
if !in.HasAttribute(attr) {
// If in does not have this attribute, then it is an
// optional attribute and there is nothing we can do except
// to return the type from out even if it is dynamic.
outTypes[attr] = attrType
continue
}
outTypes[attr] = dynamicReplace(in.AttributeType(attr), attrType)
}
}
return cty.Object(outTypes)
case out.IsSetType():
// Sets are compatible with other sets, lists, tuples.
if in.IsSetType() || in.IsListType() {
return cty.Set(dynamicReplace(in.ElementType(), out.ElementType()))
}
if in.IsTupleType() {
unifiedType, _ := unify(in.TupleElementTypes(), true)
return cty.Set(dynamicReplace(unifiedType, out.ElementType()))
}
return out
case out.IsListType():
// Lists are compatible with other lists, sets, and tuples.
if in.IsSetType() || in.IsListType() {
return cty.List(dynamicReplace(in.ElementType(), out.ElementType()))
}
if in.IsTupleType() {
unifiedType, _ := unify(in.TupleElementTypes(), true)
return cty.List(dynamicReplace(unifiedType, out.ElementType()))
}
return out
case out.IsTupleType():
// Tuples are only compatible with other tuples
var types []cty.Type
for ix := 0; ix < len(out.TupleElementTypes()); ix++ {
types = append(types, dynamicReplace(in.TupleElementType(ix), out.TupleElementType(ix)))
}
return cty.Tuple(types)
default:
panic("unrecognized type " + out.FriendlyName())
}
} | dynamicReplace aims to return the out type unchanged, but if it finds a
dynamic type either directly or in any descendent elements it replaces them
with the equivalent type from in.
This function assumes that in and out are compatible from a Convert
perspective, and will panic if it finds that they are not. For example if
in is an object and out is a map, this function will still attempt to iterate
through both as if they were the same.
While the outermost in and out types may be compatible from a Convert
perspective, inner types may not match when converting between maps and
objects with optional attributes when the optional attributes don't match
the map element type. Therefor in the case of a non-primitive type mismatch,
we have to assume conversion was possible and pass the out type through. | dynamicReplace | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/convert/conversion_dynamic.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/convert/conversion_dynamic.go | MIT |
func conversionObjectToObject(in, out cty.Type, unsafe bool) conversion {
inAtys := in.AttributeTypes()
outAtys := out.AttributeTypes()
outOptionals := out.OptionalAttributes()
attrConvs := make(map[string]conversion)
for name, outAty := range outAtys {
inAty, exists := inAtys[name]
if !exists {
if _, optional := outOptionals[name]; optional {
// If it's optional then we'll skip inserting an
// attribute conversion and then deal with inserting
// the default value in our overall conversion logic
// later.
continue
}
// No conversion is available, then.
return nil
}
if inAty.Equals(outAty) {
// No conversion needed, but we'll still record the attribute
// in our map for later reference.
attrConvs[name] = nil
continue
}
attrConvs[name] = getConversion(inAty, outAty, unsafe)
if attrConvs[name] == nil {
// If a recursive conversion isn't available, then our top-level
// configuration is impossible too.
return nil
}
}
// If we get here then a conversion is possible, using the attribute
// conversions given in attrConvs.
return func(val cty.Value, path cty.Path) (cty.Value, error) {
attrVals := make(map[string]cty.Value, len(attrConvs))
path = append(path, nil)
pathStep := &path[len(path)-1]
for it := val.ElementIterator(); it.Next(); {
nameVal, val := it.Element()
var err error
name := nameVal.AsString()
*pathStep = cty.GetAttrStep{
Name: name,
}
conv, exists := attrConvs[name]
if !exists {
continue
}
if conv != nil {
val, err = conv(val, path)
if err != nil {
return cty.NilVal, err
}
}
if val.IsNull() {
// Strip optional attributes out of the embedded type for null
// values.
val = cty.NullVal(val.Type().WithoutOptionalAttributesDeep())
}
attrVals[name] = val
}
for name := range outOptionals {
if _, exists := attrVals[name]; !exists {
wantTy := outAtys[name]
attrVals[name] = cty.NullVal(wantTy.WithoutOptionalAttributesDeep())
}
}
return cty.ObjectVal(attrVals), nil
}
} | conversionObjectToObject returns a conversion that will make the input
object type conform to the output object type, if possible.
Conversion is possible only if the output type is a subset of the input
type, meaning that each attribute of the output type has a corresponding
attribute in the input type where a recursive conversion is available.
If the "out" type has any optional attributes, those attributes may be
absent in the "in" type, in which case null values will be used in their
place in the result.
Shallow object conversions work the same for both safe and unsafe modes,
but the safety flag is passed on to recursive conversions and may thus
limit the above definition of "subset". | conversionObjectToObject | go | integrations/terraform-provider-github | vendor/github.com/zclconf/go-cty/cty/convert/conversion_object.go | https://github.com/integrations/terraform-provider-github/blob/master/vendor/github.com/zclconf/go-cty/cty/convert/conversion_object.go | MIT |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.