Skip to content

Commit 04eeeb2

Browse files
committed
Merge branch 'hashicorp:main' into shallow-tag-clone
2 parents 7dda4ee + ad4c48e commit 04eeeb2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1034
-222
lines changed

.circleci/config.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,22 @@ commands:
1515
type: string
1616
platform:
1717
type: string
18+
govet:
19+
type: string
20+
default: ""
1821
steps:
1922
- run:
2023
name: "Run go tests"
2124
command: |
2225
PACKAGE_NAMES=$(go list ./... | circleci tests split --split-by=timings --timings-type=classname)
2326
echo "Running $(echo $PACKAGE_NAMES | wc -w) packages"
2427
echo $PACKAGE_NAMES
25-
<< parameters.cmd >> --format=short-verbose --junitfile $TEST_RESULTS_PATH/go-getter/gotestsum-report.xml -- -p 2 -cover -coverprofile=<< parameters.platform >>_cov_$CIRCLE_NODE_INDEX.part $PACKAGE_NAMES
28+
<< parameters.cmd >> --format=short-verbose --junitfile $TEST_RESULTS_PATH/go-getter/gotestsum-report.xml -- -p 2 -cover -race -vet=<< parameters.govet >> -coverprofile=<< parameters.platform >>_cov_$CIRCLE_NODE_INDEX.part $PACKAGE_NAMES
2629
2730
jobs:
2831
linux-tests:
2932
docker:
30-
- image: circleci/golang:<< parameters.go-version >>
33+
- image: docker.mirror.hashicorp.services/circleci/golang:<< parameters.go-version >>
3134
parameters:
3235
go-version:
3336
type: string
@@ -140,6 +143,9 @@ jobs:
140143
- run-gotests:
141144
cmd: "./gotestsum.exe"
142145
platform: "win"
146+
# Otherwise gcc is required for race detector
147+
# See https://github.com/golang/go/issues/27089
148+
govet: "off"
143149

144150
# Save coverage report parts
145151
- persist_to_workspace:

.github/workflows/codeql-analysis.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: "Code scanning - scheduled (weekly) or on-demand"
2+
3+
on:
4+
schedule:
5+
- cron: '0 15 * * 0'
6+
workflow_dispatch:
7+
8+
jobs:
9+
CodeQL-Build:
10+
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout repository
15+
uses: actions/checkout@v2
16+
with:
17+
# We must fetch at least the immediate parents so that if this is
18+
# a pull request then we can checkout the head.
19+
fetch-depth: 2
20+
21+
# If this run was triggered by a pull request event, then checkout
22+
# the head of the pull request instead of the merge commit.
23+
- run: git checkout HEAD^2
24+
if: ${{ github.event_name == 'pull_request' }}
25+
26+
# Initializes the CodeQL tools for scanning.
27+
- name: Initialize CodeQL
28+
uses: github/codeql-action/init@v1
29+
# Override language selection by uncommenting this and choosing your languages
30+
with:
31+
languages: go
32+
33+
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
34+
# If this step fails, then you should remove it and run the build manually (see below)
35+
# - name: Autobuild
36+
# uses: github/codeql-action/autobuild@v1
37+
38+
# ℹ️ Command-line programs to run using the OS shell.
39+
# 📚 https://git.io/JvXDl
40+
41+
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
42+
# and modify them (or add more) to build your code if your project
43+
# uses a compiled language
44+
45+
#- run: |
46+
# make bootstrap
47+
# make release
48+
49+
- name: Perform CodeQL Analysis
50+
uses: github/codeql-action/analyze@v1

