Skip to content

Commit 4e0aa90

Browse files
author
J.C. Jones
committed
Rebase 'lint-errcheck-fixes' of git://github.com/mvdan/boulder to letsencrypt/master
Conflicts: cmd/boulder-start/main.go core/interfaces.go core/objects.go core/util.go ra/registration-authority.go ra/registration-authority_test.go rpc/rpc-wrappers.go va/validation-authority.go wfe/web-front-end.go
2 parents 984b156 + 70ab4a4 commit 4e0aa90

File tree

16 files changed

+184
-197
lines changed

16 files changed

+184
-197
lines changed

analysis/analysis-engine.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// This Source Code Form is subject to the terms of the Mozilla Public
33
// License, v. 2.0. If a copy of the MPL was not distributed with this
44
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
5+
56
package analysisengine
67

78
import (
@@ -19,7 +20,7 @@ type AnalysisEngine interface {
1920

2021
// An Analysis Engine that just logs to the JSON Logger.
2122
type LoggingAnalysisEngine struct {
22-
jsonLogger *log.JsonLogger
23+
jsonLogger *log.JSONLogger
2324
}
2425

2526
func (eng *LoggingAnalysisEngine) ProcessMessage(delivery amqp.Delivery) {
@@ -28,6 +29,6 @@ func (eng *LoggingAnalysisEngine) ProcessMessage(delivery amqp.Delivery) {
2829
}
2930

3031
// Construct a new Analysis Engine.
31-
func NewLoggingAnalysisEngine(logger *log.JsonLogger) AnalysisEngine {
32+
func NewLoggingAnalysisEngine(logger *log.JSONLogger) AnalysisEngine {
3233
return &LoggingAnalysisEngine{jsonLogger: logger}
3334
}

analysis/analysis-engine_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@
22
// This Source Code Form is subject to the terms of the Mozilla Public
33
// License, v. 2.0. If a copy of the MPL was not distributed with this
44
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
5+
56
package analysisengine
67

78
import (
9+
"testing"
10+
811
"github.com/letsencrypt/boulder/log"
912
"github.com/streadway/amqp"
10-
"testing"
1113
)
1214

1315
func TestNewLoggingAnalysisEngine(t *testing.T) {
14-
log := log.NewJsonLogger("newEngine")
16+
log := log.NewJSONLogger("newEngine")
1517
ae := NewLoggingAnalysisEngine(log)
1618

1719
// Trivially check an empty mock message

cmd/activity-monitor/main.go

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
package main
77

88
import (
9-
"github.com/codegangsta/cli"
10-
"github.com/streadway/amqp"
119
"log"
1210
"net/url"
1311
"os"
1412

13+
"github.com/codegangsta/cli"
14+
"github.com/streadway/amqp"
15+
1516
"github.com/letsencrypt/boulder/analysis"
1617
blog "github.com/letsencrypt/boulder/log"
1718
)
@@ -31,7 +32,7 @@ const (
3132
AmqpImmediate = false
3233
)
3334

34-
func startMonitor(AmqpUrl string, logger *blog.JsonLogger) {
35+
func startMonitor(AmqpURL string, logger *blog.JSONLogger) {
3536

3637
ae := analysisengine.NewLoggingAnalysisEngine(logger)
3738

@@ -41,16 +42,14 @@ func startMonitor(AmqpUrl string, logger *blog.JsonLogger) {
4142
log.Fatalf("Could not determine hostname")
4243
}
4344

44-
conn, err := amqp.Dial(AmqpUrl)
45+
conn, err := amqp.Dial(AmqpURL)
4546
if err != nil {
4647
log.Fatalf("Could not connect to AMQP server: %s", err)
47-
return
4848
}
4949

5050
rpcCh, err := conn.Channel()
5151
if err != nil {
5252
log.Fatalf("Could not start channel: %s", err)
53-
return
5453
}
5554

5655
err = rpcCh.ExchangeDeclare(
@@ -63,7 +62,6 @@ func startMonitor(AmqpUrl string, logger *blog.JsonLogger) {
6362
nil)
6463
if err != nil {
6564
log.Fatalf("Could not declare exchange: %s", err)
66-
return
6765
}
6866

6967
_, err = rpcCh.QueueDeclare(
@@ -75,7 +73,6 @@ func startMonitor(AmqpUrl string, logger *blog.JsonLogger) {
7573
nil)
7674
if err != nil {
7775
log.Fatalf("Could not declare queue: %s", err)
78-
return
7976
}
8077

8178
err = rpcCh.QueueBind(
@@ -86,7 +83,6 @@ func startMonitor(AmqpUrl string, logger *blog.JsonLogger) {
8683
nil)
8784
if err != nil {
8885
log.Fatalf("Could not bind queue: %s", err)
89-
return
9086
}
9187

9288
deliveries, err := rpcCh.Consume(
@@ -99,7 +95,6 @@ func startMonitor(AmqpUrl string, logger *blog.JsonLogger) {
9995
nil)
10096
if err != nil {
10197
log.Fatalf("Could not subscribe to queue: %s", err)
102-
return
10398
}
10499

105100
// Run forever.
@@ -141,7 +136,7 @@ func main() {
141136
}
142137

143138
app.Action = func(c *cli.Context) {
144-
logger := blog.NewJsonLogger("am")
139+
logger := blog.NewJSONLogger("am")
145140

146141
// Parse SysLog URL if one was provided
147142
if c.GlobalString("jsonlog") == "" {
@@ -151,14 +146,12 @@ func main() {
151146
syslogU, err := url.Parse(c.GlobalString("jsonlog"))
152147
if err != nil {
153148
log.Fatalf("Could not parse Syslog URL: %s", err)
154-
return
155149
}
156150

157151
logger.SetEndpoint(syslogU.Scheme, syslogU.Host)
158152
err = logger.Connect()
159153
if err != nil {
160154
log.Fatalf("Could not open remote syslog: %s", err)
161-
return
162155
}
163156

164157
logger.EnableStdOut(c.GlobalBool("stdout"))
@@ -170,9 +163,7 @@ func main() {
170163
startMonitor(c.GlobalString("amqp"), logger)
171164
}
172165

173-
err := app.Run(os.Args)
174-
if err != nil {
166+
if err := app.Run(os.Args); err != nil {
175167
log.Fatalf("Could not start: %s", err)
176-
return
177168
}
178169
}

cmd/boulder-start/main.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func amqpChannel(url string) (ch *amqp.Channel) {
4242
}
4343

4444
// Start the server and wait around
45-
func runForever(server *rpc.AmqpRpcServer) {
45+
func runForever(server *rpc.AmqpRPCServer) {
4646
forever := make(chan bool)
4747
server.Start()
4848
fmt.Fprintf(os.Stderr, "Server running...\n")
@@ -310,6 +310,7 @@ func main() {
310310
authzPath := "/acme/authz/"
311311
newCertPath := "/acme/new-cert"
312312
certPath := "/acme/cert/"
313+
313314
wfe.NewReg = urlBase + newRegPath
314315
wfe.RegBase = urlBase + regPath
315316
wfe.NewAuthz = urlBase + newAuthzPath
@@ -324,7 +325,8 @@ func main() {
324325
http.HandleFunc(certPath, wfe.Certificate)
325326

326327
fmt.Fprintf(os.Stderr, "Server running, listening on %s...\n", c.String("listenAddress"))
327-
http.ListenAndServe(c.String("listenAddress"), nil)
328+
err = http.ListenAndServe(c.String("listenAddress"), nil)
329+
failOnError(err, "Error starting HTTP server")
328330
},
329331
},
330332
{

core/challenges.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func SimpleHTTPSChallenge() Challenge {
2020

2121
func DvsniChallenge() Challenge {
2222
nonce := make([]byte, 16)
23-
rand.Read(nonce)
23+
_, _ = rand.Read(nonce) // NOTE: Ignoring errors
2424
return Challenge{
2525
Type: ChallengeTypeDVSNI,
2626
Status: StatusPending,

core/objects.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const (
2626
)
2727

2828
const (
29-
ChallengeTypeSimpleHTTPS = "simpleHttps"
29+
ChallengeTypeSimpleHTTPS = "simpleHTTPS"
3030
ChallengeTypeDVSNI = "dvsni"
3131
ChallengeTypeDNS = "dns"
3232
ChallengeTypeRecoveryToken = "recoveryToken"
@@ -66,8 +66,7 @@ type rawCertificateRequest struct {
6666

6767
func (cr *CertificateRequest) UnmarshalJSON(data []byte) error {
6868
var raw rawCertificateRequest
69-
err := json.Unmarshal(data, &raw)
70-
if err != nil {
69+
if err := json.Unmarshal(data, &raw); err != nil {
7170
return err
7271
}
7372

@@ -135,10 +134,10 @@ type Challenge struct {
135134
// A URI to which a response can be POSTed
136135
URI AcmeURL `json:"uri"`
137136

138-
// Used by simpleHttps, recoveryToken, and dns challenges
137+
// Used by simpleHTTPS, recoveryToken, and dns challenges
139138
Token string `json:"token,omitempty"`
140139

141-
// Used by simpleHttps challenges
140+
// Used by simpleHTTPS challenges
142141
Path string `json:"path,omitempty"`
143142

144143
// Used by dvsni challenges

core/util.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func B64dec(x string) ([]byte, error) {
7070

7171
func RandomString(byteLength int) string {
7272
b := make([]byte, byteLength)
73-
rand.Read(b) // NOTE: Ignoring errors
73+
_, _ = rand.Read(b) // NOTE: Ignoring errors
7474
return B64enc(b)
7575
}
7676

@@ -82,7 +82,7 @@ func NewToken() string {
8282

8383
func Fingerprint256(data []byte) string {
8484
d := sha256.New()
85-
d.Write(data)
85+
_, _ = d.Write(data) // Never returns an error
8686
return B64enc(d.Sum(nil))
8787
}
8888

@@ -104,8 +104,7 @@ func (u AcmeURL) MarshalJSON() ([]byte, error) {
104104

105105
func (u *AcmeURL) UnmarshalJSON(data []byte) error {
106106
var str string
107-
err := json.Unmarshal(data, &str)
108-
if err != nil {
107+
if err := json.Unmarshal(data, &str); err != nil {
109108
return err
110109
}
111110

@@ -143,7 +142,7 @@ func VerifyCSR(csr *x509.CertificateRequest) error {
143142
default:
144143
return errors.New("Unsupported CSR signing algorithm")
145144
}
146-
hash.Write(csr.RawTBSCertificateRequest)
145+
_, _ = hash.Write(csr.RawTBSCertificateRequest) // Never returns an error
147146
inputHash := hash.Sum(nil)
148147

149148
// Verify the signature using the public key in the CSR

log/json-logger.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// This Source Code Form is subject to the terms of the Mozilla Public
33
// License, v. 2.0. If a copy of the MPL was not distributed with this
44
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
5+
56
package log
67

78
import (
@@ -50,7 +51,7 @@ type LogMessage struct {
5051
}
5152

5253
// Structure to hold logger details.
53-
type JsonLogger struct {
54+
type JSONLogger struct {
5455
stdout bool // True if logging to stdout (independent of network)
5556
online bool // True if logging to network
5657
scheme string // Golang net URI scheme (tcp/udp)
@@ -61,28 +62,28 @@ type JsonLogger struct {
6162
program string // Defines the 'program' field in JSON
6263
}
6364

64-
func NewJsonLogger(programName string) *JsonLogger {
65-
return &JsonLogger{
65+
func NewJSONLogger(programName string) *JSONLogger {
66+
return &JSONLogger{
6667
program: programName,
6768
level: 7, // Default to all
6869
}
6970
}
7071

71-
func (jl *JsonLogger) EnableStdOut(stdout bool) {
72+
func (jl *JSONLogger) EnableStdOut(stdout bool) {
7273
jl.stdout = stdout
7374
}
7475

75-
func (jl *JsonLogger) SetLevel(level int) {
76+
func (jl *JSONLogger) SetLevel(level int) {
7677
jl.level = level
7778
}
7879

79-
func (jl *JsonLogger) SetEndpoint(scheme string, host string) {
80+
func (jl *JSONLogger) SetEndpoint(scheme string, host string) {
8081
jl.scheme = scheme
8182
jl.host = host
8283
jl.online = true
8384
}
8485

85-
func (jl *JsonLogger) Connect() error {
86+
func (jl *JSONLogger) Connect() error {
8687
conn, err := net.Dial(jl.scheme, jl.host)
8788
if err == nil {
8889
jl.conn = conn
@@ -91,50 +92,50 @@ func (jl *JsonLogger) Connect() error {
9192
}
9293

9394
// Log at the Critical severity level.
94-
func (jl *JsonLogger) Critical(messageStr string, payloadObj interface{}) {
95+
func (jl *JSONLogger) Critical(messageStr string, payloadObj interface{}) {
9596
jl.Write(CRITICAL, messageStr, payloadObj)
9697
}
9798

9899
// Log at the Alert severity level.
99-
func (jl *JsonLogger) Alert(messageStr string, payloadObj interface{}) {
100+
func (jl *JSONLogger) Alert(messageStr string, payloadObj interface{}) {
100101
jl.Write(ALERT, messageStr, payloadObj)
101102
}
102103

103104
// Log at the Emergency severity level.
104-
func (jl *JsonLogger) Emergency(messageStr string, payloadObj interface{}) {
105+
func (jl *JSONLogger) Emergency(messageStr string, payloadObj interface{}) {
105106
jl.Write(EMERGENCY, messageStr, payloadObj)
106107
}
107108

108109
// Log at the Error severity level.
109-
func (jl *JsonLogger) Error(messageStr string, payloadObj interface{}) {
110+
func (jl *JSONLogger) Error(messageStr string, payloadObj interface{}) {
110111
jl.Write(ERROR, messageStr, payloadObj)
111112
}
112113

113114
// Log at the Warning severity level.
114-
func (jl *JsonLogger) Warning(messageStr string, payloadObj interface{}) {
115+
func (jl *JSONLogger) Warning(messageStr string, payloadObj interface{}) {
115116
jl.Write(WARNING, messageStr, payloadObj)
116117
}
117118

118119
// Log at the Notice severity level.
119-
func (jl *JsonLogger) Notice(messageStr string, payloadObj interface{}) {
120+
func (jl *JSONLogger) Notice(messageStr string, payloadObj interface{}) {
120121
jl.Write(NOTICE, messageStr, payloadObj)
121122
}
122123

123124
// Log at the Info severity level.
124-
func (jl *JsonLogger) Info(messageStr string, payloadObj interface{}) {
125+
func (jl *JSONLogger) Info(messageStr string, payloadObj interface{}) {
125126
jl.Write(INFO, messageStr, payloadObj)
126127
}
127128

128129
// Log at the Debug severity level.
129-
func (jl *JsonLogger) Debug(messageStr string, payloadObj interface{}) {
130+
func (jl *JSONLogger) Debug(messageStr string, payloadObj interface{}) {
130131
jl.Write(DEBUG, messageStr, payloadObj)
131132
}
132133

133134
// Combines a message, payload, and severity to a LogMessage struct and
134135
// serializes it to the wire. If the send via WriteAndRetry() fails, this method
135136
// calls log.Fatalf() which will abort the program, leaving the system to restart
136137
// the process.
137-
func (jl *JsonLogger) Write(severity int, messageStr string, payloadObj interface{}) {
138+
func (jl *JSONLogger) Write(severity int, messageStr string, payloadObj interface{}) {
138139
if severity > jl.level {
139140
return
140141
}
@@ -164,15 +165,14 @@ func (jl *JsonLogger) Write(severity int, messageStr string, payloadObj interfac
164165
_, err = jl.WriteAndRetry(buf.Bytes())
165166
if err != nil {
166167
log.Fatalf("Failed to send log message, even with retry, exiting: %s\n", buf.String())
167-
return
168168
}
169169
}
170170
}
171171

172172
// Send the provided data on the connection; if there is an error,
173173
// it will retry to connect and transmit again, once. If that fails,
174174
// it returns an error.
175-
func (jl *JsonLogger) WriteAndRetry(data []byte) (int, error) {
175+
func (jl *JSONLogger) WriteAndRetry(data []byte) (int, error) {
176176
jl.mu.Lock()
177177
defer jl.mu.Unlock()
178178

0 commit comments

Comments
 (0)