Skip to content

Commit 87b93e5

Browse files
Vulnerability fix (#114)
* IND-1809 Vulnerabilities Remediation
1 parent 2320631 commit 87b93e5

File tree

7 files changed

+57
-70
lines changed

7 files changed

+57
-70
lines changed

.go-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.18
1+
1.21

addlicense/main.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"errors"
2323
"flag"
2424
"fmt"
25-
"io/ioutil"
2625
"log"
2726
"os"
2827
"path/filepath"
@@ -321,7 +320,7 @@ func addLicense(path string, fmode os.FileMode, tmpl *template.Template, data Li
321320
return false, err
322321
}
323322

324-
b, err := ioutil.ReadFile(path)
323+
b, err := os.ReadFile(path)
325324
if err != nil {
326325
return false, err
327326
}
@@ -338,12 +337,12 @@ func addLicense(path string, fmode os.FileMode, tmpl *template.Template, data Li
338337
lic = append(line, lic...)
339338
}
340339
b = append(lic, b...)
341-
return true, ioutil.WriteFile(path, b, fmode)
340+
return true, os.WriteFile(path, b, fmode)
342341
}
343342

344343
// fileHasLicense reports whether the file at path contains a license header.
345344
func fileHasLicense(path string) (bool, error) {
346-
b, err := ioutil.ReadFile(path)
345+
b, err := os.ReadFile(path)
347346
if err != nil {
348347
return false, err
349348
}

addlicense/main_test.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
package addlicense
1616

1717
import (
18-
"io/ioutil"
1918
"os"
2019
"os/exec"
2120
"path/filepath"
@@ -33,7 +32,7 @@ func run(t *testing.T, name string, args ...string) {
3332
}
3433

3534
func tempDir(t *testing.T) string {
36-
dir, err := ioutil.TempDir("", "addlicense")
35+
dir, err := os.MkdirTemp("", "addlicense")
3736
if err != nil {
3837
t.Fatal(err)
3938
}
@@ -209,12 +208,12 @@ func TestMPL(t *testing.T) {
209208
}
210209

211210
func createTempFile(contents string, pattern string) (*os.File, error) {
212-
f, err := ioutil.TempFile("", pattern)
211+
f, err := os.CreateTemp("", pattern)
213212
if err != nil {
214213
return nil, err
215214
}
216215

217-
if err := ioutil.WriteFile(f.Name(), []byte(contents), 0644); err != nil {
216+
if err := os.WriteFile(f.Name(), []byte(contents), 0644); err != nil {
218217
return nil, err
219218
}
220219

@@ -275,7 +274,7 @@ func TestAddLicense(t *testing.T) {
275274
if updated != tt.wantUpdated {
276275
t.Errorf("addLicense with contents %q returned updated: %t, want %t", tt.contents, updated, tt.wantUpdated)
277276
}
278-
gotContents, err := ioutil.ReadFile(f.Name())
277+
gotContents, err := os.ReadFile(f.Name())
279278
if err != nil {
280279
t.Error(err)
281280
}

addlicense/tmpl.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
"bufio"
1919
"bytes"
2020
"fmt"
21-
"io/ioutil"
21+
"os"
2222
"strings"
2323
"text/template"
2424
"unicode"
@@ -55,7 +55,7 @@ func fetchTemplate(license string, templateFile string, spdx spdxFlag) (string,
5555
if spdx == spdxOnly {
5656
t = tmplSPDX
5757
} else if templateFile != "" {
58-
d, err := ioutil.ReadFile(templateFile)
58+
d, err := os.ReadFile(templateFile)
5959
if err != nil {
6060
return "", fmt.Errorf("license file: %w", err)
6161
}

github/repo.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"context"
88
"fmt"
99

10-
ghcli "github.com/cli/go-gh"
10+
"github.com/cli/go-gh/v2/pkg/repository"
1111
"github.com/google/go-github/v45/github"
1212
)
1313

@@ -24,14 +24,14 @@ type GHRepo struct {
2424
// associated with the given folder. This can happen if multiple git upstreams
2525
// defined.
2626
func DiscoverRepo() (GHRepo, error) {
27-
repo, err := ghcli.CurrentRepository()
27+
repo, err := repository.Current()
2828
if err != nil {
2929
return GHRepo{}, fmt.Errorf("unable to determine if the current directory relates to a GitHub repo: %v", err)
3030
}
3131

3232
return GHRepo{
33-
Name: repo.Name(),
34-
Owner: repo.Owner(),
33+
Name: repo.Name,
34+
Owner: repo.Owner,
3535
}, nil
3636
}
3737

go.mod

+16-19
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
module github.com/hashicorp/copywrite
22

3-
go 1.18
3+
go 1.21
4+
5+
toolchain go1.23.1
46

57
require (
6-
github.com/AlecAivazis/survey/v2 v2.3.6
8+
github.com/AlecAivazis/survey/v2 v2.3.7
79
github.com/bmatcuk/doublestar/v4 v4.6.0
810
github.com/bradleyfalzon/ghinstallation/v2 v2.5.0
911
github.com/hashicorp/go-hclog v1.5.0
1012
github.com/jedib0t/go-pretty/v6 v6.4.6
1113
github.com/knadh/koanf v1.5.0
12-
github.com/mattn/go-isatty v0.0.19
14+
github.com/mattn/go-isatty v0.0.20
1315
github.com/mergestat/timediff v0.0.3
1416
github.com/mitchellh/go-homedir v1.1.0
1517
github.com/mitchellh/mapstructure v1.5.0
@@ -19,54 +21,49 @@ require (
1921
github.com/stretchr/testify v1.8.2
2022
github.com/thanhpk/randstr v1.0.4
2123
golang.org/x/oauth2 v0.8.0
22-
golang.org/x/sync v0.1.0
24+
golang.org/x/sync v0.10.0
2325
)
2426

2527
require (
2628
github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 // indirect
2729
github.com/asaskevich/govalidator v0.0.0-20200907205600-7a23bdc65eef // indirect
2830
github.com/cli/safeexec v1.0.0 // indirect
29-
github.com/cli/shurcooL-graphql v0.0.2 // indirect
30-
github.com/cloudflare/circl v1.3.3 // indirect
31+
github.com/cloudflare/circl v1.3.7 // indirect
3132
github.com/fatih/color v1.13.0 // indirect
3233
github.com/fsnotify/fsnotify v1.5.4 // indirect
3334
github.com/go-openapi/errors v0.20.2 // indirect
3435
github.com/go-openapi/strfmt v0.21.3 // indirect
35-
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
36+
github.com/golang-jwt/jwt/v4 v4.5.1 // indirect
3637
github.com/golang/protobuf v1.5.2 // indirect
3738
github.com/google/go-github/v53 v53.0.0 // indirect
3839
github.com/google/go-querystring v1.1.0 // indirect
3940
github.com/hashicorp/hcl v1.0.0 // indirect
40-
github.com/henvic/httpretty v0.0.6 // indirect
4141
github.com/inconshreveable/mousetrap v1.0.1 // indirect
4242
github.com/joho/godotenv v1.3.0 // indirect
4343
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
4444
github.com/kr/pretty v0.3.0 // indirect
45-
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
4645
github.com/mattn/go-colorable v0.1.13 // indirect
47-
github.com/mattn/go-runewidth v0.0.13 // indirect
46+
github.com/mattn/go-runewidth v0.0.15 // indirect
4847
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
4948
github.com/mitchellh/copystructure v1.2.0 // indirect
5049
github.com/mitchellh/reflectwalk v1.0.2 // indirect
51-
github.com/muesli/termenv v0.12.0 // indirect
5250
github.com/oklog/ulid v1.3.1 // indirect
5351
github.com/pelletier/go-toml v1.9.5 // indirect
54-
github.com/rivo/uniseg v0.2.0 // indirect
55-
github.com/thlib/go-timezone-local v0.0.0-20210907160436-ef149e42d28e // indirect
52+
github.com/rivo/uniseg v0.4.7 // indirect
5653
go.mongodb.org/mongo-driver v1.10.0 // indirect
57-
golang.org/x/crypto v0.7.0 // indirect
54+
golang.org/x/crypto v0.31.0 // indirect
5855
golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17 // indirect
59-
golang.org/x/net v0.10.0 // indirect
60-
golang.org/x/sys v0.8.0 // indirect
61-
golang.org/x/term v0.8.0 // indirect
62-
golang.org/x/text v0.9.0 // indirect
56+
golang.org/x/net v0.33.0 // indirect
57+
golang.org/x/sys v0.28.0 // indirect
58+
golang.org/x/term v0.27.0 // indirect
59+
golang.org/x/text v0.21.0 // indirect
6360
google.golang.org/appengine v1.6.7 // indirect
6461
google.golang.org/protobuf v1.28.0 // indirect
6562
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
6663
)
6764

6865
require (
69-
github.com/cli/go-gh v1.2.1
66+
github.com/cli/go-gh/v2 v2.11.2
7067
github.com/davecgh/go-spew v1.1.1 // indirect
7168
github.com/google/go-github/v45 v45.2.0
7269
github.com/jedib0t/go-pretty v4.3.0+incompatible

0 commit comments

Comments
 (0)