diff options
Diffstat (limited to 'vendor/github.com/hashicorp/go-getter/detect_gcs.go')
-rw-r--r-- | vendor/github.com/hashicorp/go-getter/detect_gcs.go | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/vendor/github.com/hashicorp/go-getter/detect_gcs.go b/vendor/github.com/hashicorp/go-getter/detect_gcs.go new file mode 100644 index 0000000..1136373 --- /dev/null +++ b/vendor/github.com/hashicorp/go-getter/detect_gcs.go | |||
@@ -0,0 +1,43 @@ | |||
1 | package getter | ||
2 | |||
3 | import ( | ||
4 | "fmt" | ||
5 | "net/url" | ||
6 | "strings" | ||
7 | ) | ||
8 | |||
9 | // GCSDetector implements Detector to detect GCS URLs and turn | ||
10 | // them into URLs that the GCSGetter can understand. | ||
11 | type GCSDetector struct{} | ||
12 | |||
13 | func (d *GCSDetector) Detect(src, _ string) (string, bool, error) { | ||
14 | if len(src) == 0 { | ||
15 | return "", false, nil | ||
16 | } | ||
17 | |||
18 | if strings.Contains(src, "googleapis.com/") { | ||
19 | return d.detectHTTP(src) | ||
20 | } | ||
21 | |||
22 | return "", false, nil | ||
23 | } | ||
24 | |||
25 | func (d *GCSDetector) detectHTTP(src string) (string, bool, error) { | ||
26 | |||
27 | parts := strings.Split(src, "/") | ||
28 | if len(parts) < 5 { | ||
29 | return "", false, fmt.Errorf( | ||
30 | "URL is not a valid GCS URL") | ||
31 | } | ||
32 | version := parts[2] | ||
33 | bucket := parts[3] | ||
34 | object := strings.Join(parts[4:], "/") | ||
35 | |||
36 | url, err := url.Parse(fmt.Sprintf("https://www.googleapis.com/storage/%s/%s/%s", | ||
37 | version, bucket, object)) | ||
38 | if err != nil { | ||
39 | return "", false, fmt.Errorf("error parsing GCS URL: %s", err) | ||
40 | } | ||
41 | |||
42 | return "gcs::" + url.String(), true, nil | ||
43 | } | ||