Improve deploy key and webhook URL display

- Format deploy key with comment: upaas-<date>-<vhost>
- Build webhook URL using Host header with https://
This commit is contained in:
Jeffrey Paul 2025-12-29 16:51:42 +07:00
parent 4d03350943
commit 5dc454d752
2 changed files with 22 additions and 2 deletions

View File

@ -5,6 +5,8 @@ import (
"database/sql" "database/sql"
"net/http" "net/http"
"strconv" "strconv"
"strings"
"time"
"github.com/go-chi/chi/v5" "github.com/go-chi/chi/v5"
@ -124,7 +126,9 @@ func (h *Handlers) HandleAppDetail() http.HandlerFunc {
recentDeploymentsLimit, 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{ data := map[string]any{
"App": application, "App": application,
@ -133,6 +137,7 @@ func (h *Handlers) HandleAppDetail() http.HandlerFunc {
"Volumes": volumes, "Volumes": volumes,
"Deployments": deployments, "Deployments": deployments,
"WebhookURL": webhookURL, "WebhookURL": webhookURL,
"DeployKey": deployKey,
"Success": request.URL.Query().Get("success"), "Success": request.URL.Query().Get("success"),
} }
@ -679,3 +684,18 @@ func (h *Handlers) HandleVolumeDelete() http.HandlerFunc {
http.Redirect(writer, request, "/apps/"+appID, http.StatusSeeOther) 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
}

View File

@ -50,7 +50,7 @@
<h2 class="section-title mb-4">Deploy Key</h2> <h2 class="section-title mb-4">Deploy Key</h2>
<p class="text-sm text-gray-500 mb-3">Add this SSH public key to your repository as a read-only deploy key:</p> <p class="text-sm text-gray-500 mb-3">Add this SSH public key to your repository as a read-only deploy key:</p>
<div class="copy-field"> <div class="copy-field">
<code id="deploy-key" class="copy-field-value text-xs">{{.App.SSHPublicKey}}</code> <code id="deploy-key" class="copy-field-value text-xs">{{.DeployKey}}</code>
<button <button
type="button" type="button"
data-copy-target="deploy-key" data-copy-target="deploy-key"