<host>/ssh.pub
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
@@ -13,6 +14,8 @@ import (
|
||||
"novit.tech/direktil/local-server/pkg/mime"
|
||||
)
|
||||
|
||||
var sshKeyTypes = []string{"rsa", "ecdsa", "ed25519"}
|
||||
|
||||
type AssetVariant struct {
|
||||
name string
|
||||
url string
|
||||
@@ -132,6 +135,9 @@ func (ws wsHost) register(rws *restful.WebService, alterRB func(*restful.RouteBu
|
||||
b("bootstrap.tar").
|
||||
Produces(mime.TAR).
|
||||
Doc("Get the " + ws.hostDoc + "'s bootstrap seed archive"),
|
||||
|
||||
// ssh
|
||||
b("ssh.pub").Produces("text/plain").Doc("Get the " + ws.hostDoc + "'s ssh public keys"),
|
||||
} {
|
||||
alterRB(rb)
|
||||
rws.Route(rb)
|
||||
@@ -253,6 +259,9 @@ func renderHost(w http.ResponseWriter, r *http.Request, what string, host *local
|
||||
case "ipxe":
|
||||
err = renderIPXE(w, ctx)
|
||||
|
||||
case "ssh.pub":
|
||||
err = renderSshPub(w, ctx)
|
||||
|
||||
default:
|
||||
http.NotFound(w, r)
|
||||
}
|
||||
@@ -262,3 +271,18 @@ func renderHost(w http.ResponseWriter, r *http.Request, what string, host *local
|
||||
http.Error(w, "", http.StatusServiceUnavailable)
|
||||
}
|
||||
}
|
||||
|
||||
func renderSshPub(w http.ResponseWriter, ctx *renderContext) (err error) {
|
||||
buf := new(bytes.Buffer)
|
||||
|
||||
for _, t := range sshKeyTypes {
|
||||
k, err := ctx.sshHostKeyPair(t)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
buf.WriteString(k.Public)
|
||||
}
|
||||
|
||||
_, err = w.Write(buf.Bytes())
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user