github.com/rstandt/terraform@v0.12.32-0.20230710220336-b1063613405c/internal/getproviders/types.go (about)

     1  package getproviders
     2  
     3  import (
     4  	"crypto/sha256"
     5  	"runtime"
     6  
     7  	"github.com/apparentlymart/go-versions/versions"
     8  )
     9  
    10  // Version represents a particular single version of a provider.
    11  type Version = versions.Version
    12  
    13  // VersionList represents a list of versions. It is a []Version with some
    14  // extra methods for convenient filtering.
    15  type VersionList = versions.List
    16  
    17  // ParseVersion parses a "semver"-style version string into a Version value,
    18  // which is the version syntax we use for provider versions.
    19  func ParseVersion(str string) (Version, error) {
    20  	return versions.ParseVersion(str)
    21  }
    22  
    23  // Platform represents a target platform that a provider is or might be
    24  // available for.
    25  type Platform struct {
    26  	OS, Arch string
    27  }
    28  
    29  func (p Platform) String() string {
    30  	return p.OS + "_" + p.Arch
    31  }
    32  
    33  // CurrentPlatform is the platform where the current program is running.
    34  //
    35  // If attempting to install providers for use on the same system where the
    36  // installation process is running, this is the right platform to use.
    37  var CurrentPlatform = Platform{
    38  	OS:   runtime.GOOS,
    39  	Arch: runtime.GOARCH,
    40  }
    41  
    42  // PackageMeta represents the metadata related to a particular downloadable
    43  // provider package targeting a single platform.
    44  //
    45  // Package findproviders does no signature verification or protocol version
    46  // compatibility checking of its own. A caller receving a PackageMeta must
    47  // verify that it has a correct signature and supports a protocol version
    48  // accepted by the current version of Terraform before trying to use the
    49  // described package.
    50  type PackageMeta struct {
    51  	ProtocolVersions VersionList
    52  	TargetPlatform   Platform
    53  
    54  	Filename  string
    55  	Location  PackageLocation
    56  	SHA256Sum [sha256.Size]byte
    57  
    58  	// TODO: Extra metadata for signature verification
    59  }
    60  
    61  // PackageLocation represents a location where a provider distribution package
    62  // can be obtained. A value of this type contains one of the following
    63  // concrete types: PackageLocalArchive, PackageLocalDir, or PackageHTTPURL.
    64  type PackageLocation interface {
    65  	packageLocation()
    66  }
    67  
    68  // PackageLocalArchive is the location of a provider distribution archive file
    69  // in the local filesystem. Its value is a local filesystem path using the
    70  // syntax understood by Go's standard path/filepath package on the operating
    71  // system where Terraform is running.
    72  type PackageLocalArchive string
    73  
    74  func (p PackageLocalArchive) packageLocation() {}
    75  
    76  // PackageLocalDir is the location of a directory containing an unpacked
    77  // provider distribution archive in the local filesystem. Its value is a local
    78  // filesystem path using the syntax understood by Go's standard path/filepath
    79  // package on the operating system where Terraform is running.
    80  type PackageLocalDir string
    81  
    82  func (p PackageLocalDir) packageLocation() {}
    83  
    84  // PackageHTTPURL is a provider package location accessible via HTTP.
    85  // Its value is a URL string using either the http: scheme or the https: scheme.
    86  type PackageHTTPURL string
    87  
    88  func (p PackageHTTPURL) packageLocation() {}