updates
This commit is contained in:
@@ -126,7 +126,11 @@ func generateKey(c *gin.Context) {
|
||||
id := c.Param("id")
|
||||
|
||||
var body struct {
|
||||
Label string `json:"label"`
|
||||
Label string `json:"label"`
|
||||
KeyType string `json:"key_type"`
|
||||
KeySize int `json:"key_size"`
|
||||
Passphrase string `json:"passphrase"`
|
||||
Comment string `json:"comment"`
|
||||
}
|
||||
_ = c.ShouldBindJSON(&body)
|
||||
if body.Label == "" {
|
||||
@@ -139,7 +143,13 @@ func generateKey(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
cmdID, err := services.DispatchGenerateKey(s.ServerID, body.Label)
|
||||
cmdID, err := services.DispatchGenerateKey(s.ServerID, services.KeyGenParams{
|
||||
Label: body.Label,
|
||||
KeyType: body.KeyType,
|
||||
KeySize: body.KeySize,
|
||||
Passphrase: body.Passphrase,
|
||||
Comment: body.Comment,
|
||||
})
|
||||
if err != nil {
|
||||
c.JSON(http.StatusServiceUnavailable, gin.H{"error": err.Error()})
|
||||
return
|
||||
|
||||
@@ -53,7 +53,11 @@ type ServerCommand struct {
|
||||
}
|
||||
|
||||
type GenerateKeyCmd struct {
|
||||
Label string `json:"label"`
|
||||
Label string `json:"label"`
|
||||
KeyType string `json:"key_type,omitempty"`
|
||||
KeySize int `json:"key_size,omitempty"`
|
||||
Passphrase string `json:"passphrase,omitempty"`
|
||||
Comment string `json:"comment,omitempty"`
|
||||
}
|
||||
|
||||
type AgentMessage struct {
|
||||
|
||||
@@ -58,16 +58,31 @@ func (d *commandDispatcher) dispatch(serverID string, cmd *pb.ServerCommand) err
|
||||
}
|
||||
}
|
||||
|
||||
// KeyGenParams carries all options for a generate-key command.
|
||||
type KeyGenParams struct {
|
||||
Label string
|
||||
KeyType string
|
||||
KeySize int
|
||||
Passphrase string
|
||||
Comment string
|
||||
}
|
||||
|
||||
// DispatchGenerateKey sends a generate-key command to the named server's agent.
|
||||
// Returns the command ID that can be used to correlate the agent's result.
|
||||
func DispatchGenerateKey(serverID, label string) (string, error) {
|
||||
func DispatchGenerateKey(serverID string, p KeyGenParams) (string, error) {
|
||||
if !Dispatcher.IsConnected(serverID) {
|
||||
return "", fmt.Errorf("agent is not connected to the command stream")
|
||||
}
|
||||
cmdID := uuid.New().String()
|
||||
cmd := &pb.ServerCommand{
|
||||
CommandId: cmdID,
|
||||
GenerateKey: &pb.GenerateKeyCmd{Label: label},
|
||||
CommandId: cmdID,
|
||||
GenerateKey: &pb.GenerateKeyCmd{
|
||||
Label: p.Label,
|
||||
KeyType: p.KeyType,
|
||||
KeySize: p.KeySize,
|
||||
Passphrase: p.Passphrase,
|
||||
Comment: p.Comment,
|
||||
},
|
||||
}
|
||||
if err := Dispatcher.dispatch(serverID, cmd); err != nil {
|
||||
return "", err
|
||||
|
||||
Reference in New Issue
Block a user