From 3ec866d1ea706c66d8fe0716a81002e65dc8b4ec Mon Sep 17 00:00:00 2001 From: Arjan H Date: Sun, 23 Mar 2025 10:21:49 +0100 Subject: [PATCH] Add golangci-lint for GUI --- .github/workflows/golangci-lint.yml | 36 +++++++++ dev/versions | 20 +---- gui/certificate.go | 10 +-- gui/chains.go | 10 +-- gui/dashboard.go | 2 +- gui/hsm.go | 10 +-- gui/main.go | 112 ++++++++++++++-------------- gui/upgrades.go | 16 ++-- 8 files changed, 117 insertions(+), 99 deletions(-) create mode 100644 .github/workflows/golangci-lint.yml diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml new file mode 100644 index 0000000..3378e47 --- /dev/null +++ b/.github/workflows/golangci-lint.yml @@ -0,0 +1,36 @@ +name: golangci-lint + +on: + push: + branches: + - main + - master + pull_request: + +permissions: + contents: read + # Optional: allow read access to pull request. Use with `only-new-issues` option. + # pull-requests: read + +jobs: + golangci: + name: lint + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + GO_VERSION: + - 1.24.1 + + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-go@v5 + with: + go-version: ${{ matrix.GO_VERSION }} + + - name: golangci-lint + uses: golangci/golangci-lint-action@v6 + with: + version: v1.64 + working-directory: ./gui diff --git a/dev/versions b/dev/versions index 784df28..1121c30 100755 --- a/dev/versions +++ b/dev/versions @@ -41,18 +41,6 @@ colorCITag() { echo "* $fileName:$res" } -colorNGTag() { - local fileName="$1" - local expectVersion="$2" - - if [ ! -z "$(grep -R nginx: $fileName | egrep "[\"0-9]+" | grep $expectVersion || echo "")" ]; then - res=$(grep -R nginx: $fileName | egrep "[\"0-9]+" | sed -e "s/$expectVersion/${COL_LIGHT_GREEN}$expectVersion${COL_NC}/") - else - res=$(grep -R nginx: $fileName | egrep "[\"0-9]+" | sed -e "s/\(.*:\)\([0-9\.]*\)/\1${COL_LIGHT_RED}\2${COL_NC}/") - fi - echo "* $fileName:$res" -} - colorGoVersion() { local fileName="$1" local expectVersion="$2" @@ -111,18 +99,12 @@ grep go1. ../boulder/.github/workflows/boulder-ci.yml colorCITag build/Dockerfile-boulder echo -ngversion=$(grep -R nginx: .github/Dockerfile | egrep "[\"0-9]+" | sed -e "s/.*:\([0-9\.]*\)/\1/") -echo -n "Manual .github/Dockerfile: " -grep -R nginx: .github/Dockerfile | egrep "[\"0-9]+" -colorNGTag build/docker-compose.yml $ngversion -colorNGTag patches/docker-compose.patch $ngversion -echo - goversion=$(grep GO_VERSION -A 3 ../boulder/.github/workflows/release.yml | egrep "\- [\"0-9]+" | sed -e "s/\s*-\s*//" | sed -e "s/\"//g") echo "Boulder .github/workflows/release.yml" grep GO_VERSION -A 3 ../boulder/.github/workflows/release.yml | egrep "\- [\"0-9]+" | sed -e "s/yml-/yml/" colorGoVersion .github/workflows/release.yml "$goversion" colorGoVersion .github/workflows/build-standalone.yml "$goversion" +colorGoVersion .github/workflows/golangci-lint.yml "$goversion" echo goversion=$(grep GO_VERSION ../boulder/docker-compose.yml | sed -e "s/\s*GO_VERSION://") diff --git a/gui/certificate.go b/gui/certificate.go index 4a7a676..60cf101 100644 --- a/gui/certificate.go +++ b/gui/certificate.go @@ -403,7 +403,7 @@ func (ci *CertificateInfo) CeremonyRootCRL(seqnr string) error { if viper.Get("crl_root_days") == nil || viper.Get("crl_root_days") == "" { viper.Set("crl_root_days", 365) - viper.WriteConfig() + _ = viper.WriteConfig() } crlint, err := time.ParseDuration(fmt.Sprintf("%dh", viper.GetInt("crl_root_days")*24-1)) if err != nil { @@ -479,7 +479,7 @@ func (ci *CertificateInfo) Generate(certBase string) error { _, err = ci.CeremonyRoot("01", false) viper.Set("crl_root_days", ci.NumDays) - viper.WriteConfig() + _ = viper.WriteConfig() } else { _, err = ci.CeremonyIssuer("01", "01", false) } @@ -578,7 +578,7 @@ func (ci *CertificateInfo) Import(tmpDir string, tmpKey string, tmpCert string) } defer f.Close() - io.Copy(f, ci.ImportFile) + _, _ = io.Copy(f, ci.ImportFile) contentType := ci.ImportHandler.Header.Get("Content-Type") if contentType == "application/x-pkcs12" { @@ -1000,7 +1000,7 @@ func (ci *CertificateInfo) Extract(certBase string, tmpDir string, wasCSR bool) numDays := time.Until(crt.NotAfter).Hours() / 24 // TODO: adjust for max root ceremony value... viper.Set("crl_root_days", int(math.Ceil(numDays))) - viper.WriteConfig() + _ = viper.WriteConfig() } else { // Create CRLs stating that the intermediates are not revoked. @@ -1260,7 +1260,7 @@ func renewCertificate(certname string, days int, rootname string, _ string, _ st _, err = ci.CeremonyRoot(seqnr, true) viper.Set("crl_root_days", ci.NumDays) - viper.WriteConfig() + _ = viper.WriteConfig() } else { _, err = ci.CeremonyIssuer(seqnr, rootseqnr, true) } diff --git a/gui/chains.go b/gui/chains.go index 2823a90..88b3f51 100644 --- a/gui/chains.go +++ b/gui/chains.go @@ -143,7 +143,7 @@ func getRawCAChains() []IssuerConfig { byteValue, _ := io.ReadAll(caConf) var result CAConfig - json.Unmarshal([]byte(byteValue), &result) + _ = json.Unmarshal([]byte(byteValue), &result) return result.CA.Issuance.Issuers } @@ -204,7 +204,7 @@ func getRawWFEChains() [][]string { byteValue, _ := io.ReadAll(wfeConf) var result WFEConfig - json.Unmarshal([]byte(byteValue), &result) + _ = json.Unmarshal([]byte(byteValue), &result) return result.WFE.Chains } @@ -319,17 +319,17 @@ func setUseForLeaves(active string) error { } if err := setUseForLeavesFile(caConfFile, active); err != nil { - exec.Command("mv", caConfFile+"_BAK", caConfFile).Run() + _ = exec.Command("mv", caConfFile+"_BAK", caConfFile).Run() return err } - exec.Command("rm", caConfFile+"_BAK").Run() + _ = exec.Command("rm", caConfFile+"_BAK").Run() if active != "" { viper.Set("certs.activeIssuer", active) } if active != "" { - viper.WriteConfig() + _ = viper.WriteConfig() } return nil diff --git a/gui/dashboard.go b/gui/dashboard.go index 2458eb3..d7fc977 100644 --- a/gui/dashboard.go +++ b/gui/dashboard.go @@ -13,7 +13,7 @@ import ( "strings" "time" - "github.com/dustin/go-humanize" + humanize "github.com/dustin/go-humanize" "github.com/pkg/errors" "github.com/spf13/viper" ) diff --git a/gui/hsm.go b/gui/hsm.go index 1d9aa2e..6343f03 100644 --- a/gui/hsm.go +++ b/gui/hsm.go @@ -155,7 +155,7 @@ func (cfg *HSMConfig) createSlot(slotId uint, label string) (string, error) { if err != nil { return "", fmt.Errorf("failed to open session: %s", err) } - defer ctx.CloseSession(session) + defer func() { _ = ctx.CloseSession(session) }() err = ctx.Login(session, pkcs11.CKU_SO, cfg.SOPIN) if err != nil { @@ -165,7 +165,7 @@ func (cfg *HSMConfig) createSlot(slotId uint, label string) (string, error) { return "", fmt.Errorf("failed to login: %s", err) } } - defer ctx.Logout(session) + defer func() { _ = ctx.Logout(session) }() err = ctx.InitPIN(session, cfg.UserPIN) if err != nil { @@ -173,7 +173,7 @@ func (cfg *HSMConfig) createSlot(slotId uint, label string) (string, error) { } // Forced reconnect to get the renumbered slots from SoftHSM2 - ctx.Finalize() + _ = ctx.Finalize() ctx.Destroy() ctx = pkcs11.New(cfg.Module) if ctx == nil { @@ -641,8 +641,8 @@ func (cfg *HSMConfig) ImportKeyCert(keyFile, certFile string) (crypto.PublicKey, } func (hs *HSMSession) Close() { - hs.Context.CloseSession(hs.Handle) - hs.Context.Logout(hs.Handle) + _ = hs.Context.CloseSession(hs.Handle) + _ = hs.Context.Logout(hs.Handle) } func (hs *HSMSession) CreateObject(tmpl []*pkcs11.Attribute) (pkcs11.ObjectHandle, error) { diff --git a/gui/main.go b/gui/main.go index c3cf157..5e31d22 100644 --- a/gui/main.go +++ b/gui/main.go @@ -37,14 +37,14 @@ import ( "time" "github.com/biz/templates" - "github.com/dustin/go-humanize" + humanize "github.com/dustin/go-humanize" _ "github.com/go-sql-driver/mysql" "github.com/google/go-github/github" "github.com/gorilla/mux" "github.com/gorilla/securecookie" "github.com/gorilla/sessions" "github.com/gorilla/websocket" - "github.com/nbutton23/zxcvbn-go" + zxcvbn "github.com/nbutton23/zxcvbn-go" "github.com/spf13/viper" "golang.org/x/crypto/bcrypt" "golang.org/x/text/cases" @@ -318,7 +318,7 @@ func errorHandler(w http.ResponseWriter, r *http.Request, err error, status int) var FileErrors []interface{} data := getLog(w, r, "cert") if data != "" { - FileErrors = append(FileErrors, map[string]interface{}{"FileName": "/home/labca/nginx_data/ssl/acme_tiny.log", "Content": data}) + FileErrors = append(FileErrors, map[string]interface{}{"FileName": "/home/labca/nginx_data/ssl/certbot.log", "Content": data}) } data = getLog(w, r, "commander") if data != "" { @@ -580,7 +580,7 @@ func _backupHandler(w http.ResponseWriter, r *http.Request) { } w.Header().Set("Content-Type", "application/json") - json.NewEncoder(w).Encode(res) + _ = json.NewEncoder(w).Encode(res) } type ErrorsResponse struct { @@ -624,7 +624,7 @@ func _accountUpdateHandler(w http.ResponseWriter, r *http.Request) { } } - viper.WriteConfig() + _ = viper.WriteConfig() } else { res.Success = false @@ -632,7 +632,7 @@ func _accountUpdateHandler(w http.ResponseWriter, r *http.Request) { } w.Header().Set("Content-Type", "application/json") - json.NewEncoder(w).Encode(res) + _ = json.NewEncoder(w).Encode(res) } func backendUpdateHandler(w http.ResponseWriter, r *http.Request) { @@ -659,7 +659,7 @@ func backendUpdateHandler(w http.ResponseWriter, r *http.Request) { } w.Header().Set("Content-Type", "application/json") - json.NewEncoder(w).Encode(res) + _ = json.NewEncoder(w).Encode(res) } func _configUpdateHandler(w http.ResponseWriter, r *http.Request) { @@ -738,7 +738,7 @@ func _configUpdateHandler(w http.ResponseWriter, r *http.Request) { } if delta { - viper.WriteConfig() + _ = viper.WriteConfig() webTitle = viper.GetString("labca.web_title") if webTitle == "" { @@ -769,7 +769,7 @@ func _configUpdateHandler(w http.ResponseWriter, r *http.Request) { } w.Header().Set("Content-Type", "application/json") - json.NewEncoder(w).Encode(res) + _ = json.NewEncoder(w).Encode(res) } func _crlIntervalUpdateHandler(w http.ResponseWriter, r *http.Request) { @@ -791,7 +791,7 @@ func _crlIntervalUpdateHandler(w http.ResponseWriter, r *http.Request) { } if delta { - viper.WriteConfig() + _ = viper.WriteConfig() err := _applyConfig() if err != nil { @@ -808,7 +808,7 @@ func _crlIntervalUpdateHandler(w http.ResponseWriter, r *http.Request) { } w.Header().Set("Content-Type", "application/json") - json.NewEncoder(w).Encode(res) + _ = json.NewEncoder(w).Encode(res) } // EmailConfig stores configuration used for sending out emails @@ -938,7 +938,7 @@ func _emailUpdateHandler(w http.ResponseWriter, r *http.Request) { } if delta { - viper.WriteConfig() + _ = viper.WriteConfig() err := _applyConfig() if err != nil { @@ -958,7 +958,7 @@ func _emailUpdateHandler(w http.ResponseWriter, r *http.Request) { } w.Header().Set("Content-Type", "application/json") - json.NewEncoder(w).Encode(res) + _ = json.NewEncoder(w).Encode(res) } func _emailSendHandler(w http.ResponseWriter, r *http.Request) { @@ -968,7 +968,7 @@ func _emailSendHandler(w http.ResponseWriter, r *http.Request) { if _hostCommand(w, r, "test-email", recipient) { // Only on success, as when this returns false for this case the response has already been sent! w.Header().Set("Content-Type", "application/json") - json.NewEncoder(w).Encode(res) + _ = json.NewEncoder(w).Encode(res) } } @@ -1153,7 +1153,7 @@ func _checkUpdatesHandler(w http.ResponseWriter, _ *http.Request) { res.UpdateCheckedRel = humanize.RelTime(updateChecked, time.Now(), "", "") w.Header().Set("Content-Type", "application/json") - json.NewEncoder(w).Encode(res) + _ = json.NewEncoder(w).Encode(res) } func generateCRLHandler(w http.ResponseWriter, r *http.Request, isRoot bool) { @@ -1170,7 +1170,7 @@ func generateCRLHandler(w http.ResponseWriter, r *http.Request, isRoot bool) { } w.Header().Set("Content-Type", "application/json") - json.NewEncoder(w).Encode(res) + _ = json.NewEncoder(w).Encode(res) } func uploadCRLHandler(w http.ResponseWriter, r *http.Request) { @@ -1188,7 +1188,7 @@ func uploadCRLHandler(w http.ResponseWriter, r *http.Request) { _hostCommand(w, r, "check-crl") w.Header().Set("Content-Type", "application/json") - json.NewEncoder(w).Encode(res) + _ = json.NewEncoder(w).Encode(res) } func updateLeaveIssuersHandler(w http.ResponseWriter, r *http.Request) { @@ -1209,7 +1209,7 @@ func updateLeaveIssuersHandler(w http.ResponseWriter, r *http.Request) { } w.Header().Set("Content-Type", "application/json") - json.NewEncoder(w).Encode(res) + _ = json.NewEncoder(w).Encode(res) } func renewCertHandler(w http.ResponseWriter, r *http.Request) { @@ -1245,7 +1245,7 @@ func renewCertHandler(w http.ResponseWriter, r *http.Request) { } w.Header().Set("Content-Type", "application/json") - json.NewEncoder(w).Encode(res) + _ = json.NewEncoder(w).Encode(res) } func _managePostDispatch(w http.ResponseWriter, r *http.Request, action string) bool { @@ -1403,7 +1403,7 @@ func _managePost(w http.ResponseWriter, r *http.Request) { } w.Header().Set("Content-Type", "application/json") - json.NewEncoder(w).Encode(res) + _ = json.NewEncoder(w).Encode(res) } func _manageGet(w http.ResponseWriter, r *http.Request) { @@ -1804,7 +1804,7 @@ func showLog(ws *websocket.Conn, logType string) { for scanner.Scan() { msg := scanner.Text() if logType != "audit" || strings.Contains(msg, "[AUDIT]") { - ws.SetWriteDeadline(time.Now().Add(writeWait)) + _ = ws.SetWriteDeadline(time.Now().Add(writeWait)) if err := ws.WriteMessage(websocket.TextMessage, []byte(msg)); err != nil { // Probably "websocket: close sent" return @@ -1820,8 +1820,8 @@ func showLog(ws *websocket.Conn, logType string) { func reader(ws *websocket.Conn) { defer ws.Close() ws.SetReadLimit(512) - ws.SetReadDeadline(time.Now().Add(pongWait)) - ws.SetPongHandler(func(string) error { ws.SetReadDeadline(time.Now().Add(pongWait)); return nil }) + _ = ws.SetReadDeadline(time.Now().Add(pongWait)) + ws.SetPongHandler(func(string) error { _ = ws.SetReadDeadline(time.Now().Add(pongWait)); return nil }) for { _, _, err := ws.ReadMessage() if err != nil { @@ -1840,7 +1840,7 @@ func writer(ws *websocket.Conn, logType string) { go showLog(ws, logType) for range pingTicker.C { - ws.SetWriteDeadline(time.Now().Add(writeWait)) + _ = ws.SetWriteDeadline(time.Now().Add(writeWait)) if err := ws.WriteMessage(websocket.PingMessage, []byte{}); err != nil { // Probably "websocket: close sent" return @@ -1955,9 +1955,9 @@ func _certCreate(w http.ResponseWriter, r *http.Request, certBase string, isRoot cfg := &HSMConfig{} cfg.Initialize("issuer", seqnr) - cfg.ClearAll() + _ = cfg.ClearAll() cfg.Initialize("root", rootseqnr) - cfg.ClearAll() + _ = cfg.ClearAll() certBase = "root-01" isRoot = true @@ -1971,13 +1971,13 @@ func _certCreate(w http.ResponseWriter, r *http.Request, certBase string, isRoot } else if r.Form.Get("ack-rootkey") == "yes" { // Root Key was shown, do we need to keep it online? viper.Set("keep_root_offline", r.Form.Get("keep-root-online") != "true") - viper.WriteConfig() + _ = viper.WriteConfig() // Undo what setupHandler did when showing the public key... _, errPem := os.Stat("data/root-ca.pem") _, errTmp := os.Stat("data/root-ca.pem_TMP") if errors.Is(errPem, fs.ErrNotExist) && !errors.Is(errTmp, fs.ErrNotExist) { - exeCmd("mv data/root-ca.pem_TMP data/root-ca.pem") + _, _ = exeCmd("mv data/root-ca.pem_TMP data/root-ca.pem") } r.Method = "GET" @@ -2215,7 +2215,7 @@ func _certCreate(w http.ResponseWriter, r *http.Request, certBase string, isRoot nameID, err := issuerNameID(CERT_FILES_PATH + "issuer-01-cert.pem") if err == nil { viper.Set("issuer_name_id", nameID) - viper.WriteConfig() + _ = viper.WriteConfig() } else { log.Printf("_certCreate: could not calculate IssuerNameID: %v", err) } @@ -2223,7 +2223,7 @@ func _certCreate(w http.ResponseWriter, r *http.Request, certBase string, isRoot if viper.Get("labca.organization") == nil { viper.Set("labca.organization", ci.Organization) - viper.WriteConfig() + _ = viper.WriteConfig() } session.Values["ct"] = ci.CreateType @@ -2313,7 +2313,7 @@ func _hostCommand(w http.ResponseWriter, r *http.Request, command string, params res.Errors["EmailSend"] = "Failed to send email - see logs" } w.Header().Set("Content-Type", "application/json") - json.NewEncoder(w).Encode(res) + _ = json.NewEncoder(w).Encode(res) return false } errorHandler(w, r, errors.New(string(message)), http.StatusInternalServerError) @@ -2322,7 +2322,7 @@ func _hostCommand(w http.ResponseWriter, r *http.Request, command string, params func randToken() string { b := make([]byte, 8) - rand.Read(b) + _, _ = rand.Read(b) return fmt.Sprintf("%x", b) } @@ -2509,7 +2509,7 @@ func _setupAdminUser(w http.ResponseWriter, r *http.Request) bool { } viper.Set("config.complete", false) - viper.WriteConfig() + _ = viper.WriteConfig() err = _applyConfig() if err != nil { @@ -2566,7 +2566,7 @@ func _setupAdminUser(w http.ResponseWriter, r *http.Request) bool { viper.Set("user.name", reg.Name) viper.Set("user.email", reg.Email) viper.Set("user.password", string(hash)) - viper.WriteConfig() + _ = viper.WriteConfig() session, _ := sessionStore.Get(r, "labca") session.Values["user"] = reg.Name @@ -2640,7 +2640,7 @@ func _setupBaseConfig(w http.ResponseWriter, r *http.Request) bool { if cfg.DomainMode == "whitelist" { viper.Set("labca.whitelist", cfg.WhitelistDomains) } - viper.WriteConfig() + _ = viper.WriteConfig() // Fake the method to GET as we need to continue in the setupHandler() function r.Method = "GET" @@ -2676,7 +2676,7 @@ func writeStandaloneConfig(cfg *StandaloneConfig) { viper.Set("server.key", cfg.KeyPath) } viper.Set("config.complete", true) - viper.WriteConfig() + _ = viper.WriteConfig() if restart { if cfg.UseHTTPS { @@ -2770,7 +2770,7 @@ func setupHandler(w http.ResponseWriter, r *http.Request) { if !_certCreate(w, r, "root-01", true) { // Cleanup the cert (if it even exists) so we will retry on the next run if _, err := os.Stat(CERT_FILES_PATH + "root-01-cert.pem"); !errors.Is(err, fs.ErrNotExist) { - exeCmd("mv " + CERT_FILES_PATH + "root-01-cert.pem " + CERT_FILES_PATH + "root-01-cert.pem_TMP") + _, _ = exeCmd("mv " + CERT_FILES_PATH + "root-01-cert.pem " + CERT_FILES_PATH + "root-01-cert.pem_TMP") } return } @@ -2827,11 +2827,11 @@ func restartHandler(w http.ResponseWriter, r *http.Request) { } viper.Set("config.restarted", true) - viper.WriteConfig() + _ = viper.WriteConfig() if !_hostCommand(w, r, "docker-restart") { viper.Set("config.restarted", false) - viper.WriteConfig() + _ = viper.WriteConfig() return } } @@ -2849,9 +2849,9 @@ func finalHandler(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") if viper.GetBool("config.error") { viper.Set("config.cert_requested", nil) - viper.WriteConfig() + _ = viper.WriteConfig() } - json.NewEncoder(w).Encode(map[string]interface{}{"complete": viper.GetBool("config.complete"), "error": viper.GetBool("config.error")}) + _ = json.NewEncoder(w).Encode(map[string]interface{}{"complete": viper.GetBool("config.complete"), "error": viper.GetBool("config.error")}) } else { render(w, r, "polling:manage", map[string]interface{}{"Progress": _progress("polling"), "HelpText": _helptext("polling")}) } @@ -2862,11 +2862,11 @@ func finalHandler(w http.ResponseWriter, r *http.Request) { if viper.GetBool("config.error") { viper.Set("config.error", false) } - viper.WriteConfig() + _ = viper.WriteConfig() // 9. Setup our own web certificate if !_hostCommand(w, r, "acme-request") { viper.Set("config.error", true) - viper.WriteConfig() + _ = viper.WriteConfig() http.Redirect(w, r, r.Header.Get("X-Request-Base")+"/logs/cert", http.StatusSeeOther) return } @@ -2882,11 +2882,11 @@ func finalHandler(w http.ResponseWriter, r *http.Request) { } viper.Set("config.complete", true) - viper.WriteConfig() + _ = viper.WriteConfig() if r.Header.Get("X-Requested-With") == "XMLHttpRequest" { w.Header().Set("Content-Type", "application/json") - json.NewEncoder(w).Encode(map[string]interface{}{"complete": viper.GetBool("config.complete")}) + _ = json.NewEncoder(w).Encode(map[string]interface{}{"complete": viper.GetBool("config.complete")}) } else { render(w, r, "final:manage", map[string]interface{}{"RequestBase": r.Header.Get("X-Request-Base"), "Progress": _progress("final"), "HelpText": _helptext("final")}) } @@ -3095,7 +3095,7 @@ func statsHandler(w http.ResponseWriter, r *http.Request) { res := parseDockerStats(getLog(w, r, "stats")) w.Header().Set("Content-Type", "application/json") - json.NewEncoder(w).Encode(res) + _ = json.NewEncoder(w).Encode(res) } type navItem struct { @@ -3316,7 +3316,7 @@ func render(w http.ResponseWriter, r *http.Request, view string, data map[string return } - w.Write(b) + _, _ = w.Write(b) } func notFoundHandler(w http.ResponseWriter, r *http.Request) { @@ -3377,7 +3377,7 @@ func init() { } else { _, err := os.Stat(*configFile) if errors.Is(err, fs.ErrNotExist) { - viper.WriteConfigAs(*configFile) + _ = viper.WriteConfigAs(*configFile) } viper.AddConfigPath(filepath.Dir(*configFile)) @@ -3471,7 +3471,7 @@ func init() { panic(fmt.Errorf("fatal error random key")) } viper.Set("keys.auth", base64.StdEncoding.EncodeToString(key)) - viper.WriteConfig() + _ = viper.WriteConfig() } if viper.Get("keys.enc") == nil { key := securecookie.GenerateRandomKey(32) @@ -3479,7 +3479,7 @@ func init() { panic(fmt.Errorf("fatal error random key")) } viper.Set("keys.enc", base64.StdEncoding.EncodeToString(key)) - viper.WriteConfig() + _ = viper.WriteConfig() } if *init { @@ -3490,28 +3490,28 @@ func init() { viper.Set("server.port", *port) } viper.Set("standalone", true) - viper.WriteConfig() + _ = viper.WriteConfig() } if viper.Get("server.addr") == nil { viper.Set("server.addr", "0.0.0.0") - viper.WriteConfig() + _ = viper.WriteConfig() } if viper.Get("server.port") == nil { viper.Set("server.port", 3000) - viper.WriteConfig() + _ = viper.WriteConfig() } if viper.Get("server.session.maxage") == nil { viper.Set("server.session.maxage", 3600) // 1 hour - viper.WriteConfig() + _ = viper.WriteConfig() } if viper.Get("db.conn") == nil { viper.Set("db.type", "mysql") viper.Set("db.conn", "root@tcp(boulder-mysql:3306)/boulder_sa_integration") - viper.WriteConfig() + _ = viper.WriteConfig() } dbConn = viper.GetString("db.conn") dbType = viper.GetString("db.type") @@ -3580,7 +3580,7 @@ func (br BackupResult) Remove() { func (br BackupResult) Restore() { if br.Existed { - os.Rename(br.NewName, br.OrigName) + _ = os.Rename(br.NewName, br.OrigName) } } diff --git a/gui/upgrades.go b/gui/upgrades.go index 6cb9cdd..549356e 100644 --- a/gui/upgrades.go +++ b/gui/upgrades.go @@ -21,11 +21,11 @@ func CheckUpgrades() { gitVersion := controlCommand("git-version", true) if gitVersion != "" { viper.Set("version", strings.TrimSpace(gitVersion)) - viper.WriteConfig() + _ = viper.WriteConfig() } } else if v != standaloneVersion { viper.Set("version", standaloneVersion) - viper.WriteConfig() + _ = viper.WriteConfig() } changed := CheckUpgrade_01_CeremonyHSM() @@ -155,7 +155,7 @@ func CheckUpgrade_01_CeremonyHSM() bool { prevRootCRL := baseDir + "root-ca.crl" if _, err := os.Stat(prevRootCRL); !errors.Is(err, fs.ErrNotExist) { ci.CRL = readFileAsString(prevRootCRL) - copyFile(prevRootCRL, strings.Replace(rootCertFile, "-cert.", "-crl.", -1)) + _ = copyFile(prevRootCRL, strings.Replace(rootCertFile, "-cert.", "-crl.", -1)) } if err := ci.Create("root-01", false); err != nil { @@ -183,11 +183,11 @@ func CheckUpgrade_01_CeremonyHSM() bool { os.Exit(1) } - os.Rename(prevRootCert, prevRootCert+"_backup") - os.Rename(prevRootKey, prevRootKey+"_backup") - os.Rename(prevRootCRL, prevRootCRL+"_backup") - os.Rename(prevIssuerCert, prevIssuerCert+"_backup") - os.Rename(prevIssuerKey, prevIssuerKey+"_backup") + _ = os.Rename(prevRootCert, prevRootCert+"_backup") + _ = os.Rename(prevRootKey, prevRootKey+"_backup") + _ = os.Rename(prevRootCRL, prevRootCRL+"_backup") + _ = os.Rename(prevIssuerCert, prevIssuerCert+"_backup") + _ = os.Rename(prevIssuerKey, prevIssuerKey+"_backup") log.Println("**** END MIGRATION ****") return true