Skip to content

refactor: provider configuration #613

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
187 changes: 0 additions & 187 deletions scaleway/config.go

This file was deleted.

57 changes: 0 additions & 57 deletions scaleway/helper_storage_object.go

This file was deleted.

1 change: 0 additions & 1 deletion scaleway/helpers_k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ type KubeconfigStruct struct {
}

const (
K8SClusterWaitForReadyTimeout = 10 * time.Minute
K8SClusterWaitForPoolRequiredTimeout = 10 * time.Minute
K8SClusterWaitForDeletedTimeout = 10 * time.Minute
K8SPoolWaitForReadyTimeout = 10 * time.Minute
Expand Down
58 changes: 58 additions & 0 deletions scaleway/helpers_object.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,67 @@
package scaleway

import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/scaleway/scaleway-sdk-go/scw"
)

func newS3Client(region, accessKey, secretKey string) (*s3.S3, error) {
config := &aws.Config{}
config.WithRegion(region)
config.WithCredentials(credentials.NewStaticCredentials(accessKey, secretKey, ""))
config.WithEndpoint("https://s3." + region + ".scw.cloud")

s, err := session.NewSession(config)
if err != nil {
return nil, err
}
return s3.New(s), nil
}

func newS3ClientFromMeta(meta *Meta) (*s3.S3, error) {
region, _ := meta.scwClient.GetDefaultRegion()
accessKey, _ := meta.scwClient.GetAccessKey()
secretKey, _ := meta.scwClient.GetSecretKey()
return newS3Client(region.String(), accessKey, secretKey)
}

func s3ClientWithRegion(d *schema.ResourceData, m interface{}) (*s3.S3, scw.Region, error) {
meta := m.(*Meta)
region, err := extractRegion(d, meta)
if err != nil {
return nil, "", err
}

accessKey, _ := meta.scwClient.GetAccessKey()
secretKey, _ := meta.scwClient.GetSecretKey()

s3Client, err := newS3Client(region.String(), accessKey, secretKey)
if err != nil {
return nil, "", err
}

return s3Client, region, err
}

func s3ClientWithRegionAndName(m interface{}, name string) (*s3.S3, scw.Region, string, error) {
meta := m.(*Meta)
region, name, err := parseRegionalID(name)
if err != nil {
return nil, "", name, err
}
accessKey, _ := meta.scwClient.GetAccessKey()
secretKey, _ := meta.scwClient.GetSecretKey()
s3Client, err := newS3Client(region.String(), accessKey, secretKey)
if err != nil {
return nil, "", "", err
}
return s3Client, region, name, err
}

func flattenObjectBucketTags(tagsSet []*s3.Tag) map[string]interface{} {
tags := map[string]interface{}{}

Expand Down
6 changes: 0 additions & 6 deletions scaleway/helpers_rdb.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
package scaleway

import (
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/scaleway/scaleway-sdk-go/api/rdb/v1"
"github.com/scaleway/scaleway-sdk-go/scw"
)

const (
RdbWaitForTimeout = 10 * time.Minute
)

// rdbAPIWithRegion returns a new lb API and the region for a Create request
func rdbAPIWithRegion(d *schema.ResourceData, m interface{}) (*rdb.API, scw.Region, error) {
meta := m.(*Meta)
Expand Down
Loading