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:
parent
4d03350943
commit
5dc454d752
@ -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
|
||||
}
|
||||
|
||||
@ -50,7 +50,7 @@
|
||||
<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>
|
||||
<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
|
||||
type="button"
|
||||
data-copy-target="deploy-key"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user