fix: Multiple bug fixes and add auto-alias initialization
continuous-integration/drone/push Build is passing
continuous-integration/drone/push Build is passing
- Fix null-check in Users.tsx for user.accessKey filtering - Fix null-check in Policies.tsx for policy.name filtering - Add auto-initialization of default MinIO alias from env vars on startup - Add validation to reject "undefined"/"null" as bucket names in browser API - Server now creates DEFAULT_MINIO_ALIAS automatically if MINIO_ENDPOINT, MINIO_ACCESS_KEY, and MINIO_SECRET_KEY are provided
This commit is contained in:
@@ -24,7 +24,17 @@ const browserValidation = {
|
|||||||
bucket: param('bucket')
|
bucket: param('bucket')
|
||||||
.trim()
|
.trim()
|
||||||
.notEmpty()
|
.notEmpty()
|
||||||
.matches(/^[a-z0-9][a-z0-9.-]*[a-z0-9]$/),
|
.custom((value) => {
|
||||||
|
// Reject "undefined" and "null" strings (common frontend bugs)
|
||||||
|
if (value === 'undefined' || value === 'null') {
|
||||||
|
throw new Error('Invalid bucket name');
|
||||||
|
}
|
||||||
|
// Validate bucket name format
|
||||||
|
if (!/^[a-z0-9][a-z0-9.-]*[a-z0-9]$/.test(value)) {
|
||||||
|
throw new Error('Invalid bucket name format');
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}),
|
||||||
|
|
||||||
prefix: query('prefix')
|
prefix: query('prefix')
|
||||||
.optional()
|
.optional()
|
||||||
|
|||||||
+37
-1
@@ -159,14 +159,50 @@ app.use((req, res) => {
|
|||||||
// Error handling middleware (must be last)
|
// Error handling middleware (must be last)
|
||||||
app.use(errorHandler);
|
app.use(errorHandler);
|
||||||
|
|
||||||
|
// Initialize default MinIO alias from environment variables
|
||||||
|
async function initializeDefaultAlias() {
|
||||||
|
const { defaultAlias, endpoint, accessKey, secretKey } = config.minio;
|
||||||
|
|
||||||
|
if (!endpoint || !accessKey || !secretKey) {
|
||||||
|
logger.info('Default MinIO connection not configured (MINIO_ENDPOINT, MINIO_ACCESS_KEY, MINIO_SECRET_KEY)');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const MinIOService = require('./services/minio.service');
|
||||||
|
const minioService = new MinIOService();
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Check if alias already exists
|
||||||
|
const aliases = await minioService.listAliases();
|
||||||
|
const existingAlias = aliases.find(a => a.alias === defaultAlias);
|
||||||
|
|
||||||
|
if (existingAlias) {
|
||||||
|
logger.info(`Default alias "${defaultAlias}" already configured`);
|
||||||
|
// Test connection
|
||||||
|
const testResult = await minioService.testConnection(defaultAlias);
|
||||||
|
logger.info(`Default alias "${defaultAlias}" connection status: ${testResult.status}`);
|
||||||
|
} else {
|
||||||
|
// Create the alias
|
||||||
|
logger.info(`Creating default alias "${defaultAlias}" -> ${endpoint}`);
|
||||||
|
await minioService.addAlias(defaultAlias, endpoint, accessKey, secretKey);
|
||||||
|
logger.info(`Default alias "${defaultAlias}" created and connected successfully`);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
logger.error(`Failed to initialize default alias: ${error.message}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Start server
|
// Start server
|
||||||
if (require.main === module) {
|
if (require.main === module) {
|
||||||
const PORT = config.app.port;
|
const PORT = config.app.port;
|
||||||
|
|
||||||
app.listen(PORT, () => {
|
app.listen(PORT, async () => {
|
||||||
logger.info(`MinIO WebUI Backend running on port ${PORT}`);
|
logger.info(`MinIO WebUI Backend running on port ${PORT}`);
|
||||||
logger.info(`Environment: ${config.app.env}`);
|
logger.info(`Environment: ${config.app.env}`);
|
||||||
logger.info(`IP Restriction: ${config.security.enableIpRestriction ? 'Enabled' : 'Disabled'}`);
|
logger.info(`IP Restriction: ${config.security.enableIpRestriction ? 'Enabled' : 'Disabled'}`);
|
||||||
|
|
||||||
|
// Initialize default alias after server starts
|
||||||
|
await initializeDefaultAlias();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ const Policies: React.FC = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const filteredPolicies = policies.filter((policy) =>
|
const filteredPolicies = policies.filter((policy) =>
|
||||||
policy.name.toLowerCase().includes(searchTerm.toLowerCase())
|
policy?.name?.toLowerCase().includes(searchTerm.toLowerCase())
|
||||||
);
|
);
|
||||||
|
|
||||||
const isBuiltInPolicy = (policyName: string) => {
|
const isBuiltInPolicy = (policyName: string) => {
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ const Users: React.FC = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const filteredUsers = users.filter((user) =>
|
const filteredUsers = users.filter((user) =>
|
||||||
user.accessKey.toLowerCase().includes(searchTerm.toLowerCase())
|
user?.accessKey?.toLowerCase().includes(searchTerm.toLowerCase())
|
||||||
);
|
);
|
||||||
|
|
||||||
if (loading) {
|
if (loading) {
|
||||||
|
|||||||
Reference in New Issue
Block a user