All checks were successful
Build (artifact) / build (push) Has been skipped
73 lines
1.6 KiB
Go
73 lines
1.6 KiB
Go
package shared
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"git.nevets.tech/Steven/certman/common"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
func createFile(fileName string, filePermission os.FileMode, data []byte) {
|
|
fileInfo, err := os.Stat(fileName)
|
|
if err != nil {
|
|
if os.IsNotExist(err) {
|
|
file, err := os.Create(fileName)
|
|
if err != nil {
|
|
fmt.Println("Error creating configuration file: ", err)
|
|
os.Exit(1)
|
|
}
|
|
defer file.Close()
|
|
|
|
_, err = file.Write(data)
|
|
if err != nil {
|
|
fmt.Println("Error writing to file: ", err)
|
|
os.Exit(1)
|
|
}
|
|
err = file.Chmod(filePermission)
|
|
if err != nil {
|
|
fmt.Println("Error changing file permission: ", err)
|
|
}
|
|
} else {
|
|
fmt.Println("Error opening configuration file: ", err)
|
|
os.Exit(1)
|
|
}
|
|
} else {
|
|
if fileInfo.Size() == 0 {
|
|
file, err := os.Create(fileName)
|
|
if err != nil {
|
|
fmt.Println("Error creating configuration file: ", err)
|
|
os.Exit(1)
|
|
}
|
|
defer file.Close()
|
|
|
|
_, err = file.Write(data)
|
|
if err != nil {
|
|
fmt.Println("Error writing to file:", err)
|
|
os.Exit(1)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// DomainCertsDirWConf Can return ErrBlankConfigEntry or other errors
|
|
func DomainCertsDirWConf(domain string, domainConfig *common.DomainConfig) string {
|
|
var effectiveDataRoot string
|
|
if domainConfig.Certificates.DataRoot == "" {
|
|
effectiveDataRoot = config.Certificates.DataRoot
|
|
} else {
|
|
effectiveDataRoot = domainConfig.Certificates.DataRoot
|
|
}
|
|
|
|
return filepath.Join(effectiveDataRoot, "certificates", domain)
|
|
}
|
|
|
|
func basicCmd(use, short string, commandFunc func(cmd *cobra.Command, args []string)) *cobra.Command {
|
|
return &cobra.Command{
|
|
Use: use,
|
|
Short: short,
|
|
Run: commandFunc,
|
|
}
|
|
}
|