aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/github.com/hashicorp/go-getter/get_s3.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/hashicorp/go-getter/get_s3.go')
-rw-r--r--vendor/github.com/hashicorp/go-getter/get_s3.go75
1 files changed, 51 insertions, 24 deletions
diff --git a/vendor/github.com/hashicorp/go-getter/get_s3.go b/vendor/github.com/hashicorp/go-getter/get_s3.go
index d3bffeb..ebb3217 100644
--- a/vendor/github.com/hashicorp/go-getter/get_s3.go
+++ b/vendor/github.com/hashicorp/go-getter/get_s3.go
@@ -28,7 +28,7 @@ func (g *S3Getter) ClientMode(u *url.URL) (ClientMode, error) {
28 } 28 }
29 29
30 // Create client config 30 // Create client config
31 config := g.getAWSConfig(region, creds) 31 config := g.getAWSConfig(region, u, creds)
32 sess := session.New(config) 32 sess := session.New(config)
33 client := s3.New(sess) 33 client := s3.New(sess)
34 34
@@ -84,7 +84,7 @@ func (g *S3Getter) Get(dst string, u *url.URL) error {
84 return err 84 return err
85 } 85 }
86 86
87 config := g.getAWSConfig(region, creds) 87 config := g.getAWSConfig(region, u, creds)
88 sess := session.New(config) 88 sess := session.New(config)
89 client := s3.New(sess) 89 client := s3.New(sess)
90 90
@@ -139,7 +139,7 @@ func (g *S3Getter) GetFile(dst string, u *url.URL) error {
139 return err 139 return err
140 } 140 }
141 141
142 config := g.getAWSConfig(region, creds) 142 config := g.getAWSConfig(region, u, creds)
143 sess := session.New(config) 143 sess := session.New(config)
144 client := s3.New(sess) 144 client := s3.New(sess)
145 return g.getObject(client, dst, bucket, path, version) 145 return g.getObject(client, dst, bucket, path, version)
@@ -174,7 +174,7 @@ func (g *S3Getter) getObject(client *s3.S3, dst, bucket, key, version string) er
174 return err 174 return err
175} 175}
176 176
177func (g *S3Getter) getAWSConfig(region string, creds *credentials.Credentials) *aws.Config { 177func (g *S3Getter) getAWSConfig(region string, url *url.URL, creds *credentials.Credentials) *aws.Config {
178 conf := &aws.Config{} 178 conf := &aws.Config{}
179 if creds == nil { 179 if creds == nil {
180 // Grab the metadata URL 180 // Grab the metadata URL
@@ -195,6 +195,14 @@ func (g *S3Getter) getAWSConfig(region string, creds *credentials.Credentials) *
195 }) 195 })
196 } 196 }
197 197
198 if creds != nil {
199 conf.Endpoint = &url.Host
200 conf.S3ForcePathStyle = aws.Bool(true)
201 if url.Scheme == "http" {
202 conf.DisableSSL = aws.Bool(true)
203 }
204 }
205
198 conf.Credentials = creds 206 conf.Credentials = creds
199 if region != "" { 207 if region != "" {
200 conf.Region = aws.String(region) 208 conf.Region = aws.String(region)
@@ -204,29 +212,48 @@ func (g *S3Getter) getAWSConfig(region string, creds *credentials.Credentials) *
204} 212}
205 213
206func (g *S3Getter) parseUrl(u *url.URL) (region, bucket, path, version string, creds *credentials.Credentials, err error) { 214func (g *S3Getter) parseUrl(u *url.URL) (region, bucket, path, version string, creds *credentials.Credentials, err error) {
207 // Expected host style: s3.amazonaws.com. They always have 3 parts, 215 // This just check whether we are dealing with S3 or
208 // although the first may differ if we're accessing a specific region. 216 // any other S3 compliant service. S3 has a predictable
209 hostParts := strings.Split(u.Host, ".") 217 // url as others do not
210 if len(hostParts) != 3 { 218 if strings.Contains(u.Host, "amazonaws.com") {
211 err = fmt.Errorf("URL is not a valid S3 URL") 219 // Expected host style: s3.amazonaws.com. They always have 3 parts,
212 return 220 // although the first may differ if we're accessing a specific region.
213 } 221 hostParts := strings.Split(u.Host, ".")
222 if len(hostParts) != 3 {
223 err = fmt.Errorf("URL is not a valid S3 URL")
224 return
225 }
214 226
215 // Parse the region out of the first part of the host 227 // Parse the region out of the first part of the host
216 region = strings.TrimPrefix(strings.TrimPrefix(hostParts[0], "s3-"), "s3") 228 region = strings.TrimPrefix(strings.TrimPrefix(hostParts[0], "s3-"), "s3")
217 if region == "" { 229 if region == "" {
218 region = "us-east-1" 230 region = "us-east-1"
219 } 231 }
220 232
221 pathParts := strings.SplitN(u.Path, "/", 3) 233 pathParts := strings.SplitN(u.Path, "/", 3)
222 if len(pathParts) != 3 { 234 if len(pathParts) != 3 {
223 err = fmt.Errorf("URL is not a valid S3 URL") 235 err = fmt.Errorf("URL is not a valid S3 URL")
224 return 236 return
225 } 237 }
238
239 bucket = pathParts[1]
240 path = pathParts[2]
241 version = u.Query().Get("version")
226 242
227 bucket = pathParts[1] 243 } else {
228 path = pathParts[2] 244 pathParts := strings.SplitN(u.Path, "/", 3)
229 version = u.Query().Get("version") 245 if len(pathParts) != 3 {
246 err = fmt.Errorf("URL is not a valid S3 complaint URL")
247 return
248 }
249 bucket = pathParts[1]
250 path = pathParts[2]
251 version = u.Query().Get("version")
252 region = u.Query().Get("region")
253 if region == "" {
254 region = "us-east-1"
255 }
256 }
230 257
231 _, hasAwsId := u.Query()["aws_access_key_id"] 258 _, hasAwsId := u.Query()["aws_access_key_id"]
232 _, hasAwsSecret := u.Query()["aws_access_key_secret"] 259 _, hasAwsSecret := u.Query()["aws_access_key_secret"]