From 5dc454d752e40a00804edd4e2d8e2f8bd7432f44 Mon Sep 17 00:00:00 2001 From: sneak Date: Mon, 29 Dec 2025 16:51:42 +0700 Subject: [PATCH] Improve deploy key and webhook URL display - Format deploy key with comment: upaas-- - Build webhook URL using Host header with https:// --- internal/handlers/app.go | 22 +++++++++++++++++++++- templates/app_detail.html | 2 +- 2 files changed, 22 insertions(+), 2 deletions(-) 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}}