Skip to content

Commit

Permalink
feat: added environment variable support to connector config (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
onurerdemiroglu authored Nov 12, 2024
1 parent 18e9177 commit 65065c4
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"errors"
"fmt"
"os"
"regexp"
"strings"

jsoniter "github.com/json-iterator/go"

Expand Down Expand Up @@ -229,6 +231,15 @@ func newConnectorConfigFromPath(path string) (*config.Connector, error) {
if err != nil {
return nil, err
}
envPattern := regexp.MustCompile(`\${([^}]+)}`)
matches := envPattern.FindAllStringSubmatch(string(file), -1)
for _, match := range matches {
envVar := match[1]
if value, exists := os.LookupEnv(envVar); exists {
updatedFile := strings.ReplaceAll(string(file), "${"+envVar+"}", value)
file = []byte(updatedFile)
}
}
var c config.Connector
err = yaml.Unmarshal(file, &c)
if err != nil {
Expand Down

0 comments on commit 65065c4

Please # to comment.