]> git.immae.eu Git - github/fretlink/terraform-provider-statuscake.git/blob - vendor/github.com/hashicorp/go-getter/detect_gcs.go
Upgrade to 0.12
[github/fretlink/terraform-provider-statuscake.git] / vendor / github.com / hashicorp / go-getter / detect_gcs.go
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 }