diff --git a/internal/getproviders/registry_client.go b/internal/getproviders/registry_client.go index 1ee561be6..fd96c65de 100644 --- a/internal/getproviders/registry_client.go +++ b/internal/getproviders/registry_client.go @@ -207,8 +207,8 @@ func (c *registryClient) PackageMeta(provider addrs.Provider, version Version, t OS: body.OS, Arch: body.Arch, }, - Filename: body.Filename, - DownloadURL: body.DownloadURL, + Filename: body.Filename, + Location: PackageHTTPURL(body.DownloadURL), // SHA256Sum is populated below } diff --git a/internal/getproviders/registry_source.go b/internal/getproviders/registry_source.go index 3e45f6aab..13f5e8d96 100644 --- a/internal/getproviders/registry_source.go +++ b/internal/getproviders/registry_source.go @@ -15,6 +15,8 @@ type RegistrySource struct { services *disco.Disco } +var _ Source = (*RegistrySource)(nil) + // NewRegistrySource creates and returns a new source that will install // providers from their originating provider registries. func NewRegistrySource(services *disco.Disco) *RegistrySource { @@ -60,11 +62,11 @@ func (s *RegistrySource) AvailableVersions(provider addrs.Provider) (VersionList return ret, nil } -// DownloadLocation returns metadata about the location and capabilities of +// PackageMeta returns metadata about the location and capabilities of // a distribution package for a particular provider at a particular version // targeting a particular platform. // -// Callers of DownloadLocation should first call AvailableVersions and pass +// Callers of PackageMeta should first call AvailableVersions and pass // one of the resulting versions to this function. This function cannot // distinguish between a version that is not available and an unsupported // target platform, so if it encounters either case it will return an error @@ -73,13 +75,13 @@ func (s *RegistrySource) AvailableVersions(provider addrs.Provider) (VersionList // // To find a package suitable for the platform where the provider installation // process is running, set the "target" argument to -// findproviders.CurrentPlatform. +// getproviders.CurrentPlatform. // // If the request fails, the returned error might be an value of // ErrHostNoProviders, ErrHostUnreachable, ErrUnauthenticated, // ErrPlatformNotSupported, or ErrQueryFailed. Callers must be defensive and // expect errors of other types too, to allow for future expansion. -func (s *RegistrySource) DownloadLocation(provider addrs.Provider, version Version, target Platform) (PackageMeta, error) { +func (s *RegistrySource) PackageMeta(provider addrs.Provider, version Version, target Platform) (PackageMeta, error) { client, err := s.registryClient(provider.Hostname) if err != nil { return PackageMeta{}, err diff --git a/internal/getproviders/registry_source_test.go b/internal/getproviders/registry_source_test.go index de40fd0e0..943112086 100644 --- a/internal/getproviders/registry_source_test.go +++ b/internal/getproviders/registry_source_test.go @@ -105,7 +105,7 @@ func TestSourceAvailableVersions(t *testing.T) { } -func TestSourceDownloadLocation(t *testing.T) { +func TestSourcePackageMeta(t *testing.T) { source, close := testRegistrySource(t) defer close() @@ -126,7 +126,7 @@ func TestSourceDownloadLocation(t *testing.T) { ProtocolVersions: VersionList{versions.MustParseVersion("5.0.0")}, TargetPlatform: Platform{"linux", "amd64"}, Filename: "happycloud_1.2.0.zip", - DownloadURL: "/pkg/happycloud_1.2.0.zip", + Location: PackageHTTPURL("/pkg/happycloud_1.2.0.zip"), SHA256Sum: [32]uint8{30: 0xf0, 31: 0x0d}, // fake registry uses a memorable sum }, ``, @@ -181,7 +181,7 @@ func TestSourceDownloadLocation(t *testing.T) { version := versions.MustParseVersion(test.version) - got, err := source.DownloadLocation(providerAddr, version, Platform{test.os, test.arch}) + got, err := source.PackageMeta(providerAddr, version, Platform{test.os, test.arch}) if err != nil { if test.wantErr == "" { diff --git a/internal/getproviders/source.go b/internal/getproviders/source.go new file mode 100644 index 000000000..2921e2d76 --- /dev/null +++ b/internal/getproviders/source.go @@ -0,0 +1,12 @@ +package getproviders + +import ( + "github.com/hashicorp/terraform/addrs" +) + +// A Source can query a particular source for information about providers +// that are available to install. +type Source interface { + AvailableVersions(provider addrs.Provider) (VersionList, error) + PackageMeta(provider addrs.Provider, version Version, target Platform) (PackageMeta, error) +} diff --git a/internal/getproviders/types.go b/internal/getproviders/types.go index 2162315b0..b2faf3808 100644 --- a/internal/getproviders/types.go +++ b/internal/getproviders/types.go @@ -51,9 +51,30 @@ type PackageMeta struct { ProtocolVersions VersionList TargetPlatform Platform - Filename string - DownloadURL string - SHA256Sum [sha256.Size]byte + Filename string + Location PackageLocation + SHA256Sum [sha256.Size]byte // TODO: Extra metadata for signature verification } + +// PackageLocation represents a location where a provider distribution package +// can be obtained. A value of this type contains either a PackageLocalPath or a +// PackageHTTPURL value. +type PackageLocation interface { + packageLocation() +} + +// PackageLocalPath is a provider package location in the local filesystem. +// Its value is a local filesystem path using the syntax understood by Go's +// standard path/filepath package on the operating system where Terraform is +// running. +type PackageLocalPath string + +func (p PackageLocalPath) packageLocation() {} + +// PackageHTTPURL is a provider package location accessible via HTTP. +// Its value is a URL string using either the http: scheme or the https: scheme. +type PackageHTTPURL string + +func (p PackageHTTPURL) packageLocation() {}