diff options
author | Jake Champlin <jake.champlin.27@gmail.com> | 2017-06-06 12:40:07 -0400 |
---|---|---|
committer | Jake Champlin <jake.champlin.27@gmail.com> | 2017-06-06 12:40:07 -0400 |
commit | bae9f6d2fd5eb5bc80929bd393932b23f14d7c93 (patch) | |
tree | ca9ab12a7d78b1fc27a8f734729081357ce6d252 /vendor/github.com/hashicorp/go-getter/detect_s3.go | |
parent | 254c495b6bebab3fb72a243c4bce858d79e6ee99 (diff) | |
download | terraform-provider-statuscake-bae9f6d2fd5eb5bc80929bd393932b23f14d7c93.tar.gz terraform-provider-statuscake-bae9f6d2fd5eb5bc80929bd393932b23f14d7c93.tar.zst terraform-provider-statuscake-bae9f6d2fd5eb5bc80929bd393932b23f14d7c93.zip |
Initial transfer of provider code
Diffstat (limited to 'vendor/github.com/hashicorp/go-getter/detect_s3.go')
-rw-r--r-- | vendor/github.com/hashicorp/go-getter/detect_s3.go | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/vendor/github.com/hashicorp/go-getter/detect_s3.go b/vendor/github.com/hashicorp/go-getter/detect_s3.go new file mode 100644 index 0000000..8e0f4a0 --- /dev/null +++ b/vendor/github.com/hashicorp/go-getter/detect_s3.go | |||
@@ -0,0 +1,61 @@ | |||
1 | package getter | ||
2 | |||
3 | import ( | ||
4 | "fmt" | ||
5 | "net/url" | ||
6 | "strings" | ||
7 | ) | ||
8 | |||
9 | // S3Detector implements Detector to detect S3 URLs and turn | ||
10 | // them into URLs that the S3 getter can understand. | ||
11 | type S3Detector struct{} | ||
12 | |||
13 | func (d *S3Detector) Detect(src, _ string) (string, bool, error) { | ||
14 | if len(src) == 0 { | ||
15 | return "", false, nil | ||
16 | } | ||
17 | |||
18 | if strings.Contains(src, ".amazonaws.com/") { | ||
19 | return d.detectHTTP(src) | ||
20 | } | ||
21 | |||
22 | return "", false, nil | ||
23 | } | ||
24 | |||
25 | func (d *S3Detector) detectHTTP(src string) (string, bool, error) { | ||
26 | parts := strings.Split(src, "/") | ||
27 | if len(parts) < 2 { | ||
28 | return "", false, fmt.Errorf( | ||
29 | "URL is not a valid S3 URL") | ||
30 | } | ||
31 | |||
32 | hostParts := strings.Split(parts[0], ".") | ||
33 | if len(hostParts) == 3 { | ||
34 | return d.detectPathStyle(hostParts[0], parts[1:]) | ||
35 | } else if len(hostParts) == 4 { | ||
36 | return d.detectVhostStyle(hostParts[1], hostParts[0], parts[1:]) | ||
37 | } else { | ||
38 | return "", false, fmt.Errorf( | ||
39 | "URL is not a valid S3 URL") | ||
40 | } | ||
41 | } | ||
42 | |||
43 | func (d *S3Detector) detectPathStyle(region string, parts []string) (string, bool, error) { | ||
44 | urlStr := fmt.Sprintf("https://%s.amazonaws.com/%s", region, strings.Join(parts, "/")) | ||
45 | url, err := url.Parse(urlStr) | ||
46 | if err != nil { | ||
47 | return "", false, fmt.Errorf("error parsing S3 URL: %s", err) | ||
48 | } | ||
49 | |||
50 | return "s3::" + url.String(), true, nil | ||
51 | } | ||
52 | |||
53 | func (d *S3Detector) detectVhostStyle(region, bucket string, parts []string) (string, bool, error) { | ||
54 | urlStr := fmt.Sprintf("https://%s.amazonaws.com/%s/%s", region, bucket, strings.Join(parts, "/")) | ||
55 | url, err := url.Parse(urlStr) | ||
56 | if err != nil { | ||
57 | return "", false, fmt.Errorf("error parsing S3 URL: %s", err) | ||
58 | } | ||
59 | |||
60 | return "s3::" + url.String(), true, nil | ||
61 | } | ||