Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions command/ca/federation.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import (
"github.com/smallstep/certificates/pki"
"github.com/smallstep/cli-utils/command"
"github.com/smallstep/cli-utils/errs"
"github.com/smallstep/cli-utils/fileutil"
"github.com/smallstep/cli-utils/ui"
"go.step.sm/crypto/pemutil"

"github.com/smallstep/cli/flags"
"github.com/smallstep/cli/utils"
)

type flowType int
Expand Down Expand Up @@ -170,7 +170,7 @@ func rootsAndFederationFlow(ctx *cli.Context, typ flowType) error {
}

if outFile := ctx.Args().Get(0); outFile != "" {
if err := utils.WriteFile(outFile, data, 0600); err != nil {
if err := fileutil.WriteFile(outFile, data, 0o600); err != nil {
return err
}

Expand Down
8 changes: 4 additions & 4 deletions command/ca/renew.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/smallstep/certificates/pki"
"github.com/smallstep/cli-utils/command"
"github.com/smallstep/cli-utils/errs"
"github.com/smallstep/cli-utils/fileutil"
"github.com/smallstep/cli-utils/ui"
"go.step.sm/crypto/jose"
"go.step.sm/crypto/pemutil"
Expand All @@ -35,7 +36,6 @@ import (
"github.com/smallstep/cli/flags"
"github.com/smallstep/cli/internal/cryptoutil"
"github.com/smallstep/cli/token"
"github.com/smallstep/cli/utils"
"github.com/smallstep/cli/utils/cautils"
"github.com/smallstep/cli/utils/sysutils"
)
Expand Down Expand Up @@ -495,7 +495,7 @@ func (r *renewer) Renew(outFile string) (resp *api.SignResponse, err error) {
}
data = append(data, pem.EncodeToMemory(pemblk)...)
}
if err := utils.WriteFile(outFile, data, 0600); err != nil {
if err := fileutil.WriteFile(outFile, data, 0o600); err != nil {
return nil, errs.FileError(err, outFile)
}

Expand Down Expand Up @@ -526,11 +526,11 @@ func (r *renewer) Rekey(priv interface{}, outCert, outKey string, writePrivateKe
}
data = append(data, pem.EncodeToMemory(pemblk)...)
}
if err := utils.WriteFile(outCert, data, 0600); err != nil {
if err := fileutil.WriteFile(outCert, data, 0o600); err != nil {
return nil, errs.FileError(err, outCert)
}
if writePrivateKey {
_, err = pemutil.Serialize(priv, pemutil.ToFile(outKey, 0600))
_, err = pemutil.Serialize(priv, pemutil.ToFile(outKey, 0o600))
if err != nil {
return nil, err
}
Expand Down
3 changes: 2 additions & 1 deletion command/ca/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/smallstep/certificates/pki"
"github.com/smallstep/cli-utils/command"
"github.com/smallstep/cli-utils/errs"
"github.com/smallstep/cli-utils/fileutil"
"go.step.sm/crypto/pemutil"
"golang.org/x/crypto/ssh"

Expand Down Expand Up @@ -435,7 +436,7 @@ func tokenAction(ctx *cli.Context) error {
}
}
if outputFile != "" {
return utils.WriteFile(outputFile, []byte(token), 0600)
return fileutil.WriteFile(outputFile, []byte(token), 0o600)
}
fmt.Println(token)
return nil
Expand Down
6 changes: 3 additions & 3 deletions command/certificate/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (

"github.com/smallstep/cli-utils/command"
"github.com/smallstep/cli-utils/errs"
"github.com/smallstep/cli-utils/fileutil"
"github.com/smallstep/cli-utils/ui"

"github.com/smallstep/cli/flags"
"github.com/smallstep/cli/utils"
)

func bundleCommand() cli.Command {
Expand Down Expand Up @@ -77,8 +77,8 @@ func bundleAction(ctx *cli.Context) error {
}

chainFile := ctx.Args().Get(2)
if err := utils.WriteFile(chainFile,
append(pem.EncodeToMemory(crtBlock), pem.EncodeToMemory(caBlock)...), 0600); err != nil {
if err := fileutil.WriteFile(chainFile,
append(pem.EncodeToMemory(crtBlock), pem.EncodeToMemory(caBlock)...), 0o600); err != nil {
return err
}

Expand Down
11 changes: 6 additions & 5 deletions command/certificate/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/smallstep/cli-utils/command"
"github.com/smallstep/cli-utils/errs"
"github.com/smallstep/cli-utils/fileutil"
"github.com/smallstep/cli-utils/ui"
"go.step.sm/crypto/keyutil"
"go.step.sm/crypto/pemutil"
Expand Down Expand Up @@ -616,7 +617,7 @@ func createAction(ctx *cli.Context) error {
}
}

if err = utils.WriteFile(crtFile, pem.EncodeToMemory(block), 0600); err != nil {
if err = fileutil.WriteFile(crtFile, pem.EncodeToMemory(block), 0o600); err != nil {
return errs.FileError(err, crtFile)
}

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

var certTemplate = &x509.Certificate{}
certTemplate := &x509.Certificate{}
if skipCSRSignature {
certTemplate.PublicKey = pub
certificate, err := x509util.NewCertificateFromX509(certTemplate, x509util.WithTemplate(template, templateData))
Expand Down Expand Up @@ -747,7 +748,7 @@ func createAction(ctx *cli.Context) error {
}
}

if err = utils.WriteFile(crtFile, pubBytes, 0600); err != nil {
if err = fileutil.WriteFile(crtFile, pubBytes, 0o600); err != nil {
return errs.FileError(err, crtFile)
}

Expand Down Expand Up @@ -901,7 +902,7 @@ func parseSigner(ctx *cli.Context, defaultSigner crypto.Signer) (*x509.Certifica
func savePrivateKey(ctx *cli.Context, filename string, priv interface{}, insecure bool) error {
var err error
if insecure {
_, err = pemutil.Serialize(priv, pemutil.ToFile(filename, 0600))
_, err = pemutil.Serialize(priv, pemutil.ToFile(filename, 0o600))
return err
}

Expand All @@ -918,6 +919,6 @@ func savePrivateKey(ctx *cli.Context, filename string, priv interface{}, insecur
return errors.Wrap(err, "error reading password")
}
}
_, err = pemutil.Serialize(priv, pemutil.WithPassword(pass), pemutil.ToFile(filename, 0600))
_, err = pemutil.Serialize(priv, pemutil.WithPassword(pass), pemutil.ToFile(filename, 0o600))
return err
}
5 changes: 3 additions & 2 deletions command/certificate/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/smallstep/cli-utils/command"
"github.com/smallstep/cli-utils/errs"
"github.com/smallstep/cli-utils/fileutil"
"github.com/smallstep/cli-utils/ui"

"github.com/smallstep/cli/flags"
Expand Down Expand Up @@ -111,13 +112,13 @@ func formatAction(ctx *cli.Context) error {
if out == "" {
os.Stdout.Write(ob)
} else {
var mode = os.FileMode(0600)
mode := os.FileMode(0o600)
if crtFile != "-" {
if info, err := os.Stat(crtFile); err == nil {
mode = info.Mode()
}
}
if err := utils.WriteFile(out, ob, mode); err != nil {
if err := fileutil.WriteFile(out, ob, mode); err != nil {
return err
}
ui.Printf("Your certificate has been saved in %s\n", out)
Expand Down
3 changes: 2 additions & 1 deletion command/certificate/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/smallstep/cli-utils/command"
"github.com/smallstep/cli-utils/errs"
"github.com/smallstep/cli-utils/fileutil"
"github.com/smallstep/cli-utils/ui"
"go.step.sm/crypto/pemutil"

Expand Down Expand Up @@ -80,7 +81,7 @@ func keyAction(ctx *cli.Context) error {
}

if outputFile := ctx.String("output-file"); outputFile != "" {
if err := utils.WriteFile(outputFile, pem.EncodeToMemory(block), 0600); err != nil {
if err := fileutil.WriteFile(outputFile, pem.EncodeToMemory(block), 0o600); err != nil {
return err
}
ui.Printf("The public key has been saved in %s.\n", outputFile)
Expand Down
3 changes: 2 additions & 1 deletion command/certificate/p12.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/smallstep/cli-utils/command"
"github.com/smallstep/cli-utils/errs"
"github.com/smallstep/cli-utils/fileutil"
"github.com/smallstep/cli-utils/ui"
"go.step.sm/crypto/pemutil"
"go.step.sm/crypto/x509util"
Expand Down Expand Up @@ -188,7 +189,7 @@ func p12Action(ctx *cli.Context) error {
}
}

if err := utils.WriteFile(p12File, pkcs12Data, 0600); err != nil {
if err := fileutil.WriteFile(p12File, pkcs12Data, 0o600); err != nil {
return err
}

Expand Down
6 changes: 3 additions & 3 deletions command/crypto/change-pass.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import (

"github.com/smallstep/cli-utils/command"
"github.com/smallstep/cli-utils/errs"
"github.com/smallstep/cli-utils/fileutil"
"github.com/smallstep/cli-utils/ui"
"go.step.sm/crypto/jose"
"go.step.sm/crypto/pemutil"

"github.com/smallstep/cli/flags"
"github.com/smallstep/cli/utils"
)

func changePassCommand() cli.Command {
Expand Down Expand Up @@ -136,7 +136,7 @@ func changePassAction(ctx *cli.Context) error {
opts = append(opts, pemutil.WithPassword(pass))
}
}
opts = append(opts, pemutil.ToFile(newKeyPath, 0644))
opts = append(opts, pemutil.ToFile(newKeyPath, 0o644))
if _, err := pemutil.Serialize(key, opts...); err != nil {
return err
}
Expand Down Expand Up @@ -172,7 +172,7 @@ func changePassAction(ctx *cli.Context) error {
if err := json.Indent(&out, b, "", " "); err != nil {
return errors.Wrap(err, "error formatting JSON")
}
if err := utils.WriteFile(newKeyPath, out.Bytes(), 0600); err != nil {
if err := fileutil.WriteFile(newKeyPath, out.Bytes(), 0o600); err != nil {
return errs.FileError(err, newKeyPath)
}
}
Expand Down
5 changes: 3 additions & 2 deletions command/crypto/jwk/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/smallstep/cli-utils/command"
"github.com/smallstep/cli-utils/errs"
"github.com/smallstep/cli-utils/fileutil"
"github.com/smallstep/cli-utils/ui"
"go.step.sm/crypto/jose"
"go.step.sm/crypto/keyutil"
Expand Down Expand Up @@ -515,7 +516,7 @@ func createAction(ctx *cli.Context) (err error) {
if err != nil {
return errors.Wrap(err, "error marshaling JWK")
}
if err = utils.WriteFile(pubFile, b, 0600); err != nil {
if err = fileutil.WriteFile(pubFile, b, 0o600); err != nil {
return errs.FileError(err, pubFile)
}

Expand Down Expand Up @@ -589,7 +590,7 @@ func createAction(ctx *cli.Context) (err error) {
return errors.Wrap(err, "error marshaling JWK")
}
}
if err = utils.WriteFile(privFile, b, 0600); err != nil {
if err = fileutil.WriteFile(privFile, b, 0o600); err != nil {
return errs.FileError(err, privFile)
}

Expand Down
3 changes: 2 additions & 1 deletion command/crypto/key/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/urfave/cli"

"github.com/smallstep/cli-utils/errs"
"github.com/smallstep/cli-utils/fileutil"
"github.com/smallstep/cli-utils/ui"
"go.step.sm/crypto/jose"
"go.step.sm/crypto/pemutil"
Expand Down Expand Up @@ -274,7 +275,7 @@ func formatAction(ctx *cli.Context) error {
if err != nil {
return errs.FileError(err, keyFile)
}
if err := utils.WriteFile(out, ob, info.Mode()); err != nil {
if err := fileutil.WriteFile(out, ob, info.Mode()); err != nil {
return errs.FileError(err, out)
}
ui.Printf("Your key has been saved in %s.\n", out)
Expand Down
5 changes: 3 additions & 2 deletions command/crypto/key/public.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/smallstep/cli-utils/command"
"github.com/smallstep/cli-utils/errs"
"github.com/smallstep/cli-utils/fileutil"
"github.com/smallstep/cli-utils/ui"
"go.step.sm/crypto/keyutil"
"go.step.sm/crypto/pemutil"
Expand Down Expand Up @@ -73,7 +74,7 @@ func publicAction(ctx *cli.Context) error {
return errs.TooManyArguments(ctx)
}

var b, err = utils.ReadFile(name)
b, err := utils.ReadFile(name)
if err != nil {
return errs.FileError(err, name)
}
Expand All @@ -98,7 +99,7 @@ func publicAction(ctx *cli.Context) error {
}

if out := ctx.String("out"); out != "" {
if err := utils.WriteFile(out, pem.EncodeToMemory(block), 0600); err != nil {
if err := fileutil.WriteFile(out, pem.EncodeToMemory(block), 0o600); err != nil {
return err
}
ui.Printf("The public key has been saved in %s.\n", out)
Expand Down
5 changes: 3 additions & 2 deletions command/crypto/nacl/box.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/smallstep/cli-utils/command"
"github.com/smallstep/cli-utils/errs"
"github.com/smallstep/cli-utils/fileutil"
"github.com/smallstep/cli-utils/ui"

"github.com/smallstep/cli/flags"
Expand Down Expand Up @@ -219,11 +220,11 @@ func boxKeypairAction(ctx *cli.Context) error {
return errors.Wrap(err, "error generating key")
}

if err := utils.WriteFile(pubFile, pub[:], 0600); err != nil {
if err := fileutil.WriteFile(pubFile, pub[:], 0o600); err != nil {
return errs.FileError(err, pubFile)
}

if err := utils.WriteFile(privFile, priv[:], 0600); err != nil {
if err := fileutil.WriteFile(privFile, priv[:], 0o600); err != nil {
return errs.FileError(err, privFile)
}

Expand Down
5 changes: 3 additions & 2 deletions command/crypto/nacl/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/smallstep/cli-utils/command"
"github.com/smallstep/cli-utils/errs"
"github.com/smallstep/cli-utils/fileutil"
"github.com/smallstep/cli-utils/ui"

"github.com/smallstep/cli/flags"
Expand Down Expand Up @@ -137,11 +138,11 @@ func signKeypairAction(ctx *cli.Context) error {
return errors.Wrap(err, "error generating key")
}

if err := utils.WriteFile(pubFile, pub[:], 0600); err != nil {
if err := fileutil.WriteFile(pubFile, pub[:], 0o600); err != nil {
return errs.FileError(err, pubFile)
}

if err := utils.WriteFile(privFile, priv[:], 0600); err != nil {
if err := fileutil.WriteFile(privFile, priv[:], 0o600); err != nil {
return errs.FileError(err, privFile)
}

Expand Down
4 changes: 2 additions & 2 deletions command/crypto/otp/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import (

"github.com/smallstep/cli-utils/command"
"github.com/smallstep/cli-utils/errs"
"github.com/smallstep/cli-utils/fileutil"

"github.com/smallstep/cli/flags"
"github.com/smallstep/cli/internal/cast"
"github.com/smallstep/cli/utils"
)

func generateCommand() cli.Command {
Expand Down Expand Up @@ -96,7 +96,7 @@ func generateAction(ctx *cli.Context) error {
return err
}
png.Encode(&buf, img)
if err := utils.WriteFile(filename, buf.Bytes(), 0644); err != nil {
if err := fileutil.WriteFile(filename, buf.Bytes(), 0o644); err != nil {
return errs.FileError(err, filename)
}
}
Expand Down
Loading
Loading