Documentation ¶
Overview ¶
getter is a package for downloading files or directories from a variety of protocols.
getter is unique in its ability to download both directories and files. It also detects certain source strings to be protocol-specific URLs. For example, "github.com/hashicorp/go-getter" would turn into a Git URL and use the Git protocol.
Protocols and detectors are extensible.
To get started, see Client.
Index ¶
- Variables
- func Detect(src string, pwd string, ds []Detector) (string, error)
- func Get(dst, src string) error
- func GetAny(dst, src string) error
- func GetFile(dst, src string) error
- func SourceDirSubdir(src string) (string, string)
- func TestDecompressor(t *testing.T, d Decompressor, cases []TestDecompressCase)
- type BitBucketDetector
- type Bzip2Decompressor
- type Client
- type ClientMode
- type Decompressor
- type Detector
- type FileDetector
- type FileGetter
- type FolderStorage
- type Getter
- type GitGetter
- type GitHubDetector
- type GzipDecompressor
- type HgGetter
- type HttpGetter
- type MockGetter
- type S3Detector
- type S3Getter
- type Storage
- type TarBzip2Decompressor
- type TarGzipDecompressor
- type TestDecompressCase
- type ZipDecompressor
Constants ¶
This section is empty.
Variables ¶
var Decompressors map[string]Decompressor
Decompressors is the mapping of extension to the Decompressor implementation that will decompress that extension/type.
var Detectors []Detector
Detectors is the list of detectors that are tried on an invalid URL. This is also the order they're tried (index 0 is first).
var Getters map[string]Getter
Getters is the mapping of scheme to the Getter implementation that will be used to get a dependency.
Functions ¶
func Detect ¶
Detect turns a source string into another source string if it is detected to be of a known pattern.
The third parameter should be the list of detectors to use in the order to try them. If you don't want to configure this, just use the global Detectors variable.
This is safe to be called with an already valid source string: Detect will just return it.
func Get ¶
Get downloads the directory specified by src into the folder specified by dst. If dst already exists, Get will attempt to update it.
src is a URL, whereas dst is always just a file path to a folder. This folder doesn't need to exist. It will be created if it doesn't exist.
func GetAny ¶
GetAny downloads a URL into the given destination. Unlike Get or GetFile, both directories and files are supported.
dst must be a directory. If src is a file, it will be downloaded into dst with the basename of the URL. If src is a directory or archive, it will be unpacked directly into dst.
func SourceDirSubdir ¶
SourceDirSubdir takes a source and returns a tuple of the URL without the subdir and the URL with the subdir.
func TestDecompressor ¶
func TestDecompressor(t *testing.T, d Decompressor, cases []TestDecompressCase)
TestDecompressor is a helper function for testing generic decompressors.
Types ¶
type BitBucketDetector ¶
type BitBucketDetector struct{}
BitBucketDetector implements Detector to detect BitBucket URLs and turn them into URLs that the Git or Hg Getter can understand.
type Bzip2Decompressor ¶
type Bzip2Decompressor struct{}
Bzip2Decompressor is an implementation of Decompressor that can decompress bz2 files.
func (*Bzip2Decompressor) Decompress ¶
func (d *Bzip2Decompressor) Decompress(dst, src string, dir bool) error
type Client ¶
type Client struct { // Src is the source URL to get. // // Dst is the path to save the downloaded thing as. If Dir is set to // true, then this should be a directory. If the directory doesn't exist, // it will be created for you. // // Pwd is the working directory for detection. If this isn't set, some // detection may fail. Client will not default pwd to the current // working directory for security reasons. Src string Dst string Pwd string // Mode is the method of download the client will use. See ClientMode // for documentation. Mode ClientMode // Detectors is the list of detectors that are tried on the source. // If this is nil, then the default Detectors will be used. Detectors []Detector // Decompressors is the map of decompressors supported by this client. // If this is nil, then the default value is the Decompressors global. Decompressors map[string]Decompressor // Getters is the map of protocols supported by this client. If this // is nil, then the default Getters variable will be used. Getters map[string]Getter // Dir, if true, tells the Client it is downloading a directory (versus // a single file). This distinction is necessary since filenames and // directory names follow the same format so disambiguating is impossible // without knowing ahead of time. // // WARNING: deprecated. If Mode is set, that will take precedence. Dir bool }
Client is a client for downloading things.
Top-level functions such as Get are shortcuts for interacting with a client. Using a client directly allows more fine-grained control over how downloading is done, as well as customizing the protocols supported.
type ClientMode ¶
type ClientMode uint
ClientMode is the mode that the client operates in.
const ( ClientModeInvalid ClientMode = iota // ClientModeAny downloads anything it can. In this mode, dst must // be a directory. If src is a file, it is saved into the directory // with the basename of the URL. If src is a directory or archive, // it is unpacked directly into dst. ClientModeAny // ClientModeFile downloads a single file. In this mode, dst must // be a file path (doesn't have to exist). src must point to a single // file. It is saved as dst. ClientModeFile // ClientModeDir downloads a directory. In this mode, dst must be // a directory path (doesn't have to exist). src must point to an // archive or directory (such as in s3). ClientModeDir )
type Decompressor ¶
type Decompressor interface { // Decompress should decompress src to dst. dir specifies whether dst // is a directory or single file. src is guaranteed to be a single file // that exists. dst is not guaranteed to exist already. Decompress(dst, src string, dir bool) error }
Decompressor defines the interface that must be implemented to add support for decompressing a type.
type Detector ¶
type Detector interface { // Detect will detect whether the string matches a known pattern to // turn it into a proper URL. Detect(string, string) (string, bool, error) }
Detector defines the interface that an invalid URL or a URL with a blank scheme is passed through in order to determine if its shorthand for something else well-known.
type FileDetector ¶
type FileDetector struct{}
FileDetector implements Detector to detect file paths.
type FileGetter ¶
type FileGetter struct { // Copy, if set to true, will copy data instead of using a symlink Copy bool }
FileGetter is a Getter implementation that will download a module from a file scheme.
func (*FileGetter) ClientMode ¶
func (g *FileGetter) ClientMode(u *url.URL) (ClientMode, error)
type FolderStorage ¶
type FolderStorage struct { // StorageDir is the directory where the modules will be stored. StorageDir string }
FolderStorage is an implementation of the Storage interface that manages modules on the disk.
type Getter ¶
type Getter interface { // Get downloads the given URL into the given directory. This always // assumes that we're updating and gets the latest version that it can. // // The directory may already exist (if we're updating). If it is in a // format that isn't understood, an error should be returned. Get shouldn't // simply nuke the directory. Get(string, *url.URL) error // GetFile downloads the give URL into the given path. The URL must // reference a single file. If possible, the Getter should check if // the remote end contains the same file and no-op this operation. GetFile(string, *url.URL) error // ClientMode returns the mode based on the given URL. This is used to // allow clients to let the getters decide which mode to use. ClientMode(*url.URL) (ClientMode, error) }
Getter defines the interface that schemes must implement to download things.
type GitGetter ¶
type GitGetter struct{}
GitGetter is a Getter implementation that will download a module from a git repository.
func (*GitGetter) ClientMode ¶
func (g *GitGetter) ClientMode(_ *url.URL) (ClientMode, error)
type GitHubDetector ¶
type GitHubDetector struct{}
GitHubDetector implements Detector to detect GitHub URLs and turn them into URLs that the Git Getter can understand.
type GzipDecompressor ¶
type GzipDecompressor struct{}
GzipDecompressor is an implementation of Decompressor that can decompress bz2 files.
func (*GzipDecompressor) Decompress ¶
func (d *GzipDecompressor) Decompress(dst, src string, dir bool) error
type HgGetter ¶
type HgGetter struct{}
HgGetter is a Getter implementation that will download a module from a Mercurial repository.
func (*HgGetter) ClientMode ¶
func (g *HgGetter) ClientMode(_ *url.URL) (ClientMode, error)
type HttpGetter ¶
type HttpGetter struct { // Netrc, if true, will lookup and use auth information found // in the user's netrc file if available. Netrc bool }
HttpGetter is a Getter implementation that will download from an HTTP endpoint.
For file downloads, HTTP is used directly.
The protocol for downloading a directory from an HTTP endpoing is as follows:
An HTTP GET request is made to the URL with the additional GET parameter "terraform-get=1". This lets you handle that scenario specially if you wish. The response must be a 2xx.
First, a header is looked for "X-Terraform-Get" which should contain a source URL to download.
If the header is not present, then a meta tag is searched for named "terraform-get" and the content should be a source URL.
The source URL, whether from the header or meta tag, must be a fully formed URL. The shorthand syntax of "github.com/foo/bar" or relative paths are not allowed.
func (*HttpGetter) ClientMode ¶
func (g *HttpGetter) ClientMode(u *url.URL) (ClientMode, error)
type MockGetter ¶
type MockGetter struct { // Proxy, if set, will be called after recording the calls below. // If it isn't set, then the *Err values will be returned. Proxy Getter GetCalled bool GetDst string GetURL *url.URL GetErr error GetFileCalled bool GetFileDst string GetFileURL *url.URL GetFileErr error }
MockGetter is an implementation of Getter that can be used for tests.
func (*MockGetter) ClientMode ¶
func (g *MockGetter) ClientMode(u *url.URL) (ClientMode, error)
type S3Detector ¶
type S3Detector struct{}
S3Detector implements Detector to detect S3 URLs and turn them into URLs that the S3 getter can understand.
type S3Getter ¶
type S3Getter struct{}
S3Getter is a Getter implementation that will download a module from a S3 bucket.
func (*S3Getter) ClientMode ¶
func (g *S3Getter) ClientMode(u *url.URL) (ClientMode, error)
type Storage ¶
type Storage interface { // Dir returns the directory on local disk where the directory source // can be loaded from. Dir(string) (string, bool, error) // Get will download and optionally update the given directory. Get(string, string, bool) error }
Storage is an interface that knows how to lookup downloaded directories as well as download and update directories from their sources into the proper location.
type TarBzip2Decompressor ¶
type TarBzip2Decompressor struct{}
TarBzip2Decompressor is an implementation of Decompressor that can decompress tar.bz2 files.
func (*TarBzip2Decompressor) Decompress ¶
func (d *TarBzip2Decompressor) Decompress(dst, src string, dir bool) error
type TarGzipDecompressor ¶
type TarGzipDecompressor struct{}
TarGzipDecompressor is an implementation of Decompressor that can decompress tar.gzip files.
func (*TarGzipDecompressor) Decompress ¶
func (d *TarGzipDecompressor) Decompress(dst, src string, dir bool) error
type TestDecompressCase ¶
type TestDecompressCase struct { Input string // Input is the complete path to the input file Dir bool // Dir is whether or not we're testing directory mode Err bool // Err is whether we expect an error or not DirList []string // DirList is the list of files for Dir mode FileMD5 string // FileMD5 is the expected MD5 for a single file }
TestDecompressCase is a single test case for testing decompressors
type ZipDecompressor ¶
type ZipDecompressor struct{}
ZipDecompressor is an implementation of Decompressor that can decompress tar.gzip files.
func (*ZipDecompressor) Decompress ¶
func (d *ZipDecompressor) Decompress(dst, src string, dir bool) error
Source Files ¶
- client.go
- client_mode.go
- copy_dir.go
- decompress.go
- decompress_bzip2.go
- decompress_gzip.go
- decompress_tbz2.go
- decompress_testing.go
- decompress_tgz.go
- decompress_zip.go
- detect.go
- detect_bitbucket.go
- detect_file.go
- detect_github.go
- detect_s3.go
- folder_storage.go
- get.go
- get_file.go
- get_file_unix.go
- get_git.go
- get_hg.go
- get_http.go
- get_mock.go
- get_s3.go
- netrc.go
- source.go
- storage.go