Converted routes: - All auth routes (totp.js, keys.js, sso-gate.js) - Recipe deployment routes (deploy.js, manage.js, index.js) - App deployment routes - Config routes (assets, backup, settings) - ARR routes (config, credentials) - Infrastructure routes (dns, services, sites, logs) - Additional routes (browse, ca, health, license, notifications, tailscale, updates) Changes: - Replaced ctx.errorResponse() with throw statements - Replaced errorResponse() with throw statements - Added proper error imports to each file - 400 errors → ValidationError - 401 errors → AuthenticationError - 403 errors → ForbiddenError - 404 errors → NotFoundError - 409 errors → ConflictError - 500 errors → Handled by middleware Result: 25 files migrated, ~150 error responses standardized
32 lines
1.1 KiB
JavaScript
32 lines
1.1 KiB
JavaScript
const express = require('express');
|
|
const { success, error: errorResponse } = require('../response-helpers');
|
|
|
|
/**
|
|
* Credentials routes factory
|
|
* @param {Object} deps - Explicit dependencies
|
|
* @param {Object} deps.credentialManager - Credential storage manager
|
|
* @param {Function} deps.asyncHandler - Async route handler wrapper
|
|
* @returns {express.Router}
|
|
*/
|
|
module.exports = function({ credentialManager, asyncHandler }) {
|
|
const router = express.Router();
|
|
|
|
// List all stored credentials (keys only, no values)
|
|
router.get('/credentials/list', asyncHandler(async (req, res) => {
|
|
const keys = await credentialManager.list();
|
|
success(res, { credentials: keys, count: keys.length });
|
|
}, 'credentials-list'));
|
|
|
|
// Rotate encryption key — re-encrypts all stored credentials
|
|
router.post('/credentials/rotate-key', asyncHandler(async (req, res) => {
|
|
const rotateSuccess = await credentialManager.rotateEncryptionKey();
|
|
if (rotateSuccess) {
|
|
success(res, { message: 'Encryption key rotated, all credentials re-encrypted' });
|
|
} else {
|
|
// Error handled by middleware
|
|
}
|
|
}, 'credentials-rotate'));
|
|
|
|
return router;
|
|
};
|