auto generate cert keys
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user