Skip to content

Commit 60a4eef

Browse files
authored
Fix linter warnings (#1450)
* Remove unnecessary utils files in favor of cli-utils package * Remove nolint:revive directive from bcrypt-pbkdf file
1 parent cb9a523 commit 60a4eef

File tree

25 files changed

+67
-314
lines changed

25 files changed

+67
-314
lines changed

command/ca/federation.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ import (
1313
"github.com/smallstep/certificates/pki"
1414
"github.com/smallstep/cli-utils/command"
1515
"github.com/smallstep/cli-utils/errs"
16+
"github.com/smallstep/cli-utils/fileutil"
1617
"github.com/smallstep/cli-utils/ui"
1718
"go.step.sm/crypto/pemutil"
1819

1920
"github.com/smallstep/cli/flags"
20-
"github.com/smallstep/cli/utils"
2121
)
2222

2323
type flowType int
@@ -170,7 +170,7 @@ func rootsAndFederationFlow(ctx *cli.Context, typ flowType) error {
170170
}
171171

172172
if outFile := ctx.Args().Get(0); outFile != "" {
173-
if err := utils.WriteFile(outFile, data, 0600); err != nil {
173+
if err := fileutil.WriteFile(outFile, data, 0o600); err != nil {
174174
return err
175175
}
176176

command/ca/renew.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"github.com/smallstep/certificates/pki"
2828
"github.com/smallstep/cli-utils/command"
2929
"github.com/smallstep/cli-utils/errs"
30+
"github.com/smallstep/cli-utils/fileutil"
3031
"github.com/smallstep/cli-utils/ui"
3132
"go.step.sm/crypto/jose"
3233
"go.step.sm/crypto/pemutil"
@@ -35,7 +36,6 @@ import (
3536
"github.com/smallstep/cli/flags"
3637
"github.com/smallstep/cli/internal/cryptoutil"
3738
"github.com/smallstep/cli/token"
38-
"github.com/smallstep/cli/utils"
3939
"github.com/smallstep/cli/utils/cautils"
4040
"github.com/smallstep/cli/utils/sysutils"
4141
)
@@ -495,7 +495,7 @@ func (r *renewer) Renew(outFile string) (resp *api.SignResponse, err error) {
495495
}
496496
data = append(data, pem.EncodeToMemory(pemblk)...)
497497
}
498-
if err := utils.WriteFile(outFile, data, 0600); err != nil {
498+
if err := fileutil.WriteFile(outFile, data, 0o600); err != nil {
499499
return nil, errs.FileError(err, outFile)
500500
}
501501

@@ -526,11 +526,11 @@ func (r *renewer) Rekey(priv interface{}, outCert, outKey string, writePrivateKe
526526
}
527527
data = append(data, pem.EncodeToMemory(pemblk)...)
528528
}
529-
if err := utils.WriteFile(outCert, data, 0600); err != nil {
529+
if err := fileutil.WriteFile(outCert, data, 0o600); err != nil {
530530
return nil, errs.FileError(err, outCert)
531531
}
532532
if writePrivateKey {
533-
_, err = pemutil.Serialize(priv, pemutil.ToFile(outKey, 0600))
533+
_, err = pemutil.Serialize(priv, pemutil.ToFile(outKey, 0o600))
534534
if err != nil {
535535
return nil, err
536536
}

command/ca/token.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/smallstep/certificates/pki"
1212
"github.com/smallstep/cli-utils/command"
1313
"github.com/smallstep/cli-utils/errs"
14+
"github.com/smallstep/cli-utils/fileutil"
1415
"go.step.sm/crypto/pemutil"
1516
"golang.org/x/crypto/ssh"
1617

@@ -435,7 +436,7 @@ func tokenAction(ctx *cli.Context) error {
435436
}
436437
}
437438
if outputFile != "" {
438-
return utils.WriteFile(outputFile, []byte(token), 0600)
439+
return fileutil.WriteFile(outputFile, []byte(token), 0o600)
439440
}
440441
fmt.Println(token)
441442
return nil

command/certificate/bundle.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ import (
99

1010
"github.com/smallstep/cli-utils/command"
1111
"github.com/smallstep/cli-utils/errs"
12+
"github.com/smallstep/cli-utils/fileutil"
1213
"github.com/smallstep/cli-utils/ui"
1314

1415
"github.com/smallstep/cli/flags"
15-
"github.com/smallstep/cli/utils"
1616
)
1717

1818
func bundleCommand() cli.Command {
@@ -77,8 +77,8 @@ func bundleAction(ctx *cli.Context) error {
7777
}
7878

7979
chainFile := ctx.Args().Get(2)
80-
if err := utils.WriteFile(chainFile,
81-
append(pem.EncodeToMemory(crtBlock), pem.EncodeToMemory(caBlock)...), 0600); err != nil {
80+
if err := fileutil.WriteFile(chainFile,
81+
append(pem.EncodeToMemory(crtBlock), pem.EncodeToMemory(caBlock)...), 0o600); err != nil {
8282
return err
8383
}
8484

command/certificate/create.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
"github.com/smallstep/cli-utils/command"
1313
"github.com/smallstep/cli-utils/errs"
14+
"github.com/smallstep/cli-utils/fileutil"
1415
"github.com/smallstep/cli-utils/ui"
1516
"go.step.sm/crypto/keyutil"
1617
"go.step.sm/crypto/pemutil"
@@ -616,7 +617,7 @@ func createAction(ctx *cli.Context) error {
616617
}
617618
}
618619

619-
if err = utils.WriteFile(crtFile, pem.EncodeToMemory(block), 0600); err != nil {
620+
if err = fileutil.WriteFile(crtFile, pem.EncodeToMemory(block), 0o600); err != nil {
620621
return errs.FileError(err, crtFile)
621622
}
622623

@@ -681,7 +682,7 @@ func createAction(ctx *cli.Context) error {
681682
templateData := x509util.CreateTemplateData(subject, sans)
682683
templateData.SetUserData(userData)
683684

684-
var certTemplate = &x509.Certificate{}
685+
certTemplate := &x509.Certificate{}
685686
if skipCSRSignature {
686687
certTemplate.PublicKey = pub
687688
certificate, err := x509util.NewCertificateFromX509(certTemplate, x509util.WithTemplate(template, templateData))
@@ -747,7 +748,7 @@ func createAction(ctx *cli.Context) error {
747748
}
748749
}
749750

750-
if err = utils.WriteFile(crtFile, pubBytes, 0600); err != nil {
751+
if err = fileutil.WriteFile(crtFile, pubBytes, 0o600); err != nil {
751752
return errs.FileError(err, crtFile)
752753
}
753754

@@ -901,7 +902,7 @@ func parseSigner(ctx *cli.Context, defaultSigner crypto.Signer) (*x509.Certifica
901902
func savePrivateKey(ctx *cli.Context, filename string, priv interface{}, insecure bool) error {
902903
var err error
903904
if insecure {
904-
_, err = pemutil.Serialize(priv, pemutil.ToFile(filename, 0600))
905+
_, err = pemutil.Serialize(priv, pemutil.ToFile(filename, 0o600))
905906
return err
906907
}
907908

@@ -918,6 +919,6 @@ func savePrivateKey(ctx *cli.Context, filename string, priv interface{}, insecur
918919
return errors.Wrap(err, "error reading password")
919920
}
920921
}
921-
_, err = pemutil.Serialize(priv, pemutil.WithPassword(pass), pemutil.ToFile(filename, 0600))
922+
_, err = pemutil.Serialize(priv, pemutil.WithPassword(pass), pemutil.ToFile(filename, 0o600))
922923
return err
923924
}

command/certificate/format.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
"github.com/smallstep/cli-utils/command"
1313
"github.com/smallstep/cli-utils/errs"
14+
"github.com/smallstep/cli-utils/fileutil"
1415
"github.com/smallstep/cli-utils/ui"
1516

1617
"github.com/smallstep/cli/flags"
@@ -111,13 +112,13 @@ func formatAction(ctx *cli.Context) error {
111112
if out == "" {
112113
os.Stdout.Write(ob)
113114
} else {
114-
var mode = os.FileMode(0600)
115+
mode := os.FileMode(0o600)
115116
if crtFile != "-" {
116117
if info, err := os.Stat(crtFile); err == nil {
117118
mode = info.Mode()
118119
}
119120
}
120-
if err := utils.WriteFile(out, ob, mode); err != nil {
121+
if err := fileutil.WriteFile(out, ob, mode); err != nil {
121122
return err
122123
}
123124
ui.Printf("Your certificate has been saved in %s\n", out)

command/certificate/key.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
"github.com/smallstep/cli-utils/command"
1010
"github.com/smallstep/cli-utils/errs"
11+
"github.com/smallstep/cli-utils/fileutil"
1112
"github.com/smallstep/cli-utils/ui"
1213
"go.step.sm/crypto/pemutil"
1314

@@ -80,7 +81,7 @@ func keyAction(ctx *cli.Context) error {
8081
}
8182

8283
if outputFile := ctx.String("output-file"); outputFile != "" {
83-
if err := utils.WriteFile(outputFile, pem.EncodeToMemory(block), 0600); err != nil {
84+
if err := fileutil.WriteFile(outputFile, pem.EncodeToMemory(block), 0o600); err != nil {
8485
return err
8586
}
8687
ui.Printf("The public key has been saved in %s.\n", outputFile)

command/certificate/p12.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
"github.com/smallstep/cli-utils/command"
1212
"github.com/smallstep/cli-utils/errs"
13+
"github.com/smallstep/cli-utils/fileutil"
1314
"github.com/smallstep/cli-utils/ui"
1415
"go.step.sm/crypto/pemutil"
1516
"go.step.sm/crypto/x509util"
@@ -188,7 +189,7 @@ func p12Action(ctx *cli.Context) error {
188189
}
189190
}
190191

191-
if err := utils.WriteFile(p12File, pkcs12Data, 0600); err != nil {
192+
if err := fileutil.WriteFile(p12File, pkcs12Data, 0o600); err != nil {
192193
return err
193194
}
194195

command/crypto/change-pass.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ import (
1111

1212
"github.com/smallstep/cli-utils/command"
1313
"github.com/smallstep/cli-utils/errs"
14+
"github.com/smallstep/cli-utils/fileutil"
1415
"github.com/smallstep/cli-utils/ui"
1516
"go.step.sm/crypto/jose"
1617
"go.step.sm/crypto/pemutil"
1718

1819
"github.com/smallstep/cli/flags"
19-
"github.com/smallstep/cli/utils"
2020
)
2121

2222
func changePassCommand() cli.Command {
@@ -136,7 +136,7 @@ func changePassAction(ctx *cli.Context) error {
136136
opts = append(opts, pemutil.WithPassword(pass))
137137
}
138138
}
139-
opts = append(opts, pemutil.ToFile(newKeyPath, 0644))
139+
opts = append(opts, pemutil.ToFile(newKeyPath, 0o644))
140140
if _, err := pemutil.Serialize(key, opts...); err != nil {
141141
return err
142142
}
@@ -172,7 +172,7 @@ func changePassAction(ctx *cli.Context) error {
172172
if err := json.Indent(&out, b, "", " "); err != nil {
173173
return errors.Wrap(err, "error formatting JSON")
174174
}
175-
if err := utils.WriteFile(newKeyPath, out.Bytes(), 0600); err != nil {
175+
if err := fileutil.WriteFile(newKeyPath, out.Bytes(), 0o600); err != nil {
176176
return errs.FileError(err, newKeyPath)
177177
}
178178
}

command/crypto/jwk/create.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313

1414
"github.com/smallstep/cli-utils/command"
1515
"github.com/smallstep/cli-utils/errs"
16+
"github.com/smallstep/cli-utils/fileutil"
1617
"github.com/smallstep/cli-utils/ui"
1718
"go.step.sm/crypto/jose"
1819
"go.step.sm/crypto/keyutil"
@@ -515,7 +516,7 @@ func createAction(ctx *cli.Context) (err error) {
515516
if err != nil {
516517
return errors.Wrap(err, "error marshaling JWK")
517518
}
518-
if err = utils.WriteFile(pubFile, b, 0600); err != nil {
519+
if err = fileutil.WriteFile(pubFile, b, 0o600); err != nil {
519520
return errs.FileError(err, pubFile)
520521
}
521522

@@ -589,7 +590,7 @@ func createAction(ctx *cli.Context) (err error) {
589590
return errors.Wrap(err, "error marshaling JWK")
590591
}
591592
}
592-
if err = utils.WriteFile(privFile, b, 0600); err != nil {
593+
if err = fileutil.WriteFile(privFile, b, 0o600); err != nil {
593594
return errs.FileError(err, privFile)
594595
}
595596

0 commit comments

Comments
 (0)