Get host ssh key handler
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Adam Štrauch 2023-04-13 20:07:31 +02:00
parent 8051310677
commit 9a37518431
Signed by: cx
GPG Key ID: 018304FFA8988F8D
1 changed files with 38 additions and 0 deletions

View File

@ -51,6 +51,7 @@ func _messageHandler(m *nats.Msg) error {
"start": startEventHandler,
"restart": restartEventHandler,
"get_deploy_ssh_keys": getDeploySSHKeysEventHandler,
"get_ssh_host_key": getSSHHostKeyEventHandler,
"update_keys": updateKeysEventHandler,
"set_password": setPasswordEventHandler,
"processes": processesEventHandler,
@ -438,6 +439,43 @@ func getDeploySSHKeysEventHandler(m *nats.Msg, message *RequestMessage) error {
return nil
}
// Returns SSH host key
func getSSHHostKeyEventHandler(m *nats.Msg, message *RequestMessage) error {
processor := glue.Processor{
AppName: message.AppName,
DB: common.GetDBConnection(),
SnapshotProcessor: &snapshotProcessor,
DockerSock: config.DockerSocket,
BindIPHTTP: config.AppsBindIPHTTP,
BindIPSSH: config.AppsBindIPSSH,
AppsPath: config.AppsPath,
}
hostKey, err := processor.GetHostKey()
if err != nil {
log.Printf("backend error: %v\n", err)
return errorReplyFormater(m, "backend error", err)
}
// Assembling reply message
reply := ReplyMessage{
Payload: hostKey,
}
data, err := json.Marshal(reply)
if err != nil {
return errorReplyFormater(m, "reply formatter error", err)
}
err = m.Respond(data)
if err != nil {
log.Println("ERROR: get app:", err.Error())
return err
}
return nil
}
// Copies body of the request into /srv/.ssh/authorized_keys
func updateKeysEventHandler(m *nats.Msg, message *RequestMessage) error {
body := message.Payload