From f1e64008fb080b575b76a675084d944f91f9e706 Mon Sep 17 00:00:00 2001 From: Joe Chen Date: Mon, 23 Dec 2024 12:10:43 -0500 Subject: [PATCH] cmd: always build with "cert" subcommand (#7883) --- CHANGELOG.md | 1 + internal/cmd/cert.go | 23 ++++++++++++++++------- internal/cmd/cert_stub.go | 29 ----------------------------- 3 files changed, 17 insertions(+), 36 deletions(-) delete mode 100644 internal/cmd/cert_stub.go diff --git a/CHANGELOG.md b/CHANGELOG.md index cb5c1c69e..7ad2b908f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ All notable changes to Gogs are documented in this file. ### Changed - The required Go version to compile source code changed to 1.23.4. +- The build tag `cert` has been removed, and the `gogs cert` subcommand is now always available. [#7883](https://github.com/gogs/gogs/pull/7883) ### Fixed diff --git a/internal/cmd/cert.go b/internal/cmd/cert.go index ef3f2a2a2..dbf1ccf1d 100644 --- a/internal/cmd/cert.go +++ b/internal/cmd/cert.go @@ -1,5 +1,3 @@ -//go:build cert - // Copyright 2009 The Go Authors. All rights reserved. // Copyright 2014 The Gogs Authors. All rights reserved. // Use of this source code is governed by a MIT-style @@ -147,17 +145,28 @@ func runCert(ctx *cli.Context) error { if err != nil { log.Fatalf("Failed to open cert.pem for writing: %s", err) } - pem.Encode(certOut, &pem.Block{Type: "CERTIFICATE", Bytes: derBytes}) - certOut.Close() + err = pem.Encode(certOut, &pem.Block{Type: "CERTIFICATE", Bytes: derBytes}) + if err != nil { + log.Fatalf("Failed to encode data to cert.pem: %s", err) + } + err = certOut.Close() + if err != nil { + log.Fatalf("Failed to close writing to cert.pem: %s", err) + } log.Println("Written cert.pem") keyOut, err := os.OpenFile("key.pem", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600) if err != nil { log.Fatalf("Failed to open key.pem for writing: %v\n", err) } - pem.Encode(keyOut, pemBlockForKey(priv)) - keyOut.Close() + err = pem.Encode(keyOut, pemBlockForKey(priv)) + if err != nil { + log.Fatalf("Failed to encode data to key.pem: %s", err) + } + err = keyOut.Close() + if err != nil { + log.Fatalf("Failed to close writing to key.pem: %s", err) + } log.Println("Written key.pem") - return nil } diff --git a/internal/cmd/cert_stub.go b/internal/cmd/cert_stub.go deleted file mode 100644 index f8cbaa7ed..000000000 --- a/internal/cmd/cert_stub.go +++ /dev/null @@ -1,29 +0,0 @@ -//go:build !cert - -// Copyright 2009 The Go Authors. All rights reserved. -// Copyright 2014 The Gogs Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package cmd - -import ( - "fmt" - "os" - - "github.com/urfave/cli" -) - -var Cert = cli.Command{ - Name: "cert", - Usage: "Generate self-signed certificate", - Description: `Please use build tags "cert" to rebuild Gogs in order to have this ability`, - Action: runCert, -} - -func runCert(_ *cli.Context) error { - fmt.Println("Command cert not available, please use build tags 'cert' to rebuild.") - os.Exit(1) - - return nil -}