You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by pc...@apache.org on 2023/04/26 08:51:34 UTC

[camel-k] 18/18: feat: error handler validation

This is an automated email from the ASF dual-hosted git repository.

pcongiusti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit 2b7280f7fa79691048001e6a0437064db882f63e
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Tue Apr 25 09:50:56 2023 +0200

    feat: error handler validation
---
 pkg/apis/camel/v1/error_handler_types_support.go | 15 +++++++++++++++
 pkg/controller/kameletbinding/error_handler.go   |  6 ++++--
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/pkg/apis/camel/v1/error_handler_types_support.go b/pkg/apis/camel/v1/error_handler_types_support.go
index a0aa93cd4..c7bd7d0b0 100644
--- a/pkg/apis/camel/v1/error_handler_types_support.go
+++ b/pkg/apis/camel/v1/error_handler_types_support.go
@@ -19,6 +19,7 @@ package v1
 
 import (
 	"encoding/json"
+	"fmt"
 )
 
 // +kubebuilder:object:generate=false
@@ -28,6 +29,7 @@ type ErrorHandler interface {
 	Type() ErrorHandlerType
 	Endpoint() *Endpoint
 	Configuration() (map[string]interface{}, error)
+	Validate() error
 }
 
 // baseErrorHandler is the base used for the Error Handler hierarchy
@@ -49,6 +51,11 @@ func (e baseErrorHandler) Configuration() (map[string]interface{}, error) {
 	return nil, nil
 }
 
+// Validate --
+func (e baseErrorHandler) Validate() error {
+	return nil
+}
+
 // ErrorHandlerNone --
 type ErrorHandlerNone struct {
 	baseErrorHandler
@@ -126,3 +133,11 @@ func (e ErrorHandlerSink) Configuration() (map[string]interface{}, error) {
 
 	return properties, err
 }
+
+// Validate --
+func (e ErrorHandlerSink) Validate() error {
+	if e.DLCEndpoint == nil {
+		return fmt.Errorf("Missing endpoint in Error Handler Sink")
+	}
+	return nil
+}
diff --git a/pkg/controller/kameletbinding/error_handler.go b/pkg/controller/kameletbinding/error_handler.go
index 571934a1a..2c1ee036a 100644
--- a/pkg/controller/kameletbinding/error_handler.go
+++ b/pkg/controller/kameletbinding/error_handler.go
@@ -79,8 +79,10 @@ func parseErrorHandler(rawMessage v1alpha1.RawMessage) (v1alpha1.ErrorHandler, e
 			return nil, errors.Errorf("Unknown error handler type %s", errHandlType)
 		}
 
-		err := json.Unmarshal(errHandlValue, dst)
-		if err != nil {
+		if err = json.Unmarshal(errHandlValue, dst); err != nil {
+			return nil, err
+		}
+		if err = dst.Validate(); err != nil {
 			return nil, err
 		}