Skip to content

Commit 553e77e

Browse files
committed
chore: fix linter rules
1 parent 8f94f54 commit 553e77e

File tree

7 files changed

+15
-90
lines changed

7 files changed

+15
-90
lines changed

cmd/cloudflared/generic_service.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import (
77
"os"
88

99
cli "github.com/urfave/cli/v2"
10+
11+
"github.com/cloudflare/cloudflared/cmd/cloudflared/cliutil"
1012
)
1113

1214
func runApp(app *cli.App, graceShutdownC chan struct{}) {

cmd/cloudflared/service_template.go

Lines changed: 2 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package main
22

33
import (
4-
"bufio"
54
"bytes"
5+
"errors"
66
"fmt"
77
"io"
88
"os"
@@ -44,7 +44,7 @@ func (st *ServiceTemplate) Generate(args *ServiceTemplateArgs) error {
4444
return err
4545
}
4646
if _, err = os.Stat(resolvedPath); err == nil {
47-
return fmt.Errorf(serviceAlreadyExistsWarn(resolvedPath))
47+
return errors.New(serviceAlreadyExistsWarn(resolvedPath))
4848
}
4949

5050
var buffer bytes.Buffer
@@ -118,49 +118,6 @@ func ensureConfigDirExists(configDir string) error {
118118
return err
119119
}
120120

121-
// openFile opens the file at path. If create is set and the file exists, returns nil, true, nil
122-
func openFile(path string, create bool) (file *os.File, exists bool, err error) {
123-
expandedPath, err := homedir.Expand(path)
124-
if err != nil {
125-
return nil, false, err
126-
}
127-
if create {
128-
fileInfo, err := os.Stat(expandedPath)
129-
if err == nil && fileInfo.Size() > 0 {
130-
return nil, true, nil
131-
}
132-
file, err = os.OpenFile(expandedPath, os.O_RDWR|os.O_CREATE, 0600)
133-
} else {
134-
file, err = os.Open(expandedPath)
135-
}
136-
return file, false, err
137-
}
138-
139-
func copyCredential(srcCredentialPath, destCredentialPath string) error {
140-
destFile, exists, err := openFile(destCredentialPath, true)
141-
if err != nil {
142-
return err
143-
} else if exists {
144-
// credentials already exist, do nothing
145-
return nil
146-
}
147-
defer destFile.Close()
148-
149-
srcFile, _, err := openFile(srcCredentialPath, false)
150-
if err != nil {
151-
return err
152-
}
153-
defer srcFile.Close()
154-
155-
// Copy certificate
156-
_, err = io.Copy(destFile, srcFile)
157-
if err != nil {
158-
return fmt.Errorf("unable to copy %s to %s: %v", srcCredentialPath, destCredentialPath, err)
159-
}
160-
161-
return nil
162-
}
163-
164121
func copyFile(src, dest string) error {
165122
srcFile, err := os.Open(src)
166123
if err != nil {
@@ -187,36 +144,3 @@ func copyFile(src, dest string) error {
187144
ok = true
188145
return nil
189146
}
190-
191-
func copyConfig(srcConfigPath, destConfigPath string) error {
192-
// Copy or create config
193-
destFile, exists, err := openFile(destConfigPath, true)
194-
if err != nil {
195-
return fmt.Errorf("cannot open %s with error: %s", destConfigPath, err)
196-
} else if exists {
197-
// config already exists, do nothing
198-
return nil
199-
}
200-
defer destFile.Close()
201-
202-
srcFile, _, err := openFile(srcConfigPath, false)
203-
if err != nil {
204-
fmt.Println("Your service needs a config file that at least specifies the hostname option.")
205-
fmt.Println("Type in a hostname now, or leave it blank and create the config file later.")
206-
fmt.Print("Hostname: ")
207-
reader := bufio.NewReader(os.Stdin)
208-
input, _ := reader.ReadString('\n')
209-
if input == "" {
210-
return err
211-
}
212-
fmt.Fprintf(destFile, "hostname: %s\n", input)
213-
} else {
214-
defer srcFile.Close()
215-
_, err = io.Copy(destFile, srcFile)
216-
if err != nil {
217-
return fmt.Errorf("unable to copy %s to %s: %v", srcConfigPath, destConfigPath, err)
218-
}
219-
}
220-
221-
return nil
222-
}

cmd/cloudflared/tunnel/teamnet_subcommands.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ var (
2222
Usage: "The ID or name of the virtual network to which the route is associated to.",
2323
}
2424

25-
routeAddError = errors.New("You must supply exactly one argument, the ID or CIDR of the route you want to delete")
25+
errAddRoute = errors.New("You must supply exactly one argument, the ID or CIDR of the route you want to delete")
2626
)
2727

2828
func buildRouteIPSubcommand() *cli.Command {
@@ -187,15 +187,15 @@ func deleteRouteCommand(c *cli.Context) error {
187187
}
188188

189189
if c.NArg() != 1 {
190-
return routeAddError
190+
return errAddRoute
191191
}
192192

193193
var routeId uuid.UUID
194194
routeId, err = uuid.Parse(c.Args().First())
195195
if err != nil {
196196
_, network, err := net.ParseCIDR(c.Args().First())
197197
if err != nil || network == nil {
198-
return routeAddError
198+
return errAddRoute
199199
}
200200

201201
var vnetId *uuid.UUID

cmd/cloudflared/updater/workers_update.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ func (v *WorkersVersion) Apply() error {
134134

135135
if err := os.Rename(newFilePath, v.targetPath); err != nil {
136136
//attempt rollback
137-
os.Rename(oldFilePath, v.targetPath)
137+
_ = os.Rename(oldFilePath, v.targetPath)
138138
return err
139139
}
140140
os.Remove(oldFilePath)
@@ -181,7 +181,7 @@ func download(url, filepath string, isCompressed bool) error {
181181
tr := tar.NewReader(gr)
182182

183183
// advance the reader pass the header, which will be the single binary file
184-
tr.Next()
184+
_, _ = tr.Next()
185185

186186
r = tr
187187
}
@@ -249,7 +249,6 @@ func runWindowsBatch(batchFile string) error {
249249
if exitError, ok := err.(*exec.ExitError); ok {
250250
return fmt.Errorf("Error during update : %s;", string(exitError.Stderr))
251251
}
252-
253252
}
254253
return err
255254
}

credentials/credentials_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func TestCredentialsRead(t *testing.T) {
1414
require.NoError(t, err)
1515
dir := t.TempDir()
1616
certPath := filepath.Join(dir, originCertFile)
17-
os.WriteFile(certPath, file, fs.ModePerm)
17+
_ = os.WriteFile(certPath, file, fs.ModePerm)
1818
user, err := Read(certPath, &nopLog)
1919
require.NoError(t, err)
2020
require.Equal(t, certPath, user.CertPath())

management/events.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ type EventLog struct {
7474
type LogEventType int8
7575

7676
const (
77-
// Cloudflared events are signficant to cloudflared operations like connection state changes.
77+
// Cloudflared events are significant to cloudflared operations like connection state changes.
7878
// Cloudflared is also the default event type for any events that haven't been separated into a proper event type.
7979
Cloudflared LogEventType = iota
8080
HTTP

retry/backoffhandler.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ func (b *BackoffHandler) BackoffTimer() <-chan time.Time {
7979
} else {
8080
b.retries++
8181
}
82-
maxTimeToWait := time.Duration(b.GetBaseTime() * 1 << (b.retries))
83-
timeToWait := time.Duration(rand.Int63n(maxTimeToWait.Nanoseconds()))
82+
maxTimeToWait := b.GetBaseTime() * (1 << b.retries)
83+
timeToWait := time.Duration(rand.Int63n(maxTimeToWait.Nanoseconds())) // #nosec G404
8484
return b.Clock.After(timeToWait)
8585
}
8686

@@ -103,7 +103,7 @@ func (b *BackoffHandler) Backoff(ctx context.Context) bool {
103103
// period expires, the number of retries & backoff duration is reset.
104104
func (b *BackoffHandler) SetGracePeriod() time.Duration {
105105
maxTimeToWait := b.GetBaseTime() * 2 << (b.retries + 1)
106-
timeToWait := time.Duration(rand.Int63n(maxTimeToWait.Nanoseconds()))
106+
timeToWait := time.Duration(rand.Int63n(maxTimeToWait.Nanoseconds())) // #nosec G404
107107
b.resetDeadline = b.Clock.Now().Add(timeToWait)
108108

109109
return timeToWait
@@ -118,7 +118,7 @@ func (b BackoffHandler) GetBaseTime() time.Duration {
118118

119119
// Retries returns the number of retries consumed so far.
120120
func (b *BackoffHandler) Retries() int {
121-
return int(b.retries)
121+
return int(b.retries) // #nosec G115
122122
}
123123

124124
func (b *BackoffHandler) ReachedMaxRetries() bool {

0 commit comments

Comments
 (0)