|
1 | 1 | package scaleway
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + "github.com/aws/aws-sdk-go/aws" |
| 5 | + "github.com/aws/aws-sdk-go/aws/credentials" |
| 6 | + "github.com/aws/aws-sdk-go/aws/session" |
4 | 7 | "github.com/aws/aws-sdk-go/service/s3"
|
| 8 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" |
| 9 | + "github.com/scaleway/scaleway-sdk-go/scw" |
5 | 10 | )
|
6 | 11 |
|
| 12 | +func newS3Client(region, accessKey, secretKey string) (*s3.S3, error) { |
| 13 | + config := &aws.Config{} |
| 14 | + config.WithRegion(region) |
| 15 | + config.WithCredentials(credentials.NewStaticCredentials(accessKey, secretKey, "")) |
| 16 | + config.WithEndpoint("https://s3." + region + ".scw.cloud") |
| 17 | + |
| 18 | + s, err := session.NewSession(config) |
| 19 | + if err != nil { |
| 20 | + return nil, err |
| 21 | + } |
| 22 | + return s3.New(s), nil |
| 23 | +} |
| 24 | + |
| 25 | +func newS3ClientFromMeta(meta *Meta) (*s3.S3, error) { |
| 26 | + region, _ := meta.scwClient.GetDefaultRegion() |
| 27 | + accessKey, _ := meta.scwClient.GetAccessKey() |
| 28 | + secretKey, _ := meta.scwClient.GetSecretKey() |
| 29 | + return newS3Client(region.String(), accessKey, secretKey) |
| 30 | +} |
| 31 | + |
| 32 | +func s3ClientWithRegion(d *schema.ResourceData, m interface{}) (*s3.S3, scw.Region, error) { |
| 33 | + meta := m.(*Meta) |
| 34 | + region, err := extractRegion(d, meta) |
| 35 | + if err != nil { |
| 36 | + return nil, "", err |
| 37 | + } |
| 38 | + |
| 39 | + accessKey, _ := meta.scwClient.GetAccessKey() |
| 40 | + secretKey, _ := meta.scwClient.GetSecretKey() |
| 41 | + |
| 42 | + s3Client, err := newS3Client(region.String(), accessKey, secretKey) |
| 43 | + if err != nil { |
| 44 | + return nil, "", err |
| 45 | + } |
| 46 | + |
| 47 | + return s3Client, region, err |
| 48 | +} |
| 49 | + |
| 50 | +func s3ClientWithRegionAndName(m interface{}, name string) (*s3.S3, scw.Region, string, error) { |
| 51 | + meta := m.(*Meta) |
| 52 | + region, name, err := parseRegionalID(name) |
| 53 | + if err != nil { |
| 54 | + return nil, "", name, err |
| 55 | + } |
| 56 | + accessKey, _ := meta.scwClient.GetAccessKey() |
| 57 | + secretKey, _ := meta.scwClient.GetSecretKey() |
| 58 | + s3Client, err := newS3Client(region.String(), accessKey, secretKey) |
| 59 | + if err != nil { |
| 60 | + return nil, "", "", err |
| 61 | + } |
| 62 | + return s3Client, region, name, err |
| 63 | +} |
| 64 | + |
7 | 65 | func flattenObjectBucketTags(tagsSet []*s3.Tag) map[string]interface{} {
|
8 | 66 | tags := map[string]interface{}{}
|
9 | 67 |
|
|
0 commit comments