vendor: go get github.com/hashicorp/hcl/v2@v2.6.0

This commit is contained in:
Alisdair McDiarmid 2020-06-11 12:39:35 -04:00
parent 9ef84801a8
commit 3fe8a7f76a
8 changed files with 111 additions and 23 deletions

2
go.mod
View File

@ -66,7 +66,7 @@ require (
github.com/hashicorp/go-uuid v1.0.1 github.com/hashicorp/go-uuid v1.0.1
github.com/hashicorp/go-version v1.2.0 github.com/hashicorp/go-version v1.2.0
github.com/hashicorp/hcl v0.0.0-20170504190234-a4b07c25de5f github.com/hashicorp/hcl v0.0.0-20170504190234-a4b07c25de5f
github.com/hashicorp/hcl/v2 v2.5.1 github.com/hashicorp/hcl/v2 v2.6.0
github.com/hashicorp/hil v0.0.0-20190212112733-ab17b08d6590 github.com/hashicorp/hil v0.0.0-20190212112733-ab17b08d6590
github.com/hashicorp/memberlist v0.1.0 // indirect github.com/hashicorp/memberlist v0.1.0 // indirect
github.com/hashicorp/serf v0.0.0-20160124182025-e4ec8cc423bb // indirect github.com/hashicorp/serf v0.0.0-20160124182025-e4ec8cc423bb // indirect

4
go.sum
View File

@ -281,8 +281,8 @@ github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ
github.com/hashicorp/hcl v0.0.0-20170504190234-a4b07c25de5f h1:UdxlrJz4JOnY8W+DbLISwf2B8WXEolNRA8BGCwI9jws= github.com/hashicorp/hcl v0.0.0-20170504190234-a4b07c25de5f h1:UdxlrJz4JOnY8W+DbLISwf2B8WXEolNRA8BGCwI9jws=
github.com/hashicorp/hcl v0.0.0-20170504190234-a4b07c25de5f/go.mod h1:oZtUIOe8dh44I2q6ScRibXws4Ajl+d+nod3AaR9vL5w= github.com/hashicorp/hcl v0.0.0-20170504190234-a4b07c25de5f/go.mod h1:oZtUIOe8dh44I2q6ScRibXws4Ajl+d+nod3AaR9vL5w=
github.com/hashicorp/hcl/v2 v2.0.0/go.mod h1:oVVDG71tEinNGYCxinCYadcmKU9bglqW9pV3txagJ90= github.com/hashicorp/hcl/v2 v2.0.0/go.mod h1:oVVDG71tEinNGYCxinCYadcmKU9bglqW9pV3txagJ90=
github.com/hashicorp/hcl/v2 v2.5.1 h1:5ytFZykUu2/4U59ogd2f+XZdi9+6oC/Tv5WzsH6fIDA= github.com/hashicorp/hcl/v2 v2.6.0 h1:3krZOfGY6SziUXa6H9PJU6TyohHn7I+ARYnhbeNBz+o=
github.com/hashicorp/hcl/v2 v2.5.1/go.mod h1:bQTN5mpo+jewjJgh8jr0JUguIi7qPHUF6yIfAEN3jqY= github.com/hashicorp/hcl/v2 v2.6.0/go.mod h1:bQTN5mpo+jewjJgh8jr0JUguIi7qPHUF6yIfAEN3jqY=
github.com/hashicorp/hil v0.0.0-20190212112733-ab17b08d6590 h1:2yzhWGdgQUWZUCNK+AoO35V+HTsgEmcM4J9IkArh7PI= github.com/hashicorp/hil v0.0.0-20190212112733-ab17b08d6590 h1:2yzhWGdgQUWZUCNK+AoO35V+HTsgEmcM4J9IkArh7PI=
github.com/hashicorp/hil v0.0.0-20190212112733-ab17b08d6590/go.mod h1:n2TSygSNwsLJ76m8qFXTSc7beTb+auJxYdqrnoqwZWE= github.com/hashicorp/hil v0.0.0-20190212112733-ab17b08d6590/go.mod h1:n2TSygSNwsLJ76m8qFXTSc7beTb+auJxYdqrnoqwZWE=
github.com/hashicorp/memberlist v0.1.0 h1:qSsCiC0WYD39lbSitKNt40e30uorm2Ss/d4JGU1hzH8= github.com/hashicorp/memberlist v0.1.0 h1:qSsCiC0WYD39lbSitKNt40e30uorm2Ss/d4JGU1hzH8=

View File

@ -1,5 +1,16 @@
# HCL Changelog # HCL Changelog
## v2.6.0 (June 4, 2020)
### Enhancements
* hcldec: Add a new `Spec`, `ValidateSpec`, which allows custom validation of values at decode-time. ([#387](https://github.com/hashicorp/hcl/pull/387))
### Bugs Fixed
* hclsyntax: Fix panic with combination of sequences and null arguments ([#386](https://github.com/hashicorp/hcl/pull/386))
* hclsyntax: Fix handling of unknown values and sequences ([#386](https://github.com/hashicorp/hcl/pull/386))
## v2.5.1 (May 14, 2020) ## v2.5.1 (May 14, 2020)
### Bugs Fixed ### Bugs Fixed

View File

@ -22,14 +22,14 @@ const (
) )
// Diagnostic represents information to be presented to a user about an // Diagnostic represents information to be presented to a user about an
// error or anomoly in parsing or evaluating configuration. // error or anomaly in parsing or evaluating configuration.
type Diagnostic struct { type Diagnostic struct {
Severity DiagnosticSeverity Severity DiagnosticSeverity
// Summary and Detail contain the English-language description of the // Summary and Detail contain the English-language description of the
// problem. Summary is a terse description of the general problem and // problem. Summary is a terse description of the general problem and
// detail is a more elaborate, often-multi-sentence description of // detail is a more elaborate, often-multi-sentence description of
// the probem and what might be done to solve it. // the problem and what might be done to solve it.
Summary string Summary string
Detail string Detail string

View File

@ -1565,6 +1565,52 @@ func (s *TransformFuncSpec) sourceRange(content *hcl.BodyContent, blockLabels []
return s.Wrapped.sourceRange(content, blockLabels) return s.Wrapped.sourceRange(content, blockLabels)
} }
// ValidateFuncSpec is a spec that allows for extended
// developer-defined validation. The validation function receives the
// result of the wrapped spec.
//
// The Subject field of the returned Diagnostic is optional. If not
// specified, it is automatically populated with the range covered by
// the wrapped spec.
//
type ValidateSpec struct {
Wrapped Spec
Func func(value cty.Value) hcl.Diagnostics
}
func (s *ValidateSpec) visitSameBodyChildren(cb visitFunc) {
cb(s.Wrapped)
}
func (s *ValidateSpec) decode(content *hcl.BodyContent, blockLabels []blockLabel, ctx *hcl.EvalContext) (cty.Value, hcl.Diagnostics) {
wrappedVal, diags := s.Wrapped.decode(content, blockLabels, ctx)
if diags.HasErrors() {
// We won't try to run our function in this case, because it'll probably
// generate confusing additional errors that will distract from the
// root cause.
return cty.UnknownVal(s.impliedType()), diags
}
validateDiags := s.Func(wrappedVal)
// Auto-populate the Subject fields if they weren't set.
for i := range validateDiags {
if validateDiags[i].Subject == nil {
validateDiags[i].Subject = s.sourceRange(content, blockLabels).Ptr()
}
}
diags = append(diags, validateDiags...)
return wrappedVal, diags
}
func (s *ValidateSpec) impliedType() cty.Type {
return s.Wrapped.impliedType()
}
func (s *ValidateSpec) sourceRange(content *hcl.BodyContent, blockLabels []blockLabel) hcl.Range {
return s.Wrapped.sourceRange(content, blockLabels)
}
// noopSpec is a placeholder spec that does nothing, used in situations where // noopSpec is a placeholder spec that does nothing, used in situations where
// a non-nil placeholder spec is required. It is not exported because there is // a non-nil placeholder spec is required. It is not exported because there is
// no reason to use it directly; it is always an implementation detail only. // no reason to use it directly; it is always an implementation detail only.

View File

@ -260,6 +260,20 @@ func (e *FunctionCallExpr) Value(ctx *hcl.EvalContext) (cty.Value, hcl.Diagnosti
} }
switch { switch {
case expandVal.Type().Equals(cty.DynamicPseudoType):
if expandVal.IsNull() {
diags = append(diags, &hcl.Diagnostic{
Severity: hcl.DiagError,
Summary: "Invalid expanding argument value",
Detail: "The expanding argument (indicated by ...) must not be null.",
Subject: expandExpr.Range().Ptr(),
Context: e.Range().Ptr(),
Expression: expandExpr,
EvalContext: ctx,
})
return cty.DynamicVal, diags
}
return cty.DynamicVal, diags
case expandVal.Type().IsTupleType() || expandVal.Type().IsListType() || expandVal.Type().IsSetType(): case expandVal.Type().IsTupleType() || expandVal.Type().IsListType() || expandVal.Type().IsSetType():
if expandVal.IsNull() { if expandVal.IsNull() {
diags = append(diags, &hcl.Diagnostic{ diags = append(diags, &hcl.Diagnostic{
@ -406,22 +420,39 @@ func (e *FunctionCallExpr) Value(ctx *hcl.EvalContext) (cty.Value, hcl.Diagnosti
} else { } else {
param = varParam param = varParam
} }
argExpr := e.Args[i]
// TODO: we should also unpick a PathError here and show the // this can happen if an argument is (incorrectly) null.
// path to the deep value where the error was detected. if i > len(e.Args)-1 {
diags = append(diags, &hcl.Diagnostic{ diags = append(diags, &hcl.Diagnostic{
Severity: hcl.DiagError, Severity: hcl.DiagError,
Summary: "Invalid function argument", Summary: "Invalid function argument",
Detail: fmt.Sprintf( Detail: fmt.Sprintf(
"Invalid value for %q parameter: %s.", "Invalid value for %q parameter: %s.",
param.Name, err, param.Name, err,
), ),
Subject: argExpr.StartRange().Ptr(), Subject: args[len(params)].StartRange().Ptr(),
Context: e.Range().Ptr(), Context: e.Range().Ptr(),
Expression: argExpr, Expression: e,
EvalContext: ctx, EvalContext: ctx,
}) })
} else {
argExpr := e.Args[i]
// TODO: we should also unpick a PathError here and show the
// path to the deep value where the error was detected.
diags = append(diags, &hcl.Diagnostic{
Severity: hcl.DiagError,
Summary: "Invalid function argument",
Detail: fmt.Sprintf(
"Invalid value for %q parameter: %s.",
param.Name, err,
),
Subject: argExpr.StartRange().Ptr(),
Context: e.Range().Ptr(),
Expression: argExpr,
EvalContext: ctx,
})
}
default: default:
diags = append(diags, &hcl.Diagnostic{ diags = append(diags, &hcl.Diagnostic{

View File

@ -521,8 +521,8 @@ func writerTokens(nativeTokens hclsyntax.Tokens) Tokens {
// The tokens are assumed to be in source order and non-overlapping, which // The tokens are assumed to be in source order and non-overlapping, which
// will be true if the token sequence from the scanner is used directly. // will be true if the token sequence from the scanner is used directly.
func partitionTokens(toks hclsyntax.Tokens, rng hcl.Range) (start, end int) { func partitionTokens(toks hclsyntax.Tokens, rng hcl.Range) (start, end int) {
// We us a linear search here because we assume tha in most cases our // We use a linear search here because we assume that in most cases our
// target range is close to the beginning of the sequence, and the seqences // target range is close to the beginning of the sequence, and the sequences
// are generally small for most reasonable files anyway. // are generally small for most reasonable files anyway.
for i := 0; ; i++ { for i := 0; ; i++ {
if i >= len(toks) { if i >= len(toks) {

2
vendor/modules.txt vendored
View File

@ -375,7 +375,7 @@ github.com/hashicorp/hcl/hcl/token
github.com/hashicorp/hcl/json/parser github.com/hashicorp/hcl/json/parser
github.com/hashicorp/hcl/json/scanner github.com/hashicorp/hcl/json/scanner
github.com/hashicorp/hcl/json/token github.com/hashicorp/hcl/json/token
# github.com/hashicorp/hcl/v2 v2.5.1 # github.com/hashicorp/hcl/v2 v2.6.0
## explicit ## explicit
github.com/hashicorp/hcl/v2 github.com/hashicorp/hcl/v2
github.com/hashicorp/hcl/v2/ext/customdecode github.com/hashicorp/hcl/v2/ext/customdecode