Skip to content

Commit

Permalink
fix(transform): Update Validation for EnrichHTTP Transforms
Browse files Browse the repository at this point in the history
  • Loading branch information
jshlbrd committed Jul 27, 2024
1 parent 5e93e52 commit 2fde138
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 19 deletions.
12 changes: 3 additions & 9 deletions transform/enrich_http_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,6 @@ func (c *enrichHTTPGetConfig) Decode(in interface{}) error {
}

func (c *enrichHTTPGetConfig) Validate() error {
if c.Object.SourceKey == "" && c.Object.TargetKey != "" {
return fmt.Errorf("object_source_key: %v", errors.ErrMissingRequiredOption)
}

if c.Object.SourceKey != "" && c.Object.TargetKey == "" {
return fmt.Errorf("object_target_key: %v", errors.ErrMissingRequiredOption)
}

if c.URL == "" {
return fmt.Errorf("url: %v", errors.ErrMissingRequiredOption)
}
Expand Down Expand Up @@ -111,7 +103,7 @@ func (tf *enrichHTTPGet) Transform(ctx context.Context, msg *message.Message) ([
// - Data-based interpolation, the URL is interpolated
// using the data handling pattern.
//
// The URL is always interpolated with the substring ${data}.
// The URL is always interpolated with the substring ${DATA}.
url := tf.conf.URL
if strings.Contains(url, enrichHTTPInterp) {
if tf.conf.Object.SourceKey != "" {
Expand Down Expand Up @@ -143,6 +135,8 @@ func (tf *enrichHTTPGet) Transform(ctx context.Context, msg *message.Message) ([
return nil, fmt.Errorf("transform %s: %v", tf.conf.ID, err)
}

// If TargetKey is set, then the response body is stored in the message.
// Otherwise, the response body overwrites the message data.
if tf.conf.Object.TargetKey != "" {
if err := msg.SetValue(tf.conf.Object.TargetKey, parsed); err != nil {
return nil, fmt.Errorf("transform %s: %v", tf.conf.ID, err)
Expand Down
12 changes: 2 additions & 10 deletions transform/enrich_http_post.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,6 @@ func (c *enrichHTTPPostConfig) Decode(in interface{}) error {
}

func (c *enrichHTTPPostConfig) Validate() error {
if c.Object.SourceKey == "" && c.Object.TargetKey != "" {
return fmt.Errorf("object_source_key: %v", errors.ErrMissingRequiredOption)
}

if c.Object.SourceKey != "" && c.Object.TargetKey == "" {
return fmt.Errorf("object_target_key: %v", errors.ErrMissingRequiredOption)
}

if c.URL == "" {
return fmt.Errorf("url: %v", errors.ErrMissingRequiredOption)
}
Expand Down Expand Up @@ -123,7 +115,7 @@ func (tf *enrichHTTPPost) Transform(ctx context.Context, msg *message.Message) (
// - Data-based interpolation, the URL is interpolated
// using the data handling pattern.
//
// The URL is always interpolated with the substring ${data}.
// The URL is always interpolated with the substring ${DATA}.
url := tf.conf.URL
if strings.Contains(url, enrichHTTPInterp) {
if tf.conf.Object.SourceKey != "" {
Expand Down Expand Up @@ -162,7 +154,7 @@ func (tf *enrichHTTPPost) Transform(ctx context.Context, msg *message.Message) (
return nil, fmt.Errorf("transform %s: %v", tf.conf.ID, err)
}

// If SetKey exists, then the response body is written into the message,
// If TargetKey exists, then the response body is written into the message,
// but otherwise the response is not stored and the message is returned
// as-is.
if tf.conf.Object.TargetKey != "" {
Expand Down

0 comments on commit 2fde138

Please sign in to comment.