.github/workflows/release.yml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
### This builds, packages, signs, performs AV and malware scanning, and
2+
### creates a new GitHub release for the newest version of go-getter.
3+
### The GitHub release step performs the actions outlined in
4+
### release.goreleaser.yml. A release is triggered when a new tag
5+
### is pushed in the format vX.X.X
6+
7+
name: Release
8+
9+
on:
10+
push:
11+
tags:
12+
- 'v[0-9]+.[0-9]+.[0-9]+*'
13+
14+
jobs:
15+
release:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v2
20+
with:
21+
fetch-depth: 0
22+
- name: Setup go
23+
uses: actions/setup-go@v2
24+
with:
25+
go-version: '^1.15'
26+
- name: Install hc-codesign
27+
id: codesign
28+
run: |
29+
docker login docker.pkg.github.com -u docker -p $GITHUB_TOKEN && \
30+
docker pull docker.pkg.github.com/hashicorp/hc-codesign/hc-codesign:$VERSION && \
31+
echo "::set-output name=image::docker.pkg.github.com/hashicorp/hc-codesign/hc-codesign:$VERSION"
32+
env:
33+
VERSION: v0
34+
GITHUB_TOKEN: ${{ secrets.CODESIGN_GITHUB_TOKEN }}
35+
- name: Install wget & clamAV antivirus scanner
36+
run : |
37+
sudo apt-get -qq install -y ca-certificates wget clamav
38+
wget --version
39+
- name: Install maldet malware scanner
40+
run: |
41+
wget --no-verbose -O maldet-$VERSION.tar.gz https://github.com/rfxn/linux-malware-detect/archive/$VERSION.tar.gz
42+
sha256sum -c - <<< "$SHA256SUM maldet-$VERSION.tar.gz"
43+
sudo mkdir -p maldet-$VERSION
44+
sudo tar -xzf maldet-$VERSION.tar.gz --strip-components=1 -C maldet-$VERSION
45+
cd maldet-$VERSION
46+
sudo ./install.sh
47+
sudo maldet -u
48+
env:
49+
VERSION: 1.6.4
50+
SHA256SUM: 3ad66eebd443d32dd6c811dcf2d264b78678c75ed1d40c15434180d4453e60d2
51+
- name: Import PGP key for archive signing
52+
run: echo -e $PGP_KEY | base64 -di | gpg --import --batch
53+
env:
54+
GPG_TTY: $(tty)
55+
PGP_KEY: ${{ secrets.PGP_SIGNING_KEY }}
56+
- name: GitHub Release
57+
uses: goreleaser/goreleaser-action@v1
58+
with:
59+
version: latest
60+
args: release --skip-validate --timeout "60m"
61+
env:
62+
PGP_KEY_ID: ${{ secrets.PGP_KEY_ID }}
63+
CODESIGN_IMAGE: ${{ steps.codesign.outputs.image }}
64+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
65+
ARTIFACTORY_TOKEN: ${{ secrets.ARTIFACTORY_TOKEN }}
66+
ARTIFACTORY_USER: ${{ secrets.ARTIFACTORY_USER }}
67+
CIRCLE_TOKEN: ${{ secrets.CIRCLE_TOKEN }}
68+
- name: Run clamAV antivirus scanner
69+
run: sudo clamscan /home/runner/work/$REPO/$REPO/dist/
70+
env:
71+
REPO: ${{ github.event.repository.name }}
72+
- name: Run maldet malware scanner
73+
run: sudo maldet -a /home/runner/work/$REPO/$REPO/dist/
74+
env:
75+
REPO: ${{ github.event.repository.name }}
76+

.goreleaser.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
env:
2+
- GOPRIVATE=github.com/hashicorp
3+
4+
builds:
5+
- id: signable
6+
mod_timestamp: '{{ .CommitTimestamp }}'
7+
targets:
8+
- darwin_amd64
9+
- windows_386
10+
- windows_amd64
11+
hooks:
12+
post: |
13+
docker run
14+
-e ARTIFACTORY_TOKEN={{ .Env.ARTIFACTORY_TOKEN }}
15+
-e ARTIFACTORY_USER={{ .Env.ARTIFACTORY_USER }}
16+
-e CIRCLE_TOKEN={{ .Env.CIRCLE_TOKEN }}
17+
-v {{ dir .Path }}:/workdir
18+
{{ .Env.CODESIGN_IMAGE }}
19+
sign -product-name={{ .ProjectName }} {{ .Name }}
20+
dir: ./cmd/go-getter/
21+
flags:
22+
- -trimpath
23+
ldflags:
24+
- -X main.GitCommit={{ .Commit }}
25+
- mod_timestamp: '{{ .CommitTimestamp }}'
26+
targets:
27+
- linux_386
28+
- linux_amd64
29+
dir: ./cmd/go-getter/
30+
flags:
31+
- -trimpath
32+
ldflags:
33+
- -X main.GitCommit={{ .Commit }}
34+
35+
archives:
36+
- format: zip
37+
name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
38+
files:
39+
- none*
40+
41+
checksum:
42+
name_template: '{{ .ProjectName }}_{{ .Version }}_SHA256SUMS'
43+
algorithm: sha256
44+
45+
signs:
46+
- args: ["-u", "{{ .Env.PGP_KEY_ID }}", "--output", "${signature}", "--detach-sign", "${artifact}"]
47+
artifacts: checksum
48+
49+
changelog:
50+
skip: true

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# go-getter
22

