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