fix: resolve SSH key and errcheck linter issues

Deploy workflow fixes:
- Add tr -d '\r' to strip carriage returns from SSH key
- Set chmod 700 on .ssh directory for proper permissions
- Suppress ssh-keyscan stderr output

Handler code fixes:
- Check json.Encode() return values in errors.go (2 locations)
- Check json.Encode() return value in health.go
- Add log import to health.go
- Log encoding errors instead of silently ignoring

Resolves:
- "Load key: error in libcrypto" SSH deployment error
- 3 errcheck linter warnings
This commit is contained in:
juanatsap
2025-10-31 12:23:48 +00:00
parent b167378526
commit eb920baace
3 changed files with 15 additions and 6 deletions
+4 -3
View File
@@ -25,9 +25,10 @@ jobs:
# Setup SSH
mkdir -p ~/.ssh
echo "$SSH_PRIVATE_KEY" > ~/.ssh/deploy_key
chmod 700 ~/.ssh
echo "$SSH_PRIVATE_KEY" | tr -d '\r' > ~/.ssh/deploy_key
chmod 600 ~/.ssh/deploy_key
ssh-keyscan -p $SSH_PORT -H $SSH_HOST >> ~/.ssh/known_hosts
ssh-keyscan -p $SSH_PORT -H $SSH_HOST >> ~/.ssh/known_hosts 2>/dev/null
# Pull latest code and restart service
echo "🔄 Pulling latest code and restarting service..."
@@ -70,7 +71,7 @@ jobs:
echo "🔍 Verifying deployment..."
# Setup SSH for verification
echo "$SSH_PRIVATE_KEY" > ~/.ssh/deploy_key
echo "$SSH_PRIVATE_KEY" | tr -d '\r' > ~/.ssh/deploy_key
chmod 600 ~/.ssh/deploy_key
# Test health endpoint
+6 -2
View File
@@ -79,7 +79,9 @@ func HandleError(w http.ResponseWriter, r *http.Request, err error) {
response.Message = appErr.Message
}
json.NewEncoder(w).Encode(response)
if err := json.NewEncoder(w).Encode(response); err != nil {
log.Printf("ERROR encoding JSON response: %v", err)
}
return
}
@@ -93,7 +95,9 @@ func HandleError(w http.ResponseWriter, r *http.Request, err error) {
message = "An error occurred. Please try again later."
}
w.Write([]byte("<div class='error'>" + message + "</div>"))
if _, err := w.Write([]byte("<div class='error'>" + message + "</div>")); err != nil {
log.Printf("ERROR writing HTMX error response: %v", err)
}
return
}
+5 -1
View File
@@ -2,6 +2,7 @@ package handlers
import (
"encoding/json"
"log"
"net/http"
"time"
)
@@ -35,5 +36,8 @@ func (h *HealthHandler) Check(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(response)
if err := json.NewEncoder(w).Encode(response); err != nil {
// Log error but don't change response status (already written)
log.Printf("ERROR encoding health check response: %v", err)
}
}