github.com/hashicorp/terraform-plugin-sdk@v1.17.2/internal/registry/response/terraform_provider.go (about) 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 17 Versions []*TerraformProviderVersion `json:"versions"` 18 } 19 20 // TerraformProviderVersion is the Terraform-specific response structure for a 21 // provider version. 22 type TerraformProviderVersion struct { 23 Version string `json:"version"` 24 Protocols []string `json:"protocols"` 25 26 Platforms []*TerraformProviderPlatform `json:"platforms"` 27 } 28 29 // TerraformProviderVersions is the Terraform-specific response structure for an 30 // array of provider versions 31 type TerraformProviderVersions struct { 32 ID string `json:"id"` 33 Versions []*TerraformProviderVersion `json:"versions"` 34 Warnings []string `json:"warnings"` 35 } 36 37 // TerraformProviderPlatform is the Terraform-specific response structure for a 38 // provider platform. 39 type TerraformProviderPlatform struct { 40 OS string `json:"os"` 41 Arch string `json:"arch"` 42 } 43 44 // TerraformProviderPlatformLocation is the Terraform-specific response 45 // structure for a provider platform with all details required to perform a 46 // download. 47 type TerraformProviderPlatformLocation struct { 48 Protocols []string `json:"protocols"` 49 OS string `json:"os"` 50 Arch string `json:"arch"` 51 Filename string `json:"filename"` 52 DownloadURL string `json:"download_url"` 53 ShasumsURL string `json:"shasums_url"` 54 ShasumsSignatureURL string `json:"shasums_signature_url"` 55 Shasum string `json:"shasum"` 56 57 SigningKeys SigningKeyList `json:"signing_keys"` 58 } 59 60 // SigningKeyList is the response structure for a list of signing keys. 61 type SigningKeyList struct { 62 GPGKeys []*GPGKey `json:"gpg_public_keys"` 63 } 64 65 // GPGKey is the response structure for a GPG key. 66 type GPGKey struct { 67 ASCIIArmor string `json:"ascii_armor"` 68 Source string `json:"source"` 69 SourceURL *string `json:"source_url"` 70 } 71 72 // Collection type for TerraformProviderVersion 73 type ProviderVersionCollection []*TerraformProviderVersion 74 75 // GPGASCIIArmor returns an ASCII-armor-formatted string for all of the gpg 76 // keys in the response. 77 func (signingKeys *SigningKeyList) GPGASCIIArmor() string { 78 keys := []string{} 79 80 for _, gpgKey := range signingKeys.GPGKeys { 81 keys = append(keys, gpgKey.ASCIIArmor) 82 } 83 84 return strings.Join(keys, "\n") 85 } 86 87 // Sort sorts versions from newest to oldest. 88 func (v ProviderVersionCollection) Sort() { 89 sort.Slice(v, func(i, j int) bool { 90 versionA, _ := version.NewVersion(v[i].Version) 91 versionB, _ := version.NewVersion(v[j].Version) 92 93 return versionA.GreaterThan(versionB) 94 }) 95 }