Skip to content

Commit 6d8a642

Browse files
Merge branch 'feature/keycloak-middleware-clean' into enhancement/openremote-client-service-register
2 parents 20416cf + fc2332e commit 6d8a642

File tree

6 files changed

+21
-18
lines changed

6 files changed

+21
-18
lines changed

docker/Dockerfile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ COPY frontend/ ./
1414
# Define build arguments
1515
ARG ML_SERVICE_URL
1616
ARG ML_WEB_ROOT_PATH
17-
ARG ML_KEYCLOAK_URL
17+
ARG ML_OR_KEYCLOAK_URL
18+
ARG ML_OR_URL
1819

1920
RUN ML_SERVICE_URL=${ML_SERVICE_URL:-/services/ml-forecast} \
2021
ML_WEB_ROOT_PATH=${ML_WEB_ROOT_PATH:-/services/ml-forecast/ui} \
21-
ML_KEYCLOAK_URL=${ML_KEYCLOAK_URL:-/auth} \
22+
ML_OR_KEYCLOAK_URL=${ML_OR_KEYCLOAK_URL:-/auth} \
23+
ML_OR_URL=${ML_OR_URL:-} \
2224
npm run build:prod
2325

2426
# --- Python Build Phase -------------------------------------------------------

docker/docker-compose.yml

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,21 @@ services:
66
context: ..
77
dockerfile: docker/Dockerfile
88
args:
9-
ML_KEYCLOAK_URL: ${ML_KEYCLOAK_URL:-/auth} # OpenRemote Keycloak URL
10-
ML_SERVICE_URL: ${ML_SERVICE_URL:-/services/ml-forecast} # Url to reach the back-end service, should be the same as ML_API_ROOT_PATH
11-
ML_WEB_ROOT_PATH: ${ML_WEB_ROOT_PATH:-/services/ml-forecast/ui} # Public path for the front-end (e.g. when behind a reverse proxy)
9+
ML_OR_URL: ${ML_OR_URL} # OpenRemote URL
10+
ML_OR_KEYCLOAK_URL: ${ML_OR_KEYCLOAK_URL} # OpenRemote Keycloak URL
11+
ML_SERVICE_URL: ${ML_SERVICE_URL} # Url to reach the back-end service, should be the same as ML_API_ROOT_PATH
12+
ML_WEB_ROOT_PATH: ${ML_WEB_ROOT_PATH} # Public path for the front-end (e.g. when behind a reverse proxy)
1213
container_name: service-ml-forecast
1314
ports:
1415
- "8000:8000"
1516
environment:
16-
- ML_LOG_LEVEL=${ML_LOG_LEVEL:-INFO} # Log level to use
17-
- ML_ENVIRONMENT=${ML_ENVIRONMENT:-production} # Environment to run the service in
18-
- ML_API_ROOT_PATH=${ML_API_ROOT_PATH:-/services/ml-forecast} # Public path for the back-end (e.g. when behind a reverse proxy)
19-
- ML_OR_URL=${ML_OR_URL:-http://host.docker.internal:8080} # OpenRemote URL
20-
- ML_OR_KEYCLOAK_URL=${ML_OR_KEYCLOAK_URL:-http://host.docker.internal:8081} # OpenRemote Keycloak URL
21-
- ML_OR_SERVICE_USER=${ML_OR_SERVICE_USER:-serviceuser} # OpenRemote service user
22-
- ML_OR_SERVICE_USER_SECRET=${ML_OR_SERVICE_USER_SECRET:-secret} # OpenRemote service user secret
17+
- ML_LOG_LEVEL=${ML_LOG_LEVEL} # Log level to use
18+
- ML_ENVIRONMENT=${ML_ENVIRONMENT} # Environment to run the service in
19+
- ML_API_ROOT_PATH=${ML_API_ROOT_PATH} # Public path for the back-end (e.g. when behind a reverse proxy)
20+
- ML_OR_URL=${ML_OR_URL} # OpenRemote URL
21+
- ML_OR_KEYCLOAK_URL=${ML_OR_KEYCLOAK_URL} # OpenRemote Keycloak URL
22+
- ML_OR_SERVICE_USER=${ML_OR_SERVICE_USER} # OpenRemote service user
23+
- ML_OR_SERVICE_USER_SECRET=${ML_OR_SERVICE_USER_SECRET} # OpenRemote service user secret
2324
volumes:
2425
# Model storage
2526
- ../deployment/data/models:/app/deployment/data/models

frontend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"type": "module",
66
"scripts": {
77
"serve": "cross-env rspack serve",
8-
"build:prod": "cross-env ML_KEYCLOAK_URL=${ML_KEYCLOAK_URL:-/auth} ML_SERVICE_URL=${ML_SERVICE_URL:-/services/ml-forecast} ML_WEB_ROOT_PATH=${ML_WEB_ROOT_PATH:-/services/ml-forecast/ui} rspack build --mode production",
8+
"build:prod": "cross-env ML_OR_KEYCLOAK_URL=${ML_OR_KEYCLOAK_URL:-/auth} ML_OR_URL=${ML_OR_URL} ML_SERVICE_URL=${ML_SERVICE_URL:-/services/ml-forecast} ML_WEB_ROOT_PATH=${ML_WEB_ROOT_PATH:-/services/ml-forecast/ui} rspack build --mode production",
99
"build:analyze": "rspack build --mode production --analyze",
1010
"lint": "eslint && prettier . --check",
1111
"format": "prettier . --write"

frontend/rspack.config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ const __dirname = path.dirname(__filename);
99
const isProduction = process.env.NODE_ENV === 'production';
1010
const rootPath = process.env.ML_WEB_ROOT_PATH;
1111
const serviceUrl = process.env.ML_SERVICE_URL || 'http://localhost:8000'; // Default to default service backend
12-
const keycloakUrl = process.env.ML_KEYCLOAK_URL || 'http://localhost:8081/auth'; // Default to openremote keycloak address
13-
const openremoteUrl = process.env.ML_OR_URL || 'http://localhost:8080';
12+
const keycloakUrl = process.env.ML_OR_KEYCLOAK_URL || 'http://localhost:8081/auth'; // Default to openremote keycloak address
13+
const openremoteUrl = process.env.ML_OR_URL !== undefined ? process.env.ML_OR_URL : 'http://localhost:8080'; // Default to openremote url
1414

1515
export default {
1616
mode: isProduction ? 'production' : 'development',
@@ -67,7 +67,7 @@ export default {
6767
}),
6868
new rspack.DefinePlugin({
6969
'process.env.ML_SERVICE_URL': JSON.stringify(serviceUrl),
70-
'process.env.ML_KEYCLOAK_URL': JSON.stringify(keycloakUrl),
70+
'process.env.ML_OR_KEYCLOAK_URL': JSON.stringify(keycloakUrl),
7171
'process.env.ML_OR_URL': JSON.stringify(openremoteUrl)
7272
})
7373
],

frontend/src/services/auth-service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { IS_EMBEDDED } from '../common/constants';
2020
import { manager } from '@openremote/core';
2121
import { AxiosRequestConfig } from 'axios';
2222

23-
const keycloakUrl: string = (process.env.ML_KEYCLOAK_URL || '').replace(/\/$/, '');
23+
const keycloakUrl: string = (process.env.ML_OR_KEYCLOAK_URL || '').replace(/\/$/, '');
2424

2525
type AuthChangeListener = () => void;
2626

src/service_ml_forecast/middlewares/keycloak_middleware.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ def _is_excluded_route(path: str, excluded_routes: list[str]) -> bool:
262262

263263
class KeycloakMiddleware(BaseHTTPMiddleware):
264264
"""
265-
Middleware that verifies Bearer token against OR_ML_KEYCLOAK_URL's JWKS endpoint.
265+
Middleware that verifies Bearer token against ML_OR_KEYCLOAK_URL's JWKS endpoint.
266266
Routes can be excluded from authentication by providing a list of route paths.
267267
"""
268268

0 commit comments

Comments
 (0)