Skip to content

Commit

Permalink
Merge pull request #19 from SgtCoDFish/bettersign
Browse files Browse the repository at this point in the history
Add a success page for signing
  • Loading branch information
jetstack-bot authored Mar 18, 2024
2 parents e280a9d + a5a250e commit 4d36f2f
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 13 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ print-your-cert-front.tar
*arm64
guestbook/guestbook
guestbook/guestbook.sqlite

*.age
root-print-your-cert-ca.yaml
8 changes: 7 additions & 1 deletion after-print.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,20 @@
<div class="wrapper">
<img src="static/images/logo.svg" alt="Logo" width="220" height="191" />
<h1>Printing your certificate</h1>
<div>

<div class="divider"></div>

{{if .Error}}
<div class="error">{{.Error}}</div>
{{end}}

{{if .CertName}}
<div class="success">
<p style="color: seagreen">Your certificate should now get printed! Redirecting to your certificate in 2 seconds...</p>
</div>

<div class="divider"></div>

<form method="GET" action="/certificate" class="form">
<input name="certName" type="text" value="{{.CertName}}" hidden required />
<input name="fetchKey" type="text" value="{{.FetchKey}}" hidden required />
Expand Down
43 changes: 43 additions & 0 deletions after-sign.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
href="https://fonts.googleapis.com/css2?family=Montserrat:wght@300;400;500;700&display=swap"
rel="stylesheet"
/>
<link rel="stylesheet" href="static/styles.css" />
<!--<meta http-equiv="refresh" content="2;URL=/certificate?certName={{.CertName}}&fetchKey={{.FetchKey}}">-->
</head>

<body>
<div class="wrapper">
<img src="static/images/logo.svg" alt="Logo" width="220" height="191" />
<h1>Signing the Guestbook</h1>

<div class="divider"></div>

{{if .Error}}
<div class="error">{{.Error}}</div>
{{end}}

{{if .CertName}}
<div>
<p>You signed the guestbook! Thanks for taking part in the cert-manager booth demo!</p>
<p>Note that you get a bonus star in the guestbook if you sign manually using your cert.</p>
<p>You can download your certificate and private key using the QR code on your printed cert.</p>
</div>

<div class="divider"></div>

<form method="GET" action="/certificate" class="form">
<input name="certName" type="text" value="{{.CertName}}" hidden required />
<input name="fetchKey" type="text" value="{{.FetchKey}}" hidden required />
<input type="submit" value="Back to your certificate" class="constrain" />
</form>
{{end}}
</div>
</body>
</html>
19 changes: 8 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,14 +292,14 @@ func printPage(kclient kubernetes.Interface, cmclient cmversioned.Interface) htt
_, err := cmclient.CertmanagerV1().Certificates(*namespace).Update(r.Context(), cert, metav1.UpdateOptions{})
if err != nil {
w.WriteHeader(500)
tmpl.ExecuteTemplate(w, "after-print.html", printPageData{CertName: certName, Error: "Could not trigger the print of the certificate. Please go to the previous page and press the button again."})
tmpl.ExecuteTemplate(w, "after-print.html", afterEventPageData{CertName: certName, FetchKey: fetchKey, Error: "Could not trigger certificate printing. Please go to the previous page and press the button again."})
log.Printf("POST /: could not trigger the print of the certificate %s in namespace %s: %v", certName, *namespace, err)
return
}

// Done!
w.WriteHeader(200)
tmpl.ExecuteTemplate(w, "after-print.html", printPageData{CertName: certName, FetchKey: fetchKey})
tmpl.ExecuteTemplate(w, "after-print.html", afterEventPageData{CertName: certName, FetchKey: fetchKey})
log.Printf("POST /: the certificate %s in namespace %s was added the annotation print:true", certName, *namespace)
})
}
Expand Down Expand Up @@ -535,14 +535,11 @@ func signGuestbookPage(guestbookURL string, remoteRoots *x509.CertPool, kclient
}
}

destQuery := url.Values{
"certName": []string{certName},
"fetchKey": []string{fetchKey},
}

destination := "/certificate?" + destQuery.Encode()
http.Redirect(w, r, destination, http.StatusFound)
tmpl.ExecuteTemplate(w, "landing.html", landingPageData{Error: "Redirecting..."})
w.WriteHeader(200)
tmpl.ExecuteTemplate(w, "after-sign.html", afterEventPageData{
CertName: certName,
FetchKey: fetchKey,
})
})
}

Expand Down Expand Up @@ -802,7 +799,7 @@ type landingPageData struct {
Duplicate bool
}

type printPageData struct {
type afterEventPageData struct {
CertName string // Mandatory.
FetchKey string // Mandatory.
Error string // Optional.
Expand Down
13 changes: 12 additions & 1 deletion setup_cluster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,21 @@

set -eu -o pipefail

CM_VERSION=${CM_VERSION:-v1.14.4}

#kind load docker-image --name printyourcert quay.io/jetstack/cert-manager-controller:$CM_VERSION
#kind load docker-image --name printyourcert quay.io/jetstack/cert-manager-cainjector:$CM_VERSION
#kind load docker-image --name printyourcert quay.io/jetstack/cert-manager-ctl:$CM_VERSION
#kind load docker-image --name printyourcert quay.io/jetstack/cert-manager-webhook:$CM_VERSION
#helm install cert-manager jetstack/cert-manager --namespace cert-manager --create-namespace --version $CM_VERSION --set installCRDs=true

helm repo add jetstack https://charts.jetstack.io --force-update
helm upgrade --install cert-manager --namespace cert-manager jetstack/cert-manager --set installCRDs=true --create-namespace
helm install cert-manager jetstack/cert-manager --namespace cert-manager --create-namespace --version $CM_VERSION --set installCRDs=true

kubectl apply -f root_issuer_dev.yaml --wait
#kubectl apply -f root-print-your-cert-ca.yaml
#kubectl apply -f root_issuer_prod.yaml

kubectl apply -f cluster_issuer.yaml --wait

kubectl apply -f guestbook/certificate.yaml --wait
Expand Down

0 comments on commit 4d36f2f

Please sign in to comment.