Skip to content

Commit

Permalink
fixed comments
Browse files Browse the repository at this point in the history
  • Loading branch information
MathiasB committed Jun 7, 2019
1 parent c47d616 commit ae35723
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 21 deletions.
23 changes: 8 additions & 15 deletions scaleway/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ func (c *Config) Meta() (*Meta, error) {
// Deprecated Scaleway Client
deprecatedClient, err := c.GetDeprecatedClient()
if err != nil {
return nil, fmt.Errorf("error: cannot create deprecated client: %s", err)
return nil, fmt.Errorf("cannot create deprecated client: %s", err)
}
meta.deprecatedClient = deprecatedClient

s3Client, err := c.GetS3Client()
if err != nil {
return nil, fmt.Errorf("error: cannot create S3 client: %s", err)
return nil, fmt.Errorf("cannot create S3 client: %s", err)
}
meta.s3Client = s3Client

Expand Down Expand Up @@ -205,7 +205,7 @@ func (c *Config) GetS3Client() (*s3.S3, error) {
}

config := &aws.Config{}
config.WithRegion(c.getS3Region())
config.WithRegion(string(c.DefaultRegion))
config.WithCredentials(credentials.NewStaticCredentials(s3AccessKey, c.SecretKey, ""))
config.WithEndpoint(c.getS3Endpoint())

Expand All @@ -218,14 +218,9 @@ func (c *Config) GetS3Client() (*s3.S3, error) {
return s3client, nil
}

// getS3Region returns the correct S3 region for object storage based on the current region
func (c *Config) getS3Region() string {
return string(c.DefaultRegion)
}

// getS3Endpoint returns the correct S3 endpoint for object storage based on the current region
func (c *Config) getS3Endpoint() string {
return "https://s3." + c.getS3Region() + ".scw.cloud"
return "https://s3." + string(c.DefaultRegion) + ".scw.cloud"

}

Expand Down Expand Up @@ -264,26 +259,24 @@ func (c *Config) getAccessKeyFromSecretKey(scwClient *sdk.API) (string, error) {
url := "https://account.scaleway.com/tokens/" + c.SecretKey
req, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {
panic(err)
return "", err
}

res, err := scwClient.Client.Do(req)
if err != nil {
panic(err)
return "", err
}

body, err := ioutil.ReadAll(res.Body)
defer res.Body.Close()
if err != nil {
panic(err)
return "", err
}

fmt.Println(string(body))

content := &resBody{}
err = json.Unmarshal(body, content)
if err != nil {
panic(err)
return "", err
}

return content.Token.AccessKey, nil
Expand Down
7 changes: 3 additions & 4 deletions scaleway/resource_storage_object_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package scaleway

import (
"fmt"
"log"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
Expand Down Expand Up @@ -31,7 +30,7 @@ func resourceScalewayStorageObjectBucket() *schema.Resource {
Type: schema.TypeString,
Optional: true,
Default: "private",
Description: "ACL of the bucket: either 'public-read' or 'private'. Private by default.",
Description: "ACL of the bucket: either 'public-read' or 'private'.",
},
},
}
Expand Down Expand Up @@ -66,7 +65,7 @@ func resourceScalewayStorageObjectBucketRead(d *schema.ResourceData, m interface
})
if err != nil {
if serr, ok := err.(awserr.Error); ok && serr.Code() == s3.ErrCodeNoSuchBucket {
log.Printf("[ERROR] Bucket %q was not found - removing from state!", d.Get("name").(string))
l.Errorf("Bucket %q was not found - removing from state!", d.Get("name"))
d.SetId("")
return nil
}
Expand All @@ -88,7 +87,7 @@ func resourceScalewayStorageObjectBucketUpdate(d *schema.ResourceData, m interfa
ACL: aws.String(acl),
})
if err != nil {
log.Printf("[ERROR] Couldn't update bucket ACL: %s", err)
l.Errorf("Couldn't update bucket ACL: %s", err)
return fmt.Errorf("couldn't update bucket ACL: %s", err)
}
}
Expand Down
3 changes: 1 addition & 2 deletions scaleway/resource_storage_object_bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package scaleway

import (
"fmt"
"log"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -32,7 +31,7 @@ func testSweepStorageObjectBucket(region string) error {
}

for _, bucket := range listBucketResponse.Buckets {
log.Println(*bucket.Name)
l.Debugf("Deleting %q bucket", *bucket.Name)
if strings.HasPrefix(*bucket.Name, "terraform-test") {
_, err := s3client.DeleteBucket(&s3.DeleteBucketInput{
Bucket: bucket.Name,
Expand Down

0 comments on commit ae35723

Please sign in to comment.