getmodules

package
v0.24.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 13, 2024 License: MPL-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package getmodules package

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NormalizePackageAddress

func NormalizePackageAddress(given string) (packageAddr, subDir string, err error)

NormalizePackageAddress uses the go-getter "detector" functionality in order to turn a user-supplied source address into a normalized address which always includes a prefix naming a protocol to fetch with and may also include a transformed/normalized version of the protocol-specific source address included afterward.

This is part of the implementation of addrs.ParseModulePackage and of addrs.ParseModuleSource, so for most callers it'd be better to call one of those other functions instead. The addrs package can potentially perform other processing in addition to just the go-getter detection.

Note that this function expects to receive only a package address, not a full source address that might also include a subdirectory portion. The caller must trim off any subdirectory portion using getmodules.SplitPackageSubdir before calling this function, passing in just the packageAddr return value, or the result will be incorrect.

The detectors in go-getter can potentially introduce their own package subdirectory portions. If that happens then this function will return the subdirectory portion as a non-empty subDir return value, which the caller must then use as a prefix for any subDir it already extracted from the user's given package address.

Some of go-getter's detectors make outgoing HTTP requests, and so the behavior of this function may depend on the network connectivity of the system where Terraform is running. However, most of the getters we use are local-only, and so HTTP requests are only for some ambiguous edge-cases, such as the BitBucket detector which has a mechanism to detect whether to use Git or Mercurial, because earlier versions of BitBucket used to support both.

func SplitPackageSubdir

func SplitPackageSubdir(given string) (packageAddr, subDir string)

SplitPackageSubdir detects whether the given address string has a subdirectory portion, and if so returns a non-empty subDir string along with the trimmed package address.

If the given string doesn't have a subdirectory portion then it'll just be returned verbatim in packageAddr, with an empty subDir value.

Although the rest of this package is focused only on direct remote module packages, this particular function and its companion ExpandSubdirGlobs are both also relevant for registry-based module addresses, because a registry translates such an address into a remote module package address and thus can contribute its own additions to the final subdirectory selection.

Types

type MaybeRelativePathErr

type MaybeRelativePathErr struct {
	Addr string
}

MaybeRelativePathErr is the error type returned by NormalizePackageAddress if the source address looks like it might be intended to be a relative filesystem path but without the required "./" or "../" prefix.

Specifically, NormalizePackageAddress will return a pointer to this type, so the error type will be *MaybeRelativePathErr.

It has a name starting with "Maybe" because in practice we can get here with any string that isn't recognized as one of the supported schemes: treating the address as a local filesystem path is our fallback for when everything else fails, but it could just as easily be a typo in an attempt to use one of the other schemes and thus not a filesystem path at all.

func (*MaybeRelativePathErr) Error

func (e *MaybeRelativePathErr) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL