diff options
author | Nathan Dench <ndenc2@gmail.com> | 2019-05-24 15:16:44 +1000 |
---|---|---|
committer | Nathan Dench <ndenc2@gmail.com> | 2019-05-24 15:16:44 +1000 |
commit | 107c1cdb09c575aa2f61d97f48d8587eb6bada4c (patch) | |
tree | ca7d008643efc555c388baeaf1d986e0b6b3e28c /vendor/github.com/hashicorp/terraform/registry | |
parent | 844b5a68d8af4791755b8f0ad293cc99f5959183 (diff) | |
download | terraform-provider-statuscake-107c1cdb09c575aa2f61d97f48d8587eb6bada4c.tar.gz terraform-provider-statuscake-107c1cdb09c575aa2f61d97f48d8587eb6bada4c.tar.zst terraform-provider-statuscake-107c1cdb09c575aa2f61d97f48d8587eb6bada4c.zip |
Upgrade to 0.12
Diffstat (limited to 'vendor/github.com/hashicorp/terraform/registry')
6 files changed, 367 insertions, 12 deletions
diff --git a/vendor/github.com/hashicorp/terraform/registry/client.go b/vendor/github.com/hashicorp/terraform/registry/client.go index a18e6b8..93424d1 100644 --- a/vendor/github.com/hashicorp/terraform/registry/client.go +++ b/vendor/github.com/hashicorp/terraform/registry/client.go | |||
@@ -20,10 +20,11 @@ import ( | |||
20 | ) | 20 | ) |
21 | 21 | ||
22 | const ( | 22 | const ( |
23 | xTerraformGet = "X-Terraform-Get" | 23 | xTerraformGet = "X-Terraform-Get" |
24 | xTerraformVersion = "X-Terraform-Version" | 24 | xTerraformVersion = "X-Terraform-Version" |
25 | requestTimeout = 10 * time.Second | 25 | requestTimeout = 10 * time.Second |
26 | serviceID = "modules.v1" | 26 | modulesServiceID = "modules.v1" |
27 | providersServiceID = "providers.v1" | ||
27 | ) | 28 | ) |
28 | 29 | ||
29 | var tfVersion = version.String() | 30 | var tfVersion = version.String() |
@@ -58,10 +59,10 @@ func NewClient(services *disco.Disco, client *http.Client) *Client { | |||
58 | } | 59 | } |
59 | 60 | ||
60 | // Discover queries the host, and returns the url for the registry. | 61 | // Discover queries the host, and returns the url for the registry. |
61 | func (c *Client) Discover(host svchost.Hostname) (*url.URL, error) { | 62 | func (c *Client) Discover(host svchost.Hostname, serviceID string) (*url.URL, error) { |
62 | service, err := c.services.DiscoverServiceURL(host, serviceID) | 63 | service, err := c.services.DiscoverServiceURL(host, serviceID) |
63 | if err != nil { | 64 | if err != nil { |
64 | return nil, err | 65 | return nil, &ServiceUnreachableError{err} |
65 | } | 66 | } |
66 | if !strings.HasSuffix(service.Path, "/") { | 67 | if !strings.HasSuffix(service.Path, "/") { |
67 | service.Path += "/" | 68 | service.Path += "/" |
@@ -69,14 +70,14 @@ func (c *Client) Discover(host svchost.Hostname) (*url.URL, error) { | |||
69 | return service, nil | 70 | return service, nil |
70 | } | 71 | } |
71 | 72 | ||
72 | // Versions queries the registry for a module, and returns the available versions. | 73 | // ModuleVersions queries the registry for a module, and returns the available versions. |
73 | func (c *Client) Versions(module *regsrc.Module) (*response.ModuleVersions, error) { | 74 | func (c *Client) ModuleVersions(module *regsrc.Module) (*response.ModuleVersions, error) { |
74 | host, err := module.SvcHost() | 75 | host, err := module.SvcHost() |
75 | if err != nil { | 76 | if err != nil { |
76 | return nil, err | 77 | return nil, err |
77 | } | 78 | } |
78 | 79 | ||
79 | service, err := c.Discover(host) | 80 | service, err := c.Discover(host, modulesServiceID) |
80 | if err != nil { | 81 | if err != nil { |
81 | return nil, err | 82 | return nil, err |
82 | } | 83 | } |
@@ -141,15 +142,15 @@ func (c *Client) addRequestCreds(host svchost.Hostname, req *http.Request) { | |||
141 | } | 142 | } |
142 | } | 143 | } |
143 | 144 | ||
144 | // Location find the download location for a specific version module. | 145 | // ModuleLocation find the download location for a specific version module. |
145 | // This returns a string, because the final location may contain special go-getter syntax. | 146 | // This returns a string, because the final location may contain special go-getter syntax. |
146 | func (c *Client) Location(module *regsrc.Module, version string) (string, error) { | 147 | func (c *Client) ModuleLocation(module *regsrc.Module, version string) (string, error) { |
147 | host, err := module.SvcHost() | 148 | host, err := module.SvcHost() |
148 | if err != nil { | 149 | if err != nil { |
149 | return "", err | 150 | return "", err |
150 | } | 151 | } |
151 | 152 | ||
152 | service, err := c.Discover(host) | 153 | service, err := c.Discover(host, modulesServiceID) |
153 | if err != nil { | 154 | if err != nil { |
154 | return "", err | 155 | return "", err |
155 | } | 156 | } |
@@ -225,3 +226,118 @@ func (c *Client) Location(module *regsrc.Module, version string) (string, error) | |||
225 | 226 | ||
226 | return location, nil | 227 | return location, nil |
227 | } | 228 | } |
229 | |||
230 | // TerraformProviderVersions queries the registry for a provider, and returns the available versions. | ||
231 | func (c *Client) TerraformProviderVersions(provider *regsrc.TerraformProvider) (*response.TerraformProviderVersions, error) { | ||
232 | host, err := provider.SvcHost() | ||
233 | if err != nil { | ||
234 | return nil, err | ||
235 | } | ||
236 | |||
237 | service, err := c.Discover(host, providersServiceID) | ||
238 | if err != nil { | ||
239 | return nil, err | ||
240 | } | ||
241 | |||
242 | p, err := url.Parse(path.Join(provider.TerraformProvider(), "versions")) | ||
243 | if err != nil { | ||
244 | return nil, err | ||
245 | } | ||
246 | |||
247 | service = service.ResolveReference(p) | ||
248 | |||
249 | log.Printf("[DEBUG] fetching provider versions from %q", service) | ||
250 | |||
251 | req, err := http.NewRequest("GET", service.String(), nil) | ||
252 | if err != nil { | ||
253 | return nil, err | ||
254 | } | ||
255 | |||
256 | c.addRequestCreds(host, req) | ||
257 | req.Header.Set(xTerraformVersion, tfVersion) | ||
258 | |||
259 | resp, err := c.client.Do(req) | ||
260 | if err != nil { | ||
261 | return nil, err | ||
262 | } | ||
263 | defer resp.Body.Close() | ||
264 | |||
265 | switch resp.StatusCode { | ||
266 | case http.StatusOK: | ||
267 | // OK | ||
268 | case http.StatusNotFound: | ||
269 | return nil, &errProviderNotFound{addr: provider} | ||
270 | default: | ||
271 | return nil, fmt.Errorf("error looking up provider versions: %s", resp.Status) | ||
272 | } | ||
273 | |||
274 | var versions response.TerraformProviderVersions | ||
275 | |||
276 | dec := json.NewDecoder(resp.Body) | ||
277 | if err := dec.Decode(&versions); err != nil { | ||
278 | return nil, err | ||
279 | } | ||
280 | |||
281 | return &versions, nil | ||
282 | } | ||
283 | |||
284 | // TerraformProviderLocation queries the registry for a provider download metadata | ||
285 | func (c *Client) TerraformProviderLocation(provider *regsrc.TerraformProvider, version string) (*response.TerraformProviderPlatformLocation, error) { | ||
286 | host, err := provider.SvcHost() | ||
287 | if err != nil { | ||
288 | return nil, err | ||
289 | } | ||
290 | |||
291 | service, err := c.Discover(host, providersServiceID) | ||
292 | if err != nil { | ||
293 | return nil, err | ||
294 | } | ||
295 | |||
296 | p, err := url.Parse(path.Join( | ||
297 | provider.TerraformProvider(), | ||
298 | version, | ||
299 | "download", | ||
300 | provider.OS, | ||
301 | provider.Arch, | ||
302 | )) | ||
303 | if err != nil { | ||
304 | return nil, err | ||
305 | } | ||
306 | |||
307 | service = service.ResolveReference(p) | ||
308 | |||
309 | log.Printf("[DEBUG] fetching provider location from %q", service) | ||
310 | |||
311 | req, err := http.NewRequest("GET", service.String(), nil) | ||
312 | if err != nil { | ||
313 | return nil, err | ||
314 | } | ||
315 | |||
316 | c.addRequestCreds(host, req) | ||
317 | req.Header.Set(xTerraformVersion, tfVersion) | ||
318 | |||
319 | resp, err := c.client.Do(req) | ||
320 | if err != nil { | ||
321 | return nil, err | ||
322 | } | ||
323 | defer resp.Body.Close() | ||
324 | |||
325 | var loc response.TerraformProviderPlatformLocation | ||
326 | |||
327 | dec := json.NewDecoder(resp.Body) | ||
328 | if err := dec.Decode(&loc); err != nil { | ||
329 | return nil, err | ||
330 | } | ||
331 | |||
332 | switch resp.StatusCode { | ||
333 | case http.StatusOK, http.StatusNoContent: | ||
334 | // OK | ||
335 | case http.StatusNotFound: | ||
336 | return nil, fmt.Errorf("provider %q version %q not found", provider.TerraformProvider(), version) | ||
337 | default: | ||
338 | // anything else is an error: | ||
339 | return nil, fmt.Errorf("error getting download location for %q: %s", provider.TerraformProvider(), resp.Status) | ||
340 | } | ||
341 | |||
342 | return &loc, nil | ||
343 | } | ||
diff --git a/vendor/github.com/hashicorp/terraform/registry/errors.go b/vendor/github.com/hashicorp/terraform/registry/errors.go index b8dcd31..5a6a31b 100644 --- a/vendor/github.com/hashicorp/terraform/registry/errors.go +++ b/vendor/github.com/hashicorp/terraform/registry/errors.go | |||
@@ -4,6 +4,7 @@ import ( | |||
4 | "fmt" | 4 | "fmt" |
5 | 5 | ||
6 | "github.com/hashicorp/terraform/registry/regsrc" | 6 | "github.com/hashicorp/terraform/registry/regsrc" |
7 | "github.com/hashicorp/terraform/svchost/disco" | ||
7 | ) | 8 | ) |
8 | 9 | ||
9 | type errModuleNotFound struct { | 10 | type errModuleNotFound struct { |
@@ -21,3 +22,42 @@ func IsModuleNotFound(err error) bool { | |||
21 | _, ok := err.(*errModuleNotFound) | 22 | _, ok := err.(*errModuleNotFound) |
22 | return ok | 23 | return ok |
23 | } | 24 | } |
25 | |||
26 | type errProviderNotFound struct { | ||
27 | addr *regsrc.TerraformProvider | ||
28 | } | ||
29 | |||
30 | func (e *errProviderNotFound) Error() string { | ||
31 | return fmt.Sprintf("provider %s not found", e.addr) | ||
32 | } | ||
33 | |||
34 | // IsProviderNotFound returns true only if the given error is a "provider not found" | ||
35 | // error. This allows callers to recognize this particular error condition | ||
36 | // as distinct from operational errors such as poor network connectivity. | ||
37 | func IsProviderNotFound(err error) bool { | ||
38 | _, ok := err.(*errProviderNotFound) | ||
39 | return ok | ||
40 | } | ||
41 | |||
42 | // IsServiceNotProvided returns true only if the given error is a "service not provided" | ||
43 | // error. This allows callers to recognize this particular error condition | ||
44 | // as distinct from operational errors such as poor network connectivity. | ||
45 | func IsServiceNotProvided(err error) bool { | ||
46 | _, ok := err.(*disco.ErrServiceNotProvided) | ||
47 | return ok | ||
48 | } | ||
49 | |||
50 | // ServiceUnreachableError Registry service is unreachable | ||
51 | type ServiceUnreachableError struct { | ||
52 | err error | ||
53 | } | ||
54 | |||
55 | func (e *ServiceUnreachableError) Error() string { | ||
56 | return e.err.Error() | ||
57 | } | ||
58 | |||
59 | // IsServiceUnreachable returns true if the registry/discovery service was unreachable | ||
60 | func IsServiceUnreachable(err error) bool { | ||
61 | _, ok := err.(*ServiceUnreachableError) | ||
62 | return ok | ||
63 | } | ||
diff --git a/vendor/github.com/hashicorp/terraform/registry/regsrc/terraform_provider.go b/vendor/github.com/hashicorp/terraform/registry/regsrc/terraform_provider.go new file mode 100644 index 0000000..58dedee --- /dev/null +++ b/vendor/github.com/hashicorp/terraform/registry/regsrc/terraform_provider.go | |||
@@ -0,0 +1,60 @@ | |||
1 | package regsrc | ||
2 | |||
3 | import ( | ||
4 | "fmt" | ||
5 | "runtime" | ||
6 | "strings" | ||
7 | |||
8 | "github.com/hashicorp/terraform/svchost" | ||
9 | ) | ||
10 | |||
11 | var ( | ||
12 | // DefaultProviderNamespace represents the namespace for canonical | ||
13 | // HashiCorp-controlled providers. | ||
14 | DefaultProviderNamespace = "-" | ||
15 | ) | ||
16 | |||
17 | // TerraformProvider describes a Terraform Registry Provider source. | ||
18 | type TerraformProvider struct { | ||
19 | RawHost *FriendlyHost | ||
20 | RawNamespace string | ||
21 | RawName string | ||
22 | OS string | ||
23 | Arch string | ||
24 | } | ||
25 | |||
26 | // NewTerraformProvider constructs a new provider source. | ||
27 | func NewTerraformProvider(name, os, arch string) *TerraformProvider { | ||
28 | if os == "" { | ||
29 | os = runtime.GOOS | ||
30 | } | ||
31 | if arch == "" { | ||
32 | arch = runtime.GOARCH | ||
33 | } | ||
34 | |||
35 | // separate namespace if included | ||
36 | namespace := DefaultProviderNamespace | ||
37 | if names := strings.SplitN(name, "/", 2); len(names) == 2 { | ||
38 | namespace, name = names[0], names[1] | ||
39 | } | ||
40 | p := &TerraformProvider{ | ||
41 | RawHost: PublicRegistryHost, | ||
42 | RawNamespace: namespace, | ||
43 | RawName: name, | ||
44 | OS: os, | ||
45 | Arch: arch, | ||
46 | } | ||
47 | |||
48 | return p | ||
49 | } | ||
50 | |||
51 | // Provider returns just the registry ID of the provider | ||
52 | func (p *TerraformProvider) TerraformProvider() string { | ||
53 | return fmt.Sprintf("%s/%s", p.RawNamespace, p.RawName) | ||
54 | } | ||
55 | |||
56 | // SvcHost returns the svchost.Hostname for this provider. The | ||
57 | // default PublicRegistryHost is returned. | ||
58 | func (p *TerraformProvider) SvcHost() (svchost.Hostname, error) { | ||
59 | return svchost.ForComparison(PublicRegistryHost.Raw) | ||
60 | } | ||
diff --git a/vendor/github.com/hashicorp/terraform/registry/response/provider.go b/vendor/github.com/hashicorp/terraform/registry/response/provider.go new file mode 100644 index 0000000..5e8bae3 --- /dev/null +++ b/vendor/github.com/hashicorp/terraform/registry/response/provider.go | |||
@@ -0,0 +1,36 @@ | |||
1 | package response | ||
2 | |||
3 | import ( | ||
4 | "time" | ||
5 | ) | ||
6 | |||
7 | // Provider is the response structure with the data for a single provider | ||
8 | // version. This is just the metadata. A full provider response will be | ||
9 | // ProviderDetail. | ||
10 | type Provider struct { | ||
11 | ID string `json:"id"` | ||
12 | |||
13 | //--------------------------------------------------------------- | ||
14 | // Metadata about the overall provider. | ||
15 | |||
16 | Owner string `json:"owner"` | ||
17 | Namespace string `json:"namespace"` | ||
18 | Name string `json:"name"` | ||
19 | Version string `json:"version"` | ||
20 | Description string `json:"description"` | ||
21 | Source string `json:"source"` | ||
22 | PublishedAt time.Time `json:"published_at"` | ||
23 | Downloads int `json:"downloads"` | ||
24 | } | ||
25 | |||
26 | // ProviderDetail represents a Provider with full detail. | ||
27 | type ProviderDetail struct { | ||
28 | Provider | ||
29 | |||
30 | //--------------------------------------------------------------- | ||
31 | // The fields below are only set when requesting this specific | ||
32 | // module. They are available to easily know all available versions | ||
33 | // without multiple API calls. | ||
34 | |||
35 | Versions []string `json:"versions"` // All versions | ||
36 | } | ||
diff --git a/vendor/github.com/hashicorp/terraform/registry/response/provider_list.go b/vendor/github.com/hashicorp/terraform/registry/response/provider_list.go new file mode 100644 index 0000000..1dc7d23 --- /dev/null +++ b/vendor/github.com/hashicorp/terraform/registry/response/provider_list.go | |||
@@ -0,0 +1,7 @@ | |||
1 | package response | ||
2 | |||
3 | // ProviderList is the response structure for a pageable list of providers. | ||
4 | type ProviderList struct { | ||
5 | Meta PaginationMeta `json:"meta"` | ||
6 | Providers []*Provider `json:"providers"` | ||
7 | } | ||
diff --git a/vendor/github.com/hashicorp/terraform/registry/response/terraform_provider.go b/vendor/github.com/hashicorp/terraform/registry/response/terraform_provider.go new file mode 100644 index 0000000..64e454a --- /dev/null +++ b/vendor/github.com/hashicorp/terraform/registry/response/terraform_provider.go | |||
@@ -0,0 +1,96 @@ | |||
1 | package response | ||
2 | |||
3 | import ( | ||
4 | "sort" | ||
5 | "strings" | ||
6 | |||
7 | version "github.com/hashicorp/go-version" | ||
8 | ) | ||
9 | |||
10 | // TerraformProvider is the response structure for all required information for | ||
11 | // Terraform to choose a download URL. It must include all versions and all | ||
12 | // platforms for Terraform to perform version and os/arch constraint matching | ||
13 | // locally. | ||
14 | type TerraformProvider struct { | ||
15 | ID string `json:"id"` | ||
16 | Verified bool `json:"verified"` | ||
17 | |||
18 | Versions []*TerraformProviderVersion `json:"versions"` | ||
19 | } | ||
20 | |||
21 | // TerraformProviderVersion is the Terraform-specific response structure for a | ||
22 | // provider version. | ||
23 | type TerraformProviderVersion struct { | ||
24 | Version string `json:"version"` | ||
25 | Protocols []string `json:"protocols"` | ||
26 | |||
27 | Platforms []*TerraformProviderPlatform `json:"platforms"` | ||
28 | } | ||
29 | |||
30 | // TerraformProviderVersions is the Terraform-specific response structure for an | ||
31 | // array of provider versions | ||
32 | type TerraformProviderVersions struct { | ||
33 | ID string `json:"id"` | ||
34 | Versions []*TerraformProviderVersion `json:"versions"` | ||
35 | Warnings []string `json:"warnings"` | ||
36 | } | ||
37 | |||
38 | // TerraformProviderPlatform is the Terraform-specific response structure for a | ||
39 | // provider platform. | ||
40 | type TerraformProviderPlatform struct { | ||
41 | OS string `json:"os"` | ||
42 | Arch string `json:"arch"` | ||
43 | } | ||
44 | |||
45 | // TerraformProviderPlatformLocation is the Terraform-specific response | ||
46 | // structure for a provider platform with all details required to perform a | ||
47 | // download. | ||
48 | type TerraformProviderPlatformLocation struct { | ||
49 | Protocols []string `json:"protocols"` | ||
50 | OS string `json:"os"` | ||
51 | Arch string `json:"arch"` | ||
52 | Filename string `json:"filename"` | ||
53 | DownloadURL string `json:"download_url"` | ||
54 | ShasumsURL string `json:"shasums_url"` | ||
55 | ShasumsSignatureURL string `json:"shasums_signature_url"` | ||
56 | Shasum string `json:"shasum"` | ||
57 | |||
58 | SigningKeys SigningKeyList `json:"signing_keys"` | ||
59 | } | ||
60 | |||
61 | // SigningKeyList is the response structure for a list of signing keys. | ||
62 | type SigningKeyList struct { | ||
63 | GPGKeys []*GPGKey `json:"gpg_public_keys"` | ||
64 | } | ||
65 | |||
66 | // GPGKey is the response structure for a GPG key. | ||
67 | type GPGKey struct { | ||
68 | ASCIIArmor string `json:"ascii_armor"` | ||
69 | Source string `json:"source"` | ||
70 | SourceURL *string `json:"source_url"` | ||
71 | } | ||
72 | |||
73 | // Collection type for TerraformProviderVersion | ||
74 | type ProviderVersionCollection []*TerraformProviderVersion | ||
75 | |||
76 | // GPGASCIIArmor returns an ASCII-armor-formatted string for all of the gpg | ||
77 | // keys in the response. | ||
78 | func (signingKeys *SigningKeyList) GPGASCIIArmor() string { | ||
79 | keys := []string{} | ||
80 | |||
81 | for _, gpgKey := range signingKeys.GPGKeys { | ||
82 | keys = append(keys, gpgKey.ASCIIArmor) | ||
83 | } | ||
84 | |||
85 | return strings.Join(keys, "\n") | ||
86 | } | ||
87 | |||
88 | // Sort sorts versions from newest to oldest. | ||
89 | func (v ProviderVersionCollection) Sort() { | ||
90 | sort.Slice(v, func(i, j int) bool { | ||
91 | versionA, _ := version.NewVersion(v[i].Version) | ||
92 | versionB, _ := version.NewVersion(v[j].Version) | ||
93 | |||
94 | return versionA.GreaterThan(versionB) | ||
95 | }) | ||
96 | } | ||