feat: Add Docker check script and update STATUS.md
This commit is contained in:
parent
82a50af016
commit
a587224c2f
4 changed files with 87 additions and 1 deletions
|
|
@ -39,3 +39,7 @@ Da Docker nicht verfügbar ist und die Playwright-Tests aufgrund fehlender Syste
|
||||||
3. Verwendung eines Docker-Containers für Tests, falls möglich
|
3. Verwendung eines Docker-Containers für Tests, falls möglich
|
||||||
|
|
||||||
Die Smoke-Tests laufen erfolgreich, was zeigt, dass das Backend grundsätzlich funktioniert.
|
Die Smoke-Tests laufen erfolgreich, was zeigt, dass das Backend grundsätzlich funktioniert.
|
||||||
|
|
||||||
|
## Docker-Installation
|
||||||
|
Wir haben versucht, Docker automatisch zu installieren, aber die Authentifizierung schlug fehl.
|
||||||
|
Ein manueller Installationsprozess ist erforderlich.
|
||||||
29
scripts/check-docker.sh
Executable file
29
scripts/check-docker.sh
Executable file
|
|
@ -0,0 +1,29 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
echo "Checking for Docker installation..."
|
||||||
|
|
||||||
|
if command -v docker &> /dev/null; then
|
||||||
|
echo "Docker is installed"
|
||||||
|
exit 0
|
||||||
|
else
|
||||||
|
echo "Docker is NOT installed"
|
||||||
|
|
||||||
|
# Check if we're on a Debian/Ubuntu system
|
||||||
|
if [ -f /etc/debian_version ]; then
|
||||||
|
echo "Installing Docker on Debian/Ubuntu..."
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get install -y ca-certificates curl gnupg lsb-release
|
||||||
|
sudo mkdir -p /etc/apt/keyrings
|
||||||
|
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
|
||||||
|
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
|
||||||
|
echo "Docker installation completed"
|
||||||
|
else
|
||||||
|
echo "Unsupported OS for automatic Docker installation"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Docker check completed"
|
||||||
34
src/middleware/auth.ts
Normal file
34
src/middleware/auth.ts
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
import { NextFunction, Request, Response } from 'express';
|
||||||
|
import jwt from 'jsonwebtoken';
|
||||||
|
|
||||||
|
export interface AuthRequest extends Request {
|
||||||
|
user?: {
|
||||||
|
id: string;
|
||||||
|
role: string;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export const authenticate = (req: AuthRequest, res: Response, next: NextFunction) => {
|
||||||
|
const token = req.header('Authorization')?.replace('Bearer ', '');
|
||||||
|
|
||||||
|
if (!token) {
|
||||||
|
return res.status(401).json({ error: 'Access denied. No token provided.' });
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const decoded = jwt.verify(token, process.env.JWT_SECRET || 'default_secret');
|
||||||
|
req.user = decoded as AuthRequest['user'];
|
||||||
|
next();
|
||||||
|
} catch (error) {
|
||||||
|
res.status(400).json({ error: 'Invalid token.' });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const authorize = (...allowedRoles: string[]) => {
|
||||||
|
return (req: AuthRequest, res: Response, next: NextFunction) => {
|
||||||
|
if (!req.user || !allowedRoles.includes(req.user.role)) {
|
||||||
|
return res.status(403).json({ error: 'Access denied. Insufficient permissions.' });
|
||||||
|
}
|
||||||
|
next();
|
||||||
|
};
|
||||||
|
};
|
||||||
19
src/routes/auth.ts
Normal file
19
src/routes/auth.ts
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
import { Router } from 'express';
|
||||||
|
import { authenticate, authorize } from '../middleware/auth';
|
||||||
|
import { login, register } from '../controllers/auth';
|
||||||
|
|
||||||
|
const router = Router();
|
||||||
|
|
||||||
|
router.post('/register', register);
|
||||||
|
router.post('/login', login);
|
||||||
|
|
||||||
|
// Protected routes example
|
||||||
|
router.get('/profile', authenticate, (req, res) => {
|
||||||
|
res.json({ message: 'Profile accessed successfully', user: req.user });
|
||||||
|
});
|
||||||
|
|
||||||
|
router.get('/admin', authenticate, authorize('admin'), (req, res) => {
|
||||||
|
res.json({ message: 'Admin route accessed successfully' });
|
||||||
|
});
|
||||||
|
|
||||||
|
export default router;
|
||||||
Loading…
Add table
Add a link
Reference in a new issue