Skip to content

Commit

Permalink
Stop pipe component to panic if given a bad property path. Error out …
Browse files Browse the repository at this point in the history
…intead.
  • Loading branch information
vhadianto committed Oct 19, 2023
1 parent 56e5c15 commit d99e288
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
1 change: 1 addition & 0 deletions modconfig/flowpipe_pipeline_step.go
Original file line number Diff line number Diff line change
Expand Up @@ -2491,6 +2491,7 @@ func (p *PipelineStepInput) GetInputs(evalContext *hcl.EvalContext) (map[string]
}
}
}

}

return results, nil
Expand Down
7 changes: 6 additions & 1 deletion modconfig/parsed_property_path.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func ParseResourcePropertyPath(propertyPath string) (*ParsedPropertyPath, error)

parts := strings.Split(propertyPath, ".")
if len(parts) < 2 {
return nil, perr.BadRequestWithMessage("invalid property path passed to ParseResourcePropertyPath: " + propertyPath)
return nil, perr.BadRequestWithMessage("invalid property path: " + propertyPath)
}

// special case handling for runtime dependencies which may have use the "self" qualifier
Expand All @@ -61,6 +61,11 @@ func ParseResourcePropertyPath(propertyPath string) (*ParsedPropertyPath, error)
// put empty mod as first part
parts = append([]string{""}, parts...)
}

if len(parts) < 3 {
return nil, perr.BadRequestWithMessage("invalid property path: " + propertyPath)
}

switch len(parts) {
case 3:
// no property path specified
Expand Down
18 changes: 9 additions & 9 deletions parse/pipeline_decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,17 @@ func decodeStep(mod *modconfig.Mod, block *hcl.Block, parseCtx *ModParseContext,
stepOptions, diags := block.Body.Content(pipelineStepBlockSchema)

if diags.HasErrors() {
return nil, diags
return step, diags
}

diags = step.SetAttributes(stepOptions.Attributes, parseCtx.EvalCtx)
if len(diags) > 0 {
return nil, diags
return step, diags
}

diags = step.SetBlockConfig(stepOptions.Blocks, parseCtx.EvalCtx)
if len(diags) > 0 {
return nil, diags
return step, diags
}

if errorBlocks := stepOptions.Blocks.ByType()[schema.BlockTypeError]; len(errorBlocks) > 0 {
Expand All @@ -69,7 +69,7 @@ func decodeStep(mod *modconfig.Mod, block *hcl.Block, parseCtx *ModParseContext,

attributes, diags := errorBlock.Body.JustAttributes()
if len(diags) > 0 {
return nil, diags
return step, diags
}

ignore := false
Expand All @@ -78,12 +78,12 @@ func decodeStep(mod *modconfig.Mod, block *hcl.Block, parseCtx *ModParseContext,
if attr, exists := attributes[schema.AttributeTypeIgnore]; exists {
val, diags := attr.Expr.Value(nil)
if len(diags) > 0 {
return nil, diags
return step, diags
}

var target bool
if err := gocty.FromCtyValue(val, &target); err != nil {
return nil, hcl.Diagnostics{&hcl.Diagnostic{
return step, hcl.Diagnostics{&hcl.Diagnostic{
Severity: hcl.DiagError,
Summary: "Error decoding ignore attribute",
Detail: err.Error(),
Expand All @@ -96,12 +96,12 @@ func decodeStep(mod *modconfig.Mod, block *hcl.Block, parseCtx *ModParseContext,
if attr, exists := attributes[schema.AttributeTypeRetries]; exists {
val, diags := attr.Expr.Value(nil)
if len(diags) > 0 {
return nil, diags
return step, diags
}

var target int
if err := gocty.FromCtyValue(val, &target); err != nil {
return nil, hcl.Diagnostics{&hcl.Diagnostic{
return step, hcl.Diagnostics{&hcl.Diagnostic{
Severity: hcl.DiagError,
Summary: "Error decoding retries attribute",
Detail: err.Error(),
Expand Down Expand Up @@ -132,7 +132,7 @@ func decodeStep(mod *modconfig.Mod, block *hcl.Block, parseCtx *ModParseContext,
for _, outputBlock := range outputBlocks {
attributes, diags := outputBlock.Body.JustAttributes()
if len(diags) > 0 {
return nil, diags
return step, diags
}

if attr, exists := attributes[schema.AttributeTypeValue]; exists {
Expand Down

0 comments on commit d99e288

Please sign in to comment.