diff --git a/handlers_nats.go b/handlers_nats.go index 2e140dd..cb31a05 100644 --- a/handlers_nats.go +++ b/handlers_nats.go @@ -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