Skip to content

Commit 39d8ef3

Browse files
committed
ref(*): use S3 client instead of mc CLI
1 parent 1b48115 commit 39d8ef3

7 files changed

Lines changed: 136 additions & 93 deletions

File tree

glide.lock

Lines changed: 39 additions & 43 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

glide.yaml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,15 @@ import:
2525
- package: gopkg.in/yaml.v2
2626
version: eca94c41d994ae2215d455ce578ae6e2dc6ee516
2727
- package: github.com/labstack/gommon
28-
- package: https://github.com/pborman/uuid
28+
- package: github.com/pborman/uuid
2929
- package: github.com/deis/pkg
3030
subpackages:
3131
- /time
3232
- package: github.com/codegangsta/cli
3333
version: a65b733b303f0055f8d324d805f393cd3e7a7904
34-
- package: github.com/mitchellh/goamz
34+
- package: github.com/aws/aws-sdk-go
35+
version: 87b1e60a50b09e4812dee560b33a238f67305804
36+
subpackages:
37+
- aws
38+
- aws/session
39+
- service/s3

pkg/gitreceive/build.go

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ import (
1010
"strings"
1111
"time"
1212

13+
"github.com/aws/aws-sdk-go/service/s3"
1314
"github.com/deis/builder/pkg"
1415
"github.com/deis/builder/pkg/gitreceive/log"
1516
"github.com/deis/builder/pkg/gitreceive/storage"
16-
"github.com/mitchellh/goamz/s3"
1717
"github.com/pborman/uuid"
1818
"gopkg.in/yaml.v2"
1919
)
@@ -72,11 +72,11 @@ func build(conf *Config, s3Client *s3.S3, builderKey, gitSha string) error {
7272
tmpDir := os.TempDir()
7373

7474
tarObjKey := fmt.Sprintf("home/%s/tar", slugName)
75-
tarURL := fmt.Sprintf("%s/git/%s", s3Client.S3Endpoint, tarObjKey)
75+
tarURL := fmt.Sprintf("%s/git/%s", s3Client.Endpoint, tarObjKey)
7676

7777
// this is where workflow tells slugrunner to download the slug from, so we have to tell slugbuilder to upload it to here
7878
pushObjKey := fmt.Sprintf("home/%s/push", fmt.Sprintf("%s:git-%s", appName, gitSha))
79-
pushURL := fmt.Sprintf("%s/%s", s3Client.S3Endpoint, pushObjKey)
79+
pushURL := fmt.Sprintf("%s/%s", s3Client.Endpoint, pushObjKey)
8080

8181
// Get the application config from the controller, so we can check for a custom buildpack URL
8282
appConf, err := getAppConfig(conf, builderKey, conf.Username, appName)
@@ -125,23 +125,22 @@ func build(conf *Config, s3Client *s3.S3, builderKey, gitSha string) error {
125125
}
126126

127127
var srcManifest string
128-
if creds == nil {
129-
// both key and secret are missing, proceed with no credentials
130-
if usingDockerfile {
131-
srcManifest = "/etc/deis-dockerbuilder-no-creds.yaml"
132-
} else {
133-
srcManifest = "/etc/deis-slugbuilder-no-creds.yaml"
134-
}
135-
} else if err == nil {
128+
129+
creds := storage.CredsOK()
130+
if creds {
136131
// both key and secret are in place, so proceed with credentials
137132
if usingDockerfile {
138133
srcManifest = "/etc/deis-dockerbuilder.yaml"
139134
} else {
140135
srcManifest = "/etc/deis-slugbuilder.yaml"
141136
}
142-
} else if err != nil {
143-
// unexpected error, fail
144-
return fmt.Errorf("unexpected error (%s)", err)
137+
} else {
138+
// both key and secret are missing, proceed with no credentials
139+
if usingDockerfile {
140+
srcManifest = "/etc/deis-dockerbuilder-no-creds.yaml"
141+
} else {
142+
srcManifest = "/etc/deis-slugbuilder-no-creds.yaml"
143+
}
145144
}
146145

147146
fileBytes, err := ioutil.ReadFile(srcManifest)
@@ -181,7 +180,7 @@ func build(conf *Config, s3Client *s3.S3, builderKey, gitSha string) error {
181180
return fmt.Errorf("opening %s for read (%s)", appTgz, err)
182181
}
183182
if err := storage.UploadObject(s3Client, bucketName, tarObjKey, appTgzReader); err != nil {
184-
return fmt.Errorf("uploading %s to %s/%s (%s)", absAppTgz, bucketName, tarObjKey, err)
183+
return fmt.Errorf("uploading %s to %s/%s (%v)", absAppTgz, bucketName, tarObjKey, err)
185184
}
186185

187186
log.Info("Starting build... but first, coffee!")

pkg/gitreceive/storage/auth.go

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"os"
77
"strings"
88

9-
"github.com/mitchellh/goamz/aws"
9+
"github.com/aws/aws-sdk-go/aws/credentials"
1010
)
1111

1212
const (
@@ -17,14 +17,14 @@ const (
1717
var (
1818
errMissingKey = fmt.Errorf("missing %s", accessKeyIDFile)
1919
errMissingSecret = fmt.Errorf("missing %s", accessSecretKeyFile)
20-
emptyAuth = &aws.Auth{}
20+
emptyAuth = credentials.AnonymousCredentials
2121
)
2222

23-
// getCreds gets storage credentials from accessKeyIDFile and accessSecretKeyFile.
23+
// getAuth gets storage credentials from accessKeyIDFile and accessSecretKeyFile.
2424
// if a key exists but not a secret, or vice-versa, returns an error.
2525
// if both don't exist returns emptyAuth.
2626
// otherwise returns a valid auth
27-
func getAuth() (*aws.Auth, error) {
27+
func getAuth() (*credentials.Credentials, error) {
2828
accessKeyIDBytes, accessKeyErr := ioutil.ReadFile(accessKeyIDFile)
2929
accessSecretKeyBytes, accessSecretKeyErr := ioutil.ReadFile(accessSecretKeyFile)
3030
if accessKeyErr == os.ErrNotExist && accessSecretKeyErr == os.ErrNotExist {
@@ -37,8 +37,22 @@ func getAuth() (*aws.Auth, error) {
3737
return nil, errMissingSecret
3838
}
3939

40-
return &aws.Auth{
41-
AccessKey: strings.TrimSpace(string(accessKeyIDBytes)),
42-
SecretKey: strings.TrimSpace(string(accessSecretKeyBytes)),
43-
}, nil
40+
id := strings.TrimSpace(string(accessKeyIDBytes))
41+
secret := strings.TrimSpace(string(accessSecretKeyBytes))
42+
return credentials.NewStaticCredentials(id, secret, ""), nil
43+
}
44+
45+
// CredsOK checks if the required credentials to make a request exist
46+
func CredsOK() bool {
47+
cred, err := getAuth()
48+
if err != nil {
49+
return false
50+
}
51+
52+
auth, _ := cred.Get()
53+
if auth.AccessKeyID == "" && auth.SecretAccessKey == "" {
54+
return false
55+
}
56+
57+
return true
4458
}

0 commit comments

Comments
 (0)