github.com/jaredpalmer/terraform@v1.1.0-alpha20210908.0.20210911170307-88705c943a03/internal/getmodules/installer.go (about)

     1  package getmodules
     2  
     3  // PackageFetcher is a low-level utility for fetching remote module packages
     4  // into local filesystem directories in preparation for use by higher-level
     5  // module installer functionality implemented elsewhere.
     6  //
     7  // A PackageFetcher works only with entire module packages and never with
     8  // the individual modules within a package.
     9  //
    10  // A particular PackageFetcher instance remembers the target directory of
    11  // any successfully-installed package so that it can optimize future calls
    12  // that have the same package address by copying the local directory tree,
    13  // rather than fetching the package from its origin repeatedly. There is
    14  // no way to reset this cache, so a particular PackageFetcher instance should
    15  // live only for the duration of a single initialization process.
    16  type PackageFetcher struct {
    17  	getter reusingGetter
    18  }
    19  
    20  func NewPackageFetcher() *PackageFetcher {
    21  	return &PackageFetcher{
    22  		getter: reusingGetter{},
    23  	}
    24  }
    25  
    26  // FetchPackage downloads or otherwise retrieves the filesystem inside the
    27  // package at the given address into the given local installation directory.
    28  //
    29  // packageAddr must be formatted as if it were the result of an
    30  // addrs.ModulePackage.String() call. It's only defined as a raw string here
    31  // because the getmodules package can't import the addrs package due to
    32  // that creating a package dependency cycle.
    33  //
    34  // PackageFetcher only works with entire packages. If the caller is processing
    35  // a module source address which includes a subdirectory portion then the
    36  // caller must resolve that itself, possibly with the help of the
    37  // getmodules.SplitPackageSubdir and getmodules.ExpandSubdirGlobs functions.
    38  func (f *PackageFetcher) FetchPackage(instDir string, packageAddr string) error {
    39  	return f.getter.getWithGoGetter(instDir, packageAddr)
    40  }