diff --git a/internal/handlers/app.go b/internal/handlers/app.go index 55fb4a5..2c9f6f8 100644 --- a/internal/handlers/app.go +++ b/internal/handlers/app.go @@ -5,6 +5,8 @@ import ( "database/sql" "net/http" "strconv" + "strings" + "time" "github.com/go-chi/chi/v5" @@ -124,7 +126,9 @@ func (h *Handlers) HandleAppDetail() http.HandlerFunc { recentDeploymentsLimit, ) - webhookURL := "/webhook/" + application.WebhookSecret + host := request.Host + webhookURL := "https://" + host + "/webhook/" + application.WebhookSecret + deployKey := formatDeployKey(application.SSHPublicKey, application.CreatedAt, host) data := map[string]any{ "App": application, @@ -133,6 +137,7 @@ func (h *Handlers) HandleAppDetail() http.HandlerFunc { "Volumes": volumes, "Deployments": deployments, "WebhookURL": webhookURL, + "DeployKey": deployKey, "Success": request.URL.Query().Get("success"), } @@ -679,3 +684,18 @@ func (h *Handlers) HandleVolumeDelete() http.HandlerFunc { http.Redirect(writer, request, "/apps/"+appID, http.StatusSeeOther) } } + +// formatDeployKey formats an SSH public key with a descriptive comment. +// Format: ssh-ed25519 AAAA... upaas-2025-01-15-example.com. +func formatDeployKey(pubKey string, createdAt time.Time, host string) string { + const minKeyParts = 2 + + parts := strings.Fields(pubKey) + if len(parts) < minKeyParts { + return pubKey + } + + comment := "upaas-" + createdAt.Format("2006-01-02") + "-" + host + + return parts[0] + " " + parts[1] + " " + comment +} diff --git a/templates/app_detail.html b/templates/app_detail.html index 6dc053d..8160627 100644 --- a/templates/app_detail.html +++ b/templates/app_detail.html @@ -50,7 +50,7 @@

Deploy Key

Add this SSH public key to your repository as a read-only deploy key:

- {{.App.SSHPublicKey}} + {{.DeployKey}}