3-
[![CircleCI](https://circleci.com/gh/hashicorp/go-getter/tree/master.svg?style=svg)][circleci]
3+
[![CircleCI](https://circleci.com/gh/hashicorp/go-getter/tree/main.svg?style=svg)][circleci]
44
[![Go Documentation](http://img.shields.io/badge/go-documentation-blue.svg?style=flat-square)][godocs]
55

6-
[circleci]: https://circleci.com/gh/hashicorp/go-getter/tree/master
6+
[circleci]: https://circleci.com/gh/hashicorp/go-getter/tree/main
77
[godocs]: http://godoc.org/github.com/hashicorp/go-getter
88

99
go-getter is a library for Go (golang) for downloading files or directories
@@ -80,6 +80,8 @@ is built-in by default:
8080
file URLs.
8181
* GitHub URLs, such as "github.com/mitchellh/vagrant" are automatically
8282
changed to Git protocol over HTTP.
83+
* GitLab URLs, such as "gitlab.com/inkscape/inkscape" are automatically
84+
changed to Git protocol over HTTP.
8385
* BitBucket URLs, such as "bitbucket.org/mitchellh/vagrant" are automatically
8486
changed to a Git or mercurial protocol using the BitBucket API.
8587

@@ -316,6 +318,7 @@ are also supported. If the query parameters are present, these take priority.
316318
* `aws_access_key_id` - AWS access key.
317319
* `aws_access_key_secret` - AWS access key secret.
318320
* `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.
319322

320323
#### Using IAM Instance Profiles with S3
321324

checksum.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,10 @@ func (c *Client) ChecksumFromFile(checksumFile string, src *url.URL) (*FileCheck
259259
return nil, fmt.Errorf(
260260
"Error reading checksum file: %s", err)
261261
}
262-
break
262+
if line == "" {
263+
break
264+
}
265+
// parse the line, if we hit EOF, but the line is not empty
263266
}
264267
checksum, err := parseChecksumLine(line)
265268
if err != nil || checksum == nil {

client.go

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ type Client struct {
3939
// for documentation.
4040
Mode ClientMode
4141

42+
// Umask is used to mask file permissions when storing local files or decompressing
43+
// an archive
44+
Umask os.FileMode
45+
4246
// Detectors is the list of detectors that are tried on the source.
4347
// If this is nil, then the default Detectors will be used.
4448
Detectors []Detector
@@ -63,9 +67,32 @@ type Client struct {
6367
// By default a no op progress listener is used.
6468
ProgressListener ProgressTracker
6569

70+
// Insecure controls whether a client verifies the server's
71+
// certificate chain and host name. If Insecure is true, crypto/tls
72+
// accepts any certificate presented by the server and any host name in that
73+
// certificate. In this mode, TLS is susceptible to machine-in-the-middle
74+
// attacks unless custom verification is used. This should be used only for
75+
// testing or in combination with VerifyConnection or VerifyPeerCertificate.
76+
// This is identical to tls.Config.InsecureSkipVerify.
77+
Insecure bool
78+
6679
Options []ClientOption
6780
}
6881

82+
// umask returns the effective umask for the Client, defaulting to the process umask
83+
func (c *Client) umask() os.FileMode {
84+
if c == nil {
85+
return 0
86+
}
87+
return c.Umask
88+
}
89+
90+
// mode returns file mode umasked by the Client umask
91+
func (c *Client) mode(mode os.FileMode) os.FileMode {
92+
m := mode & ^c.umask()
93+
return m
94+
}
95+
6996
// Get downloads the configured source to the destination.
7097
func (c *Client) Get() error {
7198
if err := c.Configure(c.Options...); err != nil {
@@ -233,7 +260,7 @@ func (c *Client) Get() error {
233260
if decompressor != nil {
234261
// We have a decompressor, so decompress the current destination
235262
// into the final destination with the proper mode.
236-
err := decompressor.Decompress(decompressDst, dst, decompressDir)
263+
err := decompressor.Decompress(decompressDst, dst, decompressDir, c.umask())
237264
if err != nil {
238265
return err
239266
}
@@ -271,7 +298,7 @@ func (c *Client) Get() error {
271298
// if we're specifying a subdir.
272299
err := g.Get(dst, u)
273300
if err != nil {
274-
err = fmt.Errorf("error downloading '%s': %s", src, err)
301+
err = fmt.Errorf("error downloading '%s': %s", u.Redacted(), err)
275302
return err
276303
}
277304
}
@@ -281,7 +308,7 @@ func (c *Client) Get() error {
281308
if err := os.RemoveAll(realDst); err != nil {
282309
return err
283310
}
284-
if err := os.MkdirAll(realDst, 0755); err != nil {
311+
if err := os.MkdirAll(realDst, c.mode(0755)); err != nil {
285312
return err
286313
}
287314

@@ -291,7 +318,7 @@ func (c *Client) Get() error {
291318
return err
292319
}
293320

294-
return copyDir(c.Ctx, realDst, subDir, false)
321+
return copyDir(c.Ctx, realDst, subDir, false, c.umask())
295322
}
296323

297324
return nil

client_option_insecure.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package getter
2+
3+
// WithInsecure allows for a user to avoid
4+
// checking certificates (not recommended).
5+
// For example, when connecting on HTTPS where an
6+
// invalid certificate is presented.
7+
// User assumes all risk.
8+
// Not all getters have support for insecure mode yet.
9+
func WithInsecure() func(*Client) error {
10+
return func(c *Client) error {
11+
c.Insecure = true
12+
return nil
13+
}
14+
}

cmd/go-getter/main.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
func main() {
1515
modeRaw := flag.String("mode", "any", "get mode (any, file, dir)")
1616
progress := flag.Bool("progress", false, "display terminal progress")
17+
insecure := flag.Bool("insecure", false, "do not verify server's certificate chain (not recommended)")
1718
flag.Parse()
1819
args := flag.Args()
1920
if len(args) < 2 {
@@ -46,6 +47,11 @@ func main() {
4647
opts = append(opts, getter.WithProgress(defaultProgressBar))
4748
}
4849

50+
if *insecure {
51+
log.Println("WARNING: Using Insecure TLS transport!")
52+
opts = append(opts, getter.WithInsecure())
53+
}
54+
4955
ctx, cancel := context.WithCancel(context.Background())
5056
// Build the client
5157
client := &getter.Client{

0 commit comments

Comments
 (0)