diff --git a/internal/api_handlers.go b/internal/api_handlers.go
index c23c205..6051c31 100644
--- a/internal/api_handlers.go
+++ b/internal/api_handlers.go
@@ -541,6 +541,10 @@
http.Error(w, "domain required", http.StatusBadRequest)
return
}
+ if req.SecretName == "" {
+ http.Error(w, "secret_name required", http.StatusBadRequest)
+ return
+ }
oldCert, email, issuertype, err := internalcert.LoadCertificateData(context.Background(), api.Manager.DB, req.Domain)
if err != nil {
http.Error(w, fmt.Sprintf("failed to load existing certificate data: %v", err), http.StatusInternalServerError)
diff --git a/internal/pkg/cert/persist.go b/internal/pkg/cert/persist.go
index 1c9ccb6..797a828 100644
--- a/internal/pkg/cert/persist.go
+++ b/internal/pkg/cert/persist.go
@@ -31,9 +31,9 @@
if err := store.SaveCertificate(ctx, certStorage); err != nil {
return fmt.Errorf("failed to save certificate data for %s: %w", cert.Domain, err)
}
- if err := store.UpdateSecretDomain(ctx, secretname, cert.Domain); err != nil {
- return fmt.Errorf("failed to update the domain %s for secret %s: %w", cert.Domain, secretname, err)
- }
+ // if err := store.UpdateSecretDomain(ctx, secretname, cert.Domain); err != nil {
+ // return fmt.Errorf("failed to update the domain %s for secret %s: %w", cert.Domain, secretname, err)
+ // }
return nil
}
diff --git a/static/tools/cert_issuer.html b/static/tools/cert_issuer.html
index fda6e27..996aa3b 100644
--- a/static/tools/cert_issuer.html
+++ b/static/tools/cert_issuer.html
@@ -165,6 +165,11 @@
+
+
+
+
@@ -196,6 +201,8 @@
const statusMessage = document.getElementById('status-message');
const resultsArea = document.getElementById('results-area');
const domainInput = document.getElementById('domain');
+ // Get the secret name input element
+ const secretNameInput = document.getElementById('secret-name');
// Helper function to create a text area and action buttons for a single component
function createCertComponent(title, key, content, domain) {
@@ -222,40 +229,29 @@
let displayContent;
let downloadContent;
- // --- FIX APPLIED HERE ---
- // Key components (Cert, Key, FullChain) are expected to be PEM strings after decoding.
- // The AccountKey might be a raw binary key, which should be downloaded as-is
- // or displayed in its Base64 form if it causes encoding issues.
+ // --- Key Content Handling ---
if (key === 'AccountKey' || key === 'KeyPEM') {
- // For keys, we should ideally download the raw decoded content.
- // But for display, we'll try to decode and fall back to Base64 if it fails
- // to look like a proper PEM.
try {
- // Attempt to Base64 decode and use the decoded data for both display and download
downloadContent = atob(content);
displayContent = downloadContent;
- // Heuristic check: If it doesn't look like a standard PEM (starts with "-----"),
- // display the Base64 version to prevent "garbage" text.
if (!displayContent.startsWith('-----')) {
- displayContent = content; // Display Base64
+ displayContent = content; // Display Base64 if not a standard PEM
}
} catch (e) {
- // If decoding fails, just use the Base64 string for display
downloadContent = content;
displayContent = content;
}
} else {
- // CertPEM and FullChain are almost certainly PEM format after decoding.
downloadContent = atob(content);
displayContent = downloadContent;
}
textarea.value = displayContent;
- // --- END FIX ---
+ // --- END Key Content Handling ---
itemDiv.appendChild(textarea);
@@ -265,7 +261,6 @@
// 1. Download Button
const downloadBtn = document.createElement('button');
downloadBtn.textContent = `Download (${extMap[key] || '.txt'})`;
- // Use the potentially raw/decoded content for download
downloadBtn.onclick = () => downloadFile(downloadContent, defaultFilename, 'text/plain');
actionsDiv.appendChild(downloadBtn);
@@ -330,12 +325,15 @@
submitBtn.textContent = 'Issuing... Please Wait ⏳';
const domain = domainInput.value.trim();
+ // Using snake_case for the variable name
+ const secret_name = secretNameInput.value.trim();
const email = document.getElementById('email').value.trim();
const issuer = document.getElementById('issuer').value;
showStatus(`Requesting certificate for ${domain}...`, false);
- const requestBody = { domain, email, issuer };
+ // Using 'secret_name' as the key in the request body
+ const requestBody = { domain, secret_name, email, issuer };
try {
const response = await fetch(API_ENDPOINT, {
@@ -356,7 +354,6 @@
if (!response.ok) {
// Handle API-side error (e.g., HTTP 400 or 500)
- // Prioritize specific error messages from the server response (e.g., 'error' or 'message')
const errorDetails = data.error || data.message || `HTTP ${response.status} Error`;
// Throw the detailed error. The catch block will display it.
@@ -392,7 +389,41 @@
}
}
+ // --- Logic for Secret Name Default Value ---
+
+ // Function to generate the secret name from the domain (s/./_//g)
+ function generateSecretName(domain) {
+ // Replace all occurrences of '.' with '_'
+ return domain.trim().toLowerCase().replace(/\./g, '_');
+ }
+
+ // Handler to update the secret name field whenever the domain changes
+ function updateSecretNameDefault() {
+ // Only update if the user hasn't typed anything in the secret name field
+ // OR if the current value is exactly the default value generated from the old domain
+ const currentDomain = domainInput.value;
+ const currentSecretName = secretNameInput.value;
+ const oldDefault = generateSecretName(domainInput.dataset.lastDomain || '');
+
+ if (currentSecretName === '' || currentSecretName === oldDefault) {
+ const newSecretName = generateSecretName(currentDomain);
+ secretNameInput.value = newSecretName;
+ // Store the current domain to check against on the next input event
+ domainInput.dataset.lastDomain = currentDomain;
+ }
+ }
+
+ // Attach the event listeners
form.addEventListener('submit', handleSubmit);
+
+ // Update the secret name field whenever the domain input changes
+ domainInput.addEventListener('input', updateSecretNameDefault);
+
+ // Initial setup on page load
+ document.addEventListener('DOMContentLoaded', () => {
+ // Check if there is already a domain value (e.g., from browser autofill)
+ updateSecretNameDefault();
+ });