• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

.circleci/H29-Sep-2020-171148

cmd/go-getter/H29-Sep-2020-166125

helper/url/H29-Sep-2020-156122

test-fixtures/H29-Sep-2020-

testdata/H03-May-2022-15585

LICENSEH A D29-Sep-202015.6 KiB355256

README.mdH A D29-Sep-202013.8 KiB364260

checksum.goH A D29-Sep-20207.7 KiB315235

client.goH A D29-Sep-20208 KiB317191

client_mode.goH A D29-Sep-2020776 258

client_option.goH A D29-Sep-2020943 4734

client_option_progress.goH A D29-Sep-20201.1 KiB3913

client_option_progress_test.goH A D29-Sep-20201.4 KiB6655

common.goH A D29-Sep-2020206 1512

copy_dir.goH A D29-Sep-20201.5 KiB6844

decompress.goH A D29-Sep-20201.8 KiB6038

decompress_bzip2.goH A D29-Sep-2020795 3823

decompress_bzip2_test.goH A D29-Sep-2020465 3529

decompress_gzip.goH A D29-Sep-2020848 4227

decompress_gzip_test.goH A D29-Sep-2020460 3529

decompress_tar.goH A D29-Sep-20203.5 KiB151107

decompress_tar_test.goH A D29-Sep-20202.3 KiB10890

decompress_tbz2.goH A D29-Sep-2020694 3423

decompress_tbz2_test.goH A D29-Sep-2020965 7462

decompress_testing.goH A D29-Sep-20204.1 KiB172137

decompress_tgz.goH A D29-Sep-2020815 4028

decompress_tgz_test.goH A D29-Sep-20201.2 KiB9679

decompress_txz.goH A D29-Sep-2020790 4027

decompress_txz_test.goH A D29-Sep-20201.1 KiB8571

decompress_xz.goH A D29-Sep-2020820 4226

decompress_xz_test.goH A D29-Sep-2020456 3529

decompress_zip.goH A D29-Sep-20201.8 KiB9062

decompress_zip_test.goH A D29-Sep-20201.9 KiB132113

detect.goH A D29-Sep-20202.7 KiB10764

detect_bitbucket.goH A D29-Sep-20201.6 KiB6752

detect_bitbucket_test.goH A D29-Sep-20201.1 KiB6453

detect_file.goH A D29-Sep-20201.5 KiB6846

detect_file_test.goH A D29-Sep-20202.4 KiB11696

detect_file_unix_test.goH A D29-Sep-20201.4 KiB7152

detect_gcs.goH A D29-Sep-2020935 4432

detect_gcs_test.goH A D29-Sep-2020768 4237

detect_git.goH A D29-Sep-2020573 2718

detect_git_test.goH A D29-Sep-20201.8 KiB7061

detect_github.goH A D29-Sep-20201,019 4835

detect_github_test.goH A D29-Sep-2020893 4539

detect_gitlab.goH A D29-Sep-20201 KiB4835

detect_gitlab_test.goH A D29-Sep-2020893 4539

detect_s3.goH A D29-Sep-20201.6 KiB6248

detect_s3_test.goH A D29-Sep-20201.9 KiB8577

detect_ssh.goH A D29-Sep-20201.1 KiB5034

detect_test.goH A D29-Sep-20201.7 KiB9387

folder_storage.goH A D29-Sep-20201.4 KiB6643

folder_storage_test.goH A D29-Sep-2020798 4936

get.goH A D29-Sep-20204.3 KiB15384

get_base.goH A D29-Sep-2020457 2112

get_file.goH A D29-Sep-2020716 3723

get_file_copy.goH A D29-Sep-20202 KiB7648

get_file_copy_test.goH A D29-Sep-20201.8 KiB8372

get_file_test.goH A D29-Sep-20204.4 KiB205147

get_file_unix.goH A D29-Sep-20201.9 KiB9466

get_file_windows.goH A D29-Sep-20202.7 KiB12588

get_gcs.goH A D29-Sep-20203.5 KiB166126

get_gcs_test.goH A D29-Sep-20204.6 KiB198150

get_git.goH A D29-Sep-20208.1 KiB314218

get_git_test.goH A D29-Sep-202015.7 KiB644477

get_hg.goH A D29-Sep-20203.3 KiB13694

get_hg_test.goH A D29-Sep-20201.8 KiB10073

get_http.goH A D29-Sep-20208.4 KiB329220

get_http_test.goH A D29-Sep-202011.1 KiB517396

get_mock.goH A D29-Sep-20201,017 5540

get_s3.goH A D29-Sep-20206.8 KiB290221

get_s3_test.goH A D29-Sep-20206.4 KiB254198

get_test.goH A D29-Sep-202010.6 KiB525422

go.modH A D29-Sep-2020876 2623

go.sumH A D29-Sep-202015.4 KiB163162

module_test.goH A D29-Sep-20201.6 KiB9074

netrc.goH A D29-Sep-20201.4 KiB6844

netrc_test.goH A D29-Sep-20201.3 KiB6450

source.goH A D29-Sep-20201.8 KiB7642

source_test.goH A D29-Sep-20202.1 KiB10790

storage.goH A D29-Sep-2020441 145

util_test.goH A D29-Sep-2020947 5035

README.md

1# go-getter
2
3[![CircleCI](https://circleci.com/gh/hashicorp/go-getter/tree/master.svg?style=svg)][circleci]
4[![Go Documentation](http://img.shields.io/badge/go-documentation-blue.svg?style=flat-square)][godocs]
5
6[circleci]: https://circleci.com/gh/hashicorp/go-getter/tree/master
7[godocs]: http://godoc.org/github.com/hashicorp/go-getter
8
9go-getter is a library for Go (golang) for downloading files or directories
10from various sources using a URL as the primary form of input.
11
12The power of this library is being flexible in being able to download
13from a number of different sources (file paths, Git, HTTP, Mercurial, etc.)
14using a single string as input. This removes the burden of knowing how to
15download from a variety of sources from the implementer.
16
17The concept of a _detector_ automatically turns invalid URLs into proper
18URLs. For example: "github.com/hashicorp/go-getter" would turn into a
19Git URL. Or "./foo" would turn into a file URL. These are extensible.
20
21This library is used by [Terraform](https://terraform.io) for
22downloading modules and [Nomad](https://nomadproject.io) for downloading
23binaries.
24
25## Installation and Usage
26
27Package documentation can be found on
28[GoDoc](http://godoc.org/github.com/hashicorp/go-getter).
29
30Installation can be done with a normal `go get`:
31
32```
33$ go get github.com/hashicorp/go-getter
34```
35
36go-getter also has a command you can use to test URL strings:
37
38```
39$ go install github.com/hashicorp/go-getter/cmd/go-getter
40...
41
42$ go-getter github.com/foo/bar ./foo
43...
44```
45
46The command is useful for verifying URL structures.
47
48## URL Format
49
50go-getter uses a single string URL as input to download from a variety of
51protocols. go-getter has various "tricks" with this URL to do certain things.
52This section documents the URL format.
53
54### Supported Protocols and Detectors
55
56**Protocols** are used to download files/directories using a specific
57mechanism. Example protocols are Git and HTTP.
58
59**Detectors** are used to transform a valid or invalid URL into another
60URL if it matches a certain pattern. Example: "github.com/user/repo" is
61automatically transformed into a fully valid Git URL. This allows go-getter
62to be very user friendly.
63
64go-getter out of the box supports the following protocols. Additional protocols
65can be augmented at runtime by implementing the `Getter` interface.
66
67  * Local files
68  * Git
69  * Mercurial
70  * HTTP
71  * Amazon S3
72  * Google GCP
73
74In addition to the above protocols, go-getter has what are called "detectors."
75These take a URL and attempt to automatically choose the best protocol for
76it, which might involve even changing the protocol. The following detection
77is built-in by default:
78
79  * File paths such as "./foo" are automatically changed to absolute
80    file URLs.
81  * GitHub URLs, such as "github.com/mitchellh/vagrant" are automatically
82    changed to Git protocol over HTTP.
83  * GitLab URLs, such as "gitlab.com/inkscape/inkscape" are automatically
84    changed to Git protocol over HTTP.
85  * BitBucket URLs, such as "bitbucket.org/mitchellh/vagrant" are automatically
86    changed to a Git or mercurial protocol using the BitBucket API.
87
88### Forced Protocol
89
90In some cases, the protocol to use is ambiguous depending on the source
91URL. For example, "http://github.com/mitchellh/vagrant.git" could reference
92an HTTP URL or a Git URL. Forced protocol syntax is used to disambiguate this
93URL.
94
95Forced protocol can be done by prefixing the URL with the protocol followed
96by double colons. For example: `git::http://github.com/mitchellh/vagrant.git`
97would download the given HTTP URL using the Git protocol.
98
99Forced protocols will also override any detectors.
100
101In the absence of a forced protocol, detectors may be run on the URL, transforming
102the protocol anyways. The above example would've used the Git protocol either
103way since the Git detector would've detected it was a GitHub URL.
104
105### Protocol-Specific Options
106
107Each protocol can support protocol-specific options to configure that
108protocol. For example, the `git` protocol supports specifying a `ref`
109query parameter that tells it what ref to checkout for that Git
110repository.
111
112The options are specified as query parameters on the URL (or URL-like string)
113given to go-getter. Using the Git example above, the URL below is a valid
114input to go-getter:
115
116    github.com/hashicorp/go-getter?ref=abcd1234
117
118The protocol-specific options are documented below the URL format
119section. But because they are part of the URL, we point it out here so
120you know they exist.
121
122### Subdirectories
123
124If you want to download only a specific subdirectory from a downloaded
125directory, you can specify a subdirectory after a double-slash `//`.
126go-getter will first download the URL specified _before_ the double-slash
127(as if you didn't specify a double-slash), but will then copy the
128path after the double slash into the target directory.
129
130For example, if you're downloading this GitHub repository, but you only
131want to download the `testdata` directory, you can do the following:
132
133```
134https://github.com/hashicorp/go-getter.git//testdata
135```
136
137If you downloaded this to the `/tmp` directory, then the file
138`/tmp/archive.gz` would exist. Notice that this file is in the `testdata`
139directory in this repository, but because we specified a subdirectory,
140go-getter automatically copied only that directory contents.
141
142Subdirectory paths may also use filesystem glob patterns. The path must
143match _exactly one_ entry or go-getter will return an error.
144This is useful if you're not sure the exact directory name but it follows
145a predictable naming structure.
146
147For example, the following URL would also work:
148
149```
150https://github.com/hashicorp/go-getter.git//test-*
151```
152
153### Checksumming
154
155For file downloads of any protocol, go-getter can automatically verify
156a checksum for you. Note that checksumming only works for downloading files,
157not directories, but checksumming will work for any protocol.
158
159To checksum a file, append a `checksum` query parameter to the URL. go-getter
160will parse out this query parameter automatically and use it to verify the
161checksum. The parameter value can be in the format of `type:value` or just
162`value`, where type is "md5", "sha1", "sha256", "sha512" or "file" . The
163"value" should be the actual checksum value or download URL for "file". When
164`type` part is omitted, type will be guessed based on the length of the
165checksum string. Examples:
166
167```
168./foo.txt?checksum=md5:b7d96c89d09d9e204f5fedc4d5d55b21
169```
170
171```
172./foo.txt?checksum=b7d96c89d09d9e204f5fedc4d5d55b21
173```
174
175```
176./foo.txt?checksum=file:./foo.txt.sha256sum
177```
178
179When checksumming from a file - ex: with `checksum=file:url` - go-getter will
180get the file linked in the URL after `file:` using the same configuration. For
181example, in `file:http://releases.ubuntu.com/cosmic/MD5SUMS` go-getter will
182download a checksum file under the aforementioned url using the http protocol.
183All protocols supported by go-getter can be used. The checksum file will be
184downloaded in a temporary file then parsed. The destination of the temporary
185file can be changed by setting system specific environment variables: `TMPDIR`
186for unix; `TMP`, `TEMP` or `USERPROFILE` on windows. Read godoc of
187[os.TempDir](https://golang.org/pkg/os/#TempDir) for more information on the
188temporary directory selection. Content of files are expected to be BSD or GNU
189style. Once go-getter is done with the checksum file; it is deleted.
190
191The checksum query parameter is never sent to the backend protocol
192implementation. It is used at a higher level by go-getter itself.
193
194If the destination file exists and the checksums match: download
195will be skipped.
196
197### Unarchiving
198
199go-getter will automatically unarchive files into a file or directory
200based on the extension of the file being requested (over any protocol).
201This works for both file and directory downloads.
202
203go-getter looks for an `archive` query parameter to specify the format of
204the archive. If this isn't specified, go-getter will use the extension of
205the path to see if it appears archived. Unarchiving can be explicitly
206disabled by setting the `archive` query parameter to `false`.
207
208The following archive formats are supported:
209
210  * `tar.gz` and `tgz`
211  * `tar.bz2` and `tbz2`
212  * `tar.xz` and `txz`
213  * `zip`
214  * `gz`
215  * `bz2`
216  * `xz`
217
218For example, an example URL is shown below:
219
220```
221./foo.zip
222```
223
224This will automatically be inferred to be a ZIP file and will be extracted.
225You can also be explicit about the archive type:
226
227```
228./some/other/path?archive=zip
229```
230
231And finally, you can disable archiving completely:
232
233```
234./some/path?archive=false
235```
236
237You can combine unarchiving with the other features of go-getter such
238as checksumming. The special `archive` query parameter will be removed
239from the URL before going to the final protocol downloader.
240
241## Protocol-Specific Options
242
243This section documents the protocol-specific options that can be specified for
244go-getter. These options should be appended to the input as normal query
245parameters ([HTTP headers](#headers) are an exception to this, however).
246Depending on the usage of go-getter, applications may provide alternate ways of
247inputting options. For example, [Nomad](https://www.nomadproject.io) provides a
248nice options block for specifying options rather than in the URL.
249
250## General (All Protocols)
251
252The options below are available to all protocols:
253
254  * `archive` - The archive format to use to unarchive this file, or "" (empty
255    string) to disable unarchiving. For more details, see the complete section
256    on archive support above.
257
258  * `checksum` - Checksum to verify the downloaded file or archive. See
259    the entire section on checksumming above for format and more details.
260
261  * `filename` - When in file download mode, allows specifying the name of the
262    downloaded file on disk. Has no effect in directory mode.
263
264### Local Files (`file`)
265
266None
267
268### Git (`git`)
269
270  * `ref` - The Git ref to checkout. This is a ref, so it can point to
271    a commit SHA, a branch name, etc. If it is a named ref such as a branch
272    name, go-getter will update it to the latest on each get.
273
274  * `sshkey` - An SSH private key to use during clones. The provided key must
275    be a base64-encoded string. For example, to generate a suitable `sshkey`
276    from a private key file on disk, you would run `base64 -w0 <file>`.
277
278    **Note**: Git 2.3+ is required to use this feature.
279
280  * `depth` - The Git clone depth. The provided number specifies the last `n`
281    revisions to clone from the repository.
282
283
284The `git` getter accepts both URL-style SSH addresses like
285`git::ssh://git@example.com/foo/bar`, and "scp-style" addresses like
286`git::git@example.com/foo/bar`. In the latter case, omitting the `git::`
287force prefix is allowed if the username prefix is exactly `git@`.
288
289The "scp-style" addresses _cannot_ be used in conjunction with the `ssh://`
290scheme prefix, because in that case the colon is used to mark an optional
291port number to connect on, rather than to delimit the path from the host.
292
293### Mercurial (`hg`)
294
295  * `rev` - The Mercurial revision to checkout.
296
297### HTTP (`http`)
298
299#### Basic Authentication
300
301To use HTTP basic authentication with go-getter, simply prepend `username:password@` to the
302hostname in the URL such as `https://Aladdin:OpenSesame@www.example.com/index.html`. All special
303characters, including the username and password, must be URL encoded.
304
305#### Headers
306
307Optional request headers can be added by supplying them in a custom
308[`HttpGetter`](https://godoc.org/github.com/hashicorp/go-getter#HttpGetter)
309(_not_ as query parameters like most other options). These headers will be sent
310out on every request the getter in question makes.
311
312### S3 (`s3`)
313
314S3 takes various access configurations in the URL. Note that it will also
315read these from standard AWS environment variables if they're set. S3 compliant servers like Minio
316are also supported. If the query parameters are present, these take priority.
317
318  * `aws_access_key_id` - AWS access key.
319  * `aws_access_key_secret` - AWS access key secret.
320  * `aws_access_token` - AWS access token if this is being used.
321  * `aws_profile` - Use this profile from local ~/.aws/ config. Takes priority over the other three.
322
323#### Using IAM Instance Profiles with S3
324
325If you use go-getter and want to use an EC2 IAM Instance Profile to avoid
326using credentials, then just omit these and the profile, if available will
327be used automatically.
328
329### Using S3 with Minio
330 If you use go-gitter for Minio support, you must consider the following:
331
332  * `aws_access_key_id` (required) - Minio access key.
333  * `aws_access_key_secret` (required) - Minio access key secret.
334  * `region` (optional - defaults to us-east-1) - Region identifier to use.
335  * `version` (optional - defaults to Minio default) - Configuration file format.
336
337#### S3 Bucket Examples
338
339S3 has several addressing schemes used to reference your bucket. These are
340listed here: http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingBucket.html#access-bucket-intro
341
342Some examples for these addressing schemes:
343- s3::https://s3.amazonaws.com/bucket/foo
344- s3::https://s3-eu-west-1.amazonaws.com/bucket/foo
345- bucket.s3.amazonaws.com/foo
346- bucket.s3-eu-west-1.amazonaws.com/foo/bar
347- "s3::http://127.0.0.1:9000/test-bucket/hello.txt?aws_access_key_id=KEYID&aws_access_key_secret=SECRETKEY&region=us-east-2"
348
349### GCS (`gcs`)
350
351#### GCS Authentication
352
353In order to access to GCS, authentication credentials should be provided. More information can be found [here](https://cloud.google.com/docs/authentication/getting-started)
354
355#### GCS Bucket Examples
356
357- gcs::https://www.googleapis.com/storage/v1/bucket
358- gcs::https://www.googleapis.com/storage/v1/bucket/foo.zip
359- www.googleapis.com/storage/v1/bucket/foo
360
361#### GCS Testing
362
363The tests for `get_gcs.go` require you to have GCP credentials set in your environment.  These credentials can have any level of permissions to any project, they just need to exist.  This means setting `GOOGLE_APPLICATION_CREDENTIALS="~/path/to/credentials.json"` or `GOOGLE_CREDENTIALS="{stringified-credentials-json}"`.  Due to this configuration, `get_gcs_test.go` will fail for external contributors in CircleCI.
364