You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by nf...@apache.org on 2021/03/19 16:08:02 UTC
[camel-k] branch master updated: Fix #2035: invalid YAML should not
make the operator panic
This is an automated email from the ASF dual-hosted git repository.
nferraro pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k.git
The following commit(s) were added to refs/heads/master by this push:
new 5ff1d5a Fix #2035: invalid YAML should not make the operator panic
5ff1d5a is described below
commit 5ff1d5a04c820c7b5a6a42ace3fc89a2552cf8e9
Author: nicolaferraro <ni...@gmail.com>
AuthorDate: Fri Mar 19 15:43:43 2021 +0100
Fix #2035: invalid YAML should not make the operator panic
---
pkg/util/source/inspector_yaml.go | 41 ++++++++++++++++++----------------
pkg/util/source/inspector_yaml_test.go | 14 ++++++++++++
2 files changed, 36 insertions(+), 19 deletions(-)
diff --git a/pkg/util/source/inspector_yaml.go b/pkg/util/source/inspector_yaml.go
index 213fbf8..1f96ae8 100644
--- a/pkg/util/source/inspector_yaml.go
+++ b/pkg/util/source/inspector_yaml.go
@@ -91,34 +91,37 @@ func (i YAMLInspector) parseStep(key string, content interface{}, meta *Metadata
} else if u, ok := t["from"]; ok {
return i.parseStep("from", u, meta)
} else if u, ok := t["steps"]; ok {
- steps := u.([]interface{})
+ if steps, stepsFormatOk := u.([]interface{}); stepsFormatOk {
+ for _, raw := range steps {
+ if step, stepFormatOk := raw.(map[interface{}]interface{}); stepFormatOk {
- for _, raw := range steps {
- step := raw.(map[interface{}]interface{})
-
- if len(step) != 1 {
- return fmt.Errorf("unable to parse step: %v", step)
- }
-
- for k, v := range step {
- switch kt := k.(type) {
- case fmt.Stringer:
- if err := i.parseStep(kt.String(), v, meta); err != nil {
- return err
+ if len(step) != 1 {
+ return fmt.Errorf("unable to parse step: %v", step)
}
- case string:
- if err := i.parseStep(kt, v, meta); err != nil {
- return err
+
+ for k, v := range step {
+ switch kt := k.(type) {
+ case fmt.Stringer:
+ if err := i.parseStep(kt.String(), v, meta); err != nil {
+ return err
+ }
+ case string:
+ if err := i.parseStep(kt, v, meta); err != nil {
+ return err
+ }
+ default:
+ return fmt.Errorf("unknown key type: %v, step: %v", k, step)
+ }
}
- default:
- return fmt.Errorf("unknown key type: %v, step: %v", k, step)
}
}
}
}
if u, ok := t["uri"]; ok {
- maybeURI = u.(string)
+ if v, isString := u.(string); isString {
+ maybeURI = v
+ }
}
if _, ok := t["language"]; ok {
diff --git a/pkg/util/source/inspector_yaml_test.go b/pkg/util/source/inspector_yaml_test.go
index aedb20d..f866f6f 100644
--- a/pkg/util/source/inspector_yaml_test.go
+++ b/pkg/util/source/inspector_yaml_test.go
@@ -62,6 +62,13 @@ const YAMLRouteTransformer = `
uri: knative:endpoint/service
`
+const YAMLInvalid = `
+- from:
+ uri: knative:endpoint/default
+ steps:
+ - "log:out"
+`
+
func TestYAMLDependencies(t *testing.T) {
tests := []struct {
name string
@@ -89,6 +96,13 @@ func TestYAMLDependencies(t *testing.T) {
`mvn:org.apache.camel.k:camel-k-knative-consumer`,
},
},
+ {
+ name: "invalid",
+ source: YAMLInvalid,
+ dependencies: []string{
+ `mvn:org.apache.camel.k:camel-k-knative-consumer`,
+ },
+ },
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {