Skip to content

Commit

Permalink
Merge pull request #211 from deepgoel17/main
Browse files Browse the repository at this point in the history
bug fix for override.HandleGenericConnectorTask using config var
  • Loading branch information
srinandan authored Mar 8, 2024
2 parents c0a9527 + 0972c00 commit 207bfac
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 14 deletions.
6 changes: 3 additions & 3 deletions internal/client/integrations/integrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -1460,10 +1460,10 @@ func getConfigParamValue(name string, configParams []parameterConfig) string {
name = strings.ReplaceAll(name, "$", "")
for _, configParam := range configParams {
if configParam.Parameter.Key == name {
if configParam.Parameter.DefaultValue != nil && configParam.Parameter.DefaultValue.StringValue != nil {
return *configParam.Parameter.DefaultValue.StringValue
} else if configParam.Value != nil && configParam.Value.StringValue != nil {
if configParam.Value != nil && configParam.Value.StringValue != nil {
return *configParam.Value.StringValue
} else if configParam.Parameter.DefaultValue != nil && configParam.Parameter.DefaultValue.StringValue != nil {
return *configParam.Parameter.DefaultValue.StringValue
}
}
}
Expand Down
59 changes: 48 additions & 11 deletions internal/client/integrations/overrides.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ package integrations

import (
"encoding/json"
"errors"
"fmt"
"regexp"
"strings"

"internal/apiclient"
Expand Down Expand Up @@ -265,7 +267,7 @@ func extractOverrides(iversion integrationVersion) (overrides, error) {

for _, task := range iversion.TaskConfigs {
if task.Task == "GenericConnectorTask" {
if err := handleGenericConnectorTask(task, &taskOverrides); err != nil {
if err := handleGenericConnectorTask(task, &taskOverrides, iversion.IntegrationConfigParameters); err != nil {
return taskOverrides, err
}
} else if task.Task == "GenericRestV2Task" {
Expand Down Expand Up @@ -395,13 +397,30 @@ func handleCloudFunctionTask(taskConfig taskconfig, taskOverrides *overrides) er
return nil
}

func handleGenericConnectorTask(taskConfig taskconfig, taskOverrides *overrides) error {
func handleGenericConnectorTask(taskConfig taskconfig, taskOverrides *overrides, iconfigParam []parameterConfig) error {
co := connectionoverrides{}
co.TaskId = taskConfig.TaskId
co.Task = taskConfig.Task

cparams, ok := taskConfig.Parameters["config"]
if (eventparameter{}) != cparams && ok {
connectionNameparams, okConnectionName := taskConfig.Parameters["connectionName"]

if !ok && !okConnectionName {
return nil
}
if connectionNameparams.Key == "connectionName" {
if connectionNameparams.Value.StringValue != nil {
connectionName, err := getConnectionStringFromConnectionName(*connectionNameparams.Value.StringValue, iconfigParam)
if err != nil {
return err
}
parts := strings.Split(connectionName, "/")
connName := parts[len(parts)-1]
co.Parameters.ConnectionName = connName

}

} else if (eventparameter{}) != cparams && ok {
if cparams.Value.JsonValue != nil {
cd, err := getConnectionDetails(*cparams.Value.JsonValue)
if err != nil {
Expand All @@ -411,16 +430,9 @@ func handleGenericConnectorTask(taskConfig taskconfig, taskOverrides *overrides)
parts := strings.Split(cd.Connection.ConnectionName, "/")
connName := parts[len(parts)-1]
co.Parameters.ConnectionName = connName

taskOverrides.ConnectionOverrides = append(taskOverrides.ConnectionOverrides, co)
}
}

cconnversion, ok := taskConfig.Parameters["connectionVersion"]
if (eventparameter{}) != cconnversion && ok {
co.Parameters.ConnectionName = strings.Split(*cconnversion.Value.StringValue, "/")[7]
taskOverrides.ConnectionOverrides = append(taskOverrides.ConnectionOverrides, co)
}
taskOverrides.ConnectionOverrides = append(taskOverrides.ConnectionOverrides, co)

return nil
}
Expand Down Expand Up @@ -504,3 +516,28 @@ func stringifyValue(cd connectiondetails) (string, error) {
}
return string(jsonValue), nil
}

// getConnectionStringFromConnectionName
func getConnectionStringFromConnectionName(connectionName string, iconfigParam []parameterConfig) (connection string, err error) {

var name string
if strings.HasPrefix(connectionName, "$`CONFIG_") {
for _, param := range iconfigParam {
if param.Parameter.Key == strings.ReplaceAll(connectionName, "$", "") {
if param.Value != nil {
name = *param.Value.StringValue
} else if param.Parameter.DefaultValue != nil {
name = *param.Parameter.DefaultValue.StringValue
}
}
}
} else {
name = connectionName
}

re := regexp.MustCompile(`projects/(.*)/locations/(.*)/connections/(.*)`)
if !re.MatchString(name) {
return "", errors.New("Connection Name is not valid. Connection name should be in the format: projects/{projectId}/locations/{locationId}/connections/{connectionId}")
}
return name, nil
}

0 comments on commit 207bfac

Please sign in to comment.