mirror of
https://github.com/drakkan/sftpgo.git
synced 2025-12-07 14:50:55 +03:00
add support for ACME compliant certificate authorities
Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
55
cmd/acme.go
Normal file
55
cmd/acme.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/drakkan/sftpgo/v2/acme"
|
||||
"github.com/drakkan/sftpgo/v2/config"
|
||||
"github.com/drakkan/sftpgo/v2/logger"
|
||||
"github.com/drakkan/sftpgo/v2/util"
|
||||
)
|
||||
|
||||
var (
|
||||
acmeCmd = &cobra.Command{
|
||||
Use: "acme",
|
||||
Short: "Obtain TLS certificates from ACME-based CAs like Let's Encrypt",
|
||||
}
|
||||
acmeRunCmd = &cobra.Command{
|
||||
Use: "run",
|
||||
Short: "Register your account and obtain certificates",
|
||||
Long: `This command must be run to obtain TLS certificates the first time or every
|
||||
time you add a new domain to your configuration file.
|
||||
Certificates are saved in the configured "certs_path".
|
||||
After this initial step, the certificates are automatically checked and
|
||||
renewed by the SFTPGo service
|
||||
`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
logger.DisableLogger()
|
||||
logger.EnableConsoleLogger(zerolog.DebugLevel)
|
||||
configDir = util.CleanDirInput(configDir)
|
||||
err := config.LoadConfig(configDir, configFile)
|
||||
if err != nil {
|
||||
logger.ErrorToConsole("Unable to initialize data provider, config load error: %v", err)
|
||||
return
|
||||
}
|
||||
acmeConfig := config.GetACMEConfig()
|
||||
err = acmeConfig.Initialize(configDir, false)
|
||||
if err != nil {
|
||||
logger.ErrorToConsole("Unable to initialize ACME configuration: %v", err)
|
||||
}
|
||||
if err = acme.GetCertificates(); err != nil {
|
||||
logger.ErrorToConsole("Cannot get certificates: %v", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
addConfigFlags(acmeRunCmd)
|
||||
acmeCmd.AddCommand(acmeRunCmd)
|
||||
rootCmd.AddCommand(acmeCmd)
|
||||
}
|
||||
Reference in New Issue
Block a user