Skip to content

Commit

Permalink
use listobjects
Browse files Browse the repository at this point in the history
  • Loading branch information
Amogh-Bharadwaj committed Feb 13, 2024
1 parent 9081af8 commit 0a12e51
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions flow/connectors/clickhouse/clickhouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import (
"crypto/tls"
"database/sql"
"fmt"
"log/slog"
"net/url"

"github.com/ClickHouse/clickhouse-go/v2"
_ "github.com/ClickHouse/clickhouse-go/v2/lib/driver"
"github.com/aws/aws-sdk-go-v2/service/s3"
"go.temporal.io/sdk/log"

metadataStore "github.com/PeerDB-io/peer-flow/connectors/external_metadata"
conns3 "github.com/PeerDB-io/peer-flow/connectors/s3"
"github.com/PeerDB-io/peer-flow/connectors/utils"
"github.com/PeerDB-io/peer-flow/generated/protos"
"github.com/PeerDB-io/peer-flow/logger"
Expand All @@ -39,9 +40,18 @@ func ValidateS3(ctx context.Context, creds *utils.ClickhouseS3Credentials) error
return fmt.Errorf("failed to create S3 client: %w", err)
}

validErr := conns3.ValidCheck(ctx, s3Client, creds.BucketPath, nil)
if validErr != nil {
return validErr
object, err := utils.NewS3BucketAndPrefix(creds.BucketPath)
if err != nil {
return fmt.Errorf("failed to create S3 bucket and prefix: %w", err)
}

slog.Info(fmt.Sprintf("Validating S3 bucke: %s", object.Bucket))
_, listErr := s3Client.ListObjectsV2(ctx, &s3.ListObjectsV2Input{
Bucket: &object.Bucket,
},
)
if listErr != nil {
return fmt.Errorf("failed to list objects: %w", listErr)
}

return nil
Expand Down

0 comments on commit 0a12e51

Please sign in to comment.