From 0e3f15f33da1c9f4b3c06fc84f65370b913009bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Le=C5=9Bniewski?= Date: Mon, 9 Dec 2024 18:04:09 +0100 Subject: [PATCH] add possibility to set local profile to use in spec --- plugins/destination/s3/client/client.go | 9 ++++++++- .../destination/s3/client/spec/schema.json | 7 +++++++ plugins/destination/s3/client/spec/spec.go | 18 ++++++++++++++++++ .../destination/s3/docs/_authentication.md | 1 + plugins/destination/s3/docs/overview.md | 19 +++++++++++++++++++ 5 files changed, 53 insertions(+), 1 deletion(-) diff --git a/plugins/destination/s3/client/client.go b/plugins/destination/s3/client/client.go index 3820a4417043bd..c88be81177af00 100644 --- a/plugins/destination/s3/client/client.go +++ b/plugins/destination/s3/client/client.go @@ -71,7 +71,14 @@ func New(ctx context.Context, logger zerolog.Logger, s []byte, opts plugin.NewCl } c.Client = filetypesClient - cfg, err := config.LoadDefaultConfig(ctx, config.WithDefaultRegion("us-east-1")) + configFns := []func(*config.LoadOptions) error{ + config.WithDefaultRegion("us-east-1"), + } + if c.spec.LocalProfile != "" { + configFns = append(configFns, config.WithSharedConfigProfile(c.spec.LocalProfile)) + } + + cfg, err := config.LoadDefaultConfig(ctx, configFns...) if err != nil { return nil, fmt.Errorf("unable to load AWS SDK config: %w", err) } diff --git a/plugins/destination/s3/client/spec/schema.json b/plugins/destination/s3/client/spec/schema.json index 27f4cf5fe49a14..47f3e32117edf3 100644 --- a/plugins/destination/s3/client/spec/schema.json +++ b/plugins/destination/s3/client/spec/schema.json @@ -341,6 +341,13 @@ "minLength": 1, "description": "Region where bucket is located." }, + "local_profile": { + "type": "string", + "description": "[Local profile](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html) to use to authenticate this account with.\nShould be set to the name of the profile.\n\nFor example, with the following credentials file:\n\n ```ini copy\n [default]\n aws_access_key_id=xxxx\n aws_secret_access_key=xxxx\n\n [user1]\n aws_access_key_id=xxxx\n aws_secret_access_key=xxxx\n ```\n\n`local_profile` should be set to either `default` or `user1`.", + "examples": [ + "my_aws_profile" + ] + }, "path": { "type": "string", "pattern": "^[^/].*$", diff --git a/plugins/destination/s3/client/spec/spec.go b/plugins/destination/s3/client/spec/spec.go index 4d8b21f7fc7881..7508d3d6817e10 100644 --- a/plugins/destination/s3/client/spec/spec.go +++ b/plugins/destination/s3/client/spec/spec.go @@ -35,6 +35,24 @@ type Spec struct { // Region where bucket is located. Region string `json:"region,omitempty" jsonschema:"required,minLength=1"` + // [Local profile](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html) to use to authenticate this account with. + // Should be set to the name of the profile. + // + // For example, with the following credentials file: + // + // ```ini copy + // [default] + // aws_access_key_id=xxxx + // aws_secret_access_key=xxxx + // + // [user1] + // aws_access_key_id=xxxx + // aws_secret_access_key=xxxx + // ``` + // + // `local_profile` should be set to either `default` or `user1`. + LocalProfile string `json:"local_profile,omitempty" jsonschema:"example=my_aws_profile"` + // Path to where the files will be uploaded in the above bucket, for example `path/to/files/{{TABLE}}/{{UUID}}.parquet`. // The path supports the following placeholder variables: // diff --git a/plugins/destination/s3/docs/_authentication.md b/plugins/destination/s3/docs/_authentication.md index 3a8adac1ee5d7a..88cf1ccc8390e3 100644 --- a/plugins/destination/s3/docs/_authentication.md +++ b/plugins/destination/s3/docs/_authentication.md @@ -56,6 +56,7 @@ Then, you can either export the `AWS_PROFILE` environment variable (On Linux/Mac export AWS_PROFILE=myprofile ``` +You can also use the `local_profile` field in plugin configuration (can be helpful for syncing between different accounts). ### IAM Roles for AWS Compute Resources diff --git a/plugins/destination/s3/docs/overview.md b/plugins/destination/s3/docs/overview.md index cf259e242fe2ad..a4a64717d75657 100644 --- a/plugins/destination/s3/docs/overview.md +++ b/plugins/destination/s3/docs/overview.md @@ -30,6 +30,25 @@ This is the (nested) spec used by the CSV destination Plugin. Region where bucket is located. +- `local_profile` (`string`) (optional) (default: will use current credentials) + + [Local profile](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html) to use to authenticate this account with. + Please note this should be set to the name of the profile. + + For example, with the following credentials file: + + ```toml copy + [default] + aws_access_key_id=xxxx + aws_secret_access_key=xxxx + + [user1] + aws_access_key_id=xxxx + aws_secret_access_key=xxxx + ``` + + `local_profile` should be set to either `default` or `user1`. + - `path` (`string`) (required) Path to where the files will be uploaded in the above bucket, for example `path/to/files/{{TABLE}}/{{UUID}}.parquet`.