From d9354738b608ac0fd3855bab7d2955aa83dc6367 Mon Sep 17 00:00:00 2001 From: "jan.kaifer" Date: Tue, 15 Oct 2024 12:24:41 +0000 Subject: [PATCH] Feat: use separate config for s3 bucket configuration for result download from s3 --- go/config.go | 17 +++++++++++++++++ go/errors.go | 1 + go/rows.go | 2 +- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/go/config.go b/go/config.go index fed8b55..ce499b7 100644 --- a/go/config.go +++ b/go/config.go @@ -213,6 +213,23 @@ func (c *Config) GetS3ResultPrefix() string { return GetFromEnvVal(s3ResultPrefixEnvKey) } +// SetS3OutputBucket is setter for S3 output bucket +func (c *Config) SetS3OutputBucket(o string) error { + if len(o) == 0 { + return ErrConfigS3OutputBucket + } + c.values.Set("s3_output_bucket", o) + return nil +} + +// GetS3OutputBucket is getter of s3 output bucket +func (c *Config) GetS3OutputBucket() string { + if val := c.values.Get("s3_output_bucket"); val != "" { + return val + } + return "" +} + // SetUser is a setter of User. func (c *Config) SetUser(o string) { c.dsn.User = url.UserPassword(o, "") diff --git a/go/errors.go b/go/errors.go index 2e75496..a59e5e5 100644 --- a/go/errors.go +++ b/go/errors.go @@ -32,6 +32,7 @@ var ( ErrConfigOutputLocation = errors.New("output location must starts with s3") ErrConfigRegion = errors.New("region is required") ErrConfigS3ResultPrefix = errors.New("S3 result prefix is required") + ErrConfigS3OutputBucket = errors.New("S3 output bucket is required") ErrConfigWGPointer = errors.New("workgroup pointer is nil") ErrConfigAccessIDRequired = errors.New("AWS access ID is required") ErrConfigAccessKeyRequired = errors.New("AWS access Key is required") diff --git a/go/rows.go b/go/rows.go index 8ced5c6..9e18a5c 100644 --- a/go/rows.go +++ b/go/rows.go @@ -109,7 +109,7 @@ func (r *Rows) DownloadResultFromS3() (*csv.Reader, error) { client := s3.NewFromConfig(cfg) - bucket := r.config.GetOutputBucket() + bucket := r.config.GetS3OutputBucket() path := fmt.Sprintf("%s/%s.csv", r.config.GetS3ResultPrefix(), r.queryID) output, err := client.GetObject(context.TODO(), &s3.GetObjectInput{