Major Refactoring, Client can now be used as a library
Some checks failed
Build (artifact) / build (push) Failing after 1m3s
Some checks failed
Build (artifact) / build (push) Failing after 1m3s
This commit is contained in:
72
app/shared/util.go
Normal file
72
app/shared/util.go
Normal file
@@ -0,0 +1,72 @@
|
||||
package shared
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"git.nevets.tech/Keys/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,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user