auto generate cert keys

This commit is contained in:
Alireza Ahmadi
2024-06-13 20:16:04 +02:00
parent d057076251
commit b144aecb6a
11 changed files with 215 additions and 20 deletions
+5
View File
@@ -163,6 +163,11 @@ func (a *APIHandler) getHandler(c *gin.Context) {
count := c.Query("c")
changes := a.ConfigService.GetChanges(actor, chngKey, count)
jsonObj(c, changes, nil)
case "keypairs":
kType := c.Query("k")
options := c.Query("o")
keypair := a.ServerService.GenKeypair(kType, options)
jsonObj(c, keypair, nil)
default:
jsonMsg(c, "API call", nil)
}
+20
View File
@@ -159,3 +159,23 @@ func (s *ServerService) GetLogs(service string, count string, level string) []st
return lines
}
func (s *ServerService) GenKeypair(keyType string, options string) []string {
if len(keyType) == 0 {
return []string{"No keypair to generate"}
}
sbExec := s.GetBinaryPath()
cmdArgs := []string{"generate", keyType + "-keypair"}
if keyType == "tls" || keyType == "ech" {
cmdArgs = append(cmdArgs, options)
}
// Run the command
cmd := exec.Command(sbExec, cmdArgs...)
var out bytes.Buffer
cmd.Stdout = &out
err := cmd.Run()
if err != nil {
return []string{"Failed to generate keypair"}
}
return strings.Split(out.String(), "\n")
}