Skip to content

Commit

Permalink
chore: add check for semver for clickhouse for aws session token support
Browse files Browse the repository at this point in the history
  • Loading branch information
iamKunalGupta committed Mar 20, 2024
1 parent adce418 commit c45d1ae
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions flow/connectors/clickhouse/clickhouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"database/sql"
"errors"
"fmt"
"golang.org/x/mod/semver"

Check failure on line 9 in flow/connectors/clickhouse/clickhouse.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s prefix(github.com/PeerDB-io) -s default (gci)
"net/url"
"os"
"strings"

Check failure on line 12 in flow/connectors/clickhouse/clickhouse.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed (gofumpt)
Expand Down Expand Up @@ -138,6 +139,39 @@ func NewClickhouseConnector(
Provider: credentialsProvider,
BucketPath: awsBucketPath,
}
credentials, err := credentialsProvider.Retrieve(ctx)
// TODO finish and test this flow when a compatible ClickHouse version is available
if credentials.AWS.SessionToken != "" {
minSupportedClickhouseVersions := []string{
// TODO versions having
// https://github.com/ClickHouse/ClickHouse/commit/d045ab150ed5659f143beca5e50d0b72dae3bf78
}
clickHouseVersionRow := database.QueryRowContext(ctx, "SELECT version()")
var clickHouseVersion string
err := clickHouseVersionRow.Scan(&clickHouseVersionRow)
if err != nil {
return nil, fmt.Errorf("failed to query clickhouse version: %w", err)
}
supportsSessionToken := false
for _, minSupportedVersion := range minSupportedClickhouseVersions {
minSupportedMajor := semver.Major(minSupportedVersion)
currentClickHouseMajor := semver.Major(clickHouseVersion)
// We are in the same major version, now check if we are ahead of the minor version having the change
if semver.Compare(minSupportedMajor, currentClickHouseMajor) == 0 {
if semver.Compare(minSupportedMajor, clickHouseVersion) <= 0 {
supportsSessionToken = true
break
}
}
}
if !supportsSessionToken {
return nil, fmt.Errorf("please provide AWS access credentials explicitly or upgrade to version >= %v, current version is %s", minSupportedClickhouseVersions, clickHouseVersion)

Check failure on line 168 in flow/connectors/clickhouse/clickhouse.go

View workflow job for this annotation

GitHub Actions / lint

line is 188 characters (lll)
}
}

if err != nil {
return nil, err
}

validateErr := ValidateS3(ctx, &clickHouseS3CredentialsNew)
if validateErr != nil {
Expand Down

0 comments on commit c45d1ae

Please sign in to comment.