cmd: always build with "cert" subcommand

pull/7883/head
Joe Chen 2024-12-23 12:01:49 -05:00
parent cfde357824
commit 4b8ce53e88
2 changed files with 16 additions and 36 deletions

View File

@ -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
}

View File

@ -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
}