Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Amogh-Bharadwaj committed Feb 13, 2024
1 parent deca6fd commit 222f03f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
26 changes: 15 additions & 11 deletions flow/connectors/clickhouse/clickhouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"crypto/tls"
"database/sql"
"fmt"
"net/url"

"github.com/ClickHouse/clickhouse-go/v2"
_ "github.com/ClickHouse/clickhouse-go/v2/lib/driver"
Expand Down Expand Up @@ -95,18 +96,21 @@ func NewClickhouseConnector(
var clickhouseS3Creds *utils.ClickhouseS3Credentials
deploymentUID := shared.GetDeploymentUID()
flowName, _ := ctx.Value(shared.FlowNameKey).(string)
bucketPathSuffix := fmt.Sprintf("%s/%s", deploymentUID, flowName)
// Get S3 credentials from environment
clickhouseS3Creds = utils.GetClickhouseAWSSecrets(bucketPathSuffix)
bucketPathSuffix := fmt.Sprintf("%s/%s", url.PathEscape(deploymentUID), flowName)

// Get user provided S3 credentials
clickhouseS3Creds = &utils.ClickhouseS3Credentials{
AccessKeyID: config.AccessKeyId,
SecretAccessKey: config.SecretAccessKey,
Region: config.Region,
BucketPath: config.S3Path,
}

if clickhouseS3Creds.AccessKeyID == "" &&
clickhouseS3Creds.SecretAccessKey == "" && clickhouseS3Creds.Region == "" {
// Fallback: user provided S3 credentials
clickhouseS3Creds = &utils.ClickhouseS3Credentials{
AccessKeyID: config.AccessKeyId,
SecretAccessKey: config.SecretAccessKey,
Region: config.Region,
BucketPath: config.S3Path,
}
clickhouseS3Creds.SecretAccessKey == "" && clickhouseS3Creds.Region == "" &&
clickhouseS3Creds.BucketPath == "" {
// Fallback: Get S3 credentials from environment
clickhouseS3Creds = utils.GetClickhouseAWSSecrets(bucketPathSuffix)
}

validateErr := ValidateS3(ctx, clickhouseS3Creds)
Expand Down
4 changes: 1 addition & 3 deletions flow/connectors/utils/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package utils
import (
"fmt"
"net/http"
"net/url"
"os"
"strings"
"time"
Expand Down Expand Up @@ -86,8 +85,7 @@ func GetClickhouseAWSSecrets(bucketPathSuffix string) *ClickhouseS3Credentials {
awsSecret := os.Getenv("PEERDB_CLICKHOUSE_AWS_CREDENTIALS_AWS_SECRET_ACCESS_KEY")
awsBucketName := os.Getenv("PEERDB_CLICKHOUSE_AWS_S3_BUCKET_NAME")

escapedPathSuffix := url.PathEscape(bucketPathSuffix)
awsBucketPath := fmt.Sprintf("s3://%s/%s", awsBucketName, escapedPathSuffix)
awsBucketPath := fmt.Sprintf("s3://%s/%s", awsBucketName, bucketPathSuffix)
return &ClickhouseS3Credentials{
AccessKeyID: awsKey,
SecretAccessKey: awsSecret,
Expand Down
2 changes: 1 addition & 1 deletion ui/components/PeerForms/ClickhouseConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export default function ClickhouseForm({ settings, setter }: ConfigProps) {
.map((setting, id) => (
<RowWithTextField
key={id}
label={<Label>{setting.label} </Label>}
label={<Label>{setting.label}</Label>}
action={
<div
style={{
Expand Down

0 comments on commit 222f03f

Please sign in to comment.