|
22 | 22 | from django.utils.http import url_has_allowed_host_and_scheme |
23 | 23 | from django.views import View |
24 | 24 | from django.views.generic.edit import FormView |
25 | | -from drf_spectacular.utils import extend_schema, extend_schema_view |
| 25 | +from drf_spectacular.utils import ( |
| 26 | + OpenApiParameter, |
| 27 | + OpenApiTypes, |
| 28 | + extend_schema, |
| 29 | + extend_schema_view, |
| 30 | +) |
26 | 31 | from haystack.query import SQ, SearchQuerySet |
27 | 32 | from rest_framework import authentication, permissions |
28 | 33 | from rest_framework.authtoken.models import Token |
@@ -1080,11 +1085,10 @@ def logout_user(request): |
1080 | 1085 | def _pbi_token_via_managed_identity() -> str | None: |
1081 | 1086 | """ |
1082 | 1087 | Acquire an AAD access token for Power BI using the AKS managed identity. |
1083 | | - If POWERBI_AZURE_CLIENT_ID is provided, target that user-assigned MI. |
1084 | | - (There is another AZURE_CLIENT_ID among env vars, that is why this distinctive name is used.) |
| 1088 | + If AZURE_CLIENT_ID is provided, target that user-assigned Managed Identity. |
1085 | 1089 | """ |
1086 | 1090 | try: |
1087 | | - client_id = getattr(settings, "POWERBI_AZURE_CLIENT_ID", None) or os.getenv("POWERBI_AZURE_CLIENT_ID") |
| 1091 | + client_id = getattr(settings, "AZURE_CLIENT_ID", None) or os.getenv("AZURE_CLIENT_ID") |
1088 | 1092 | if client_id: |
1089 | 1093 | cred = ManagedIdentityCredential(client_id=client_id) |
1090 | 1094 | else: |
@@ -1169,31 +1173,47 @@ class AuthPowerBI(APIView): |
1169 | 1173 | authentication_classes = (authentication.TokenAuthentication,) # later to SessionAuthentication |
1170 | 1174 | permission_classes = (permissions.IsAuthenticated,) |
1171 | 1175 |
|
| 1176 | + @extend_schema( |
| 1177 | + parameters=[ |
| 1178 | + OpenApiParameter( |
| 1179 | + name="report_id", |
| 1180 | + type=OpenApiTypes.STR, |
| 1181 | + location=OpenApiParameter.QUERY, |
| 1182 | + required=False, |
| 1183 | + description=("Power BI report identifier. If omitted, the first report in the configured workspace is used."), |
| 1184 | + ), |
| 1185 | + OpenApiParameter( |
| 1186 | + name="debug", |
| 1187 | + type=OpenApiTypes.BOOL, |
| 1188 | + location=OpenApiParameter.QUERY, |
| 1189 | + required=False, |
| 1190 | + description=("Enable debug-lite logging of safe token claim metadata (tid, appid, oid, aud, exp)."), |
| 1191 | + ), |
| 1192 | + ] |
| 1193 | + ) |
1172 | 1194 | def get(self, request): |
1173 | 1195 | # Try real Power BI via managed identity |
1174 | | - # Accept config from settings or environment for parity with diagnostics command |
| 1196 | + # Workspace can come from settings or environment; report_id must come from query param |
1175 | 1197 | workspace_id = getattr(settings, "POWERBI_WORKSPACE_ID", None) or os.getenv("POWERBI_WORKSPACE_ID") |
1176 | | - # Support both POWERBI_REPORT_ID (preferred) and legacy REPORT_ID, plus env override |
1177 | | - report_id_cfg = ( |
1178 | | - getattr(settings, "POWERBI_REPORT_ID", None) or getattr(settings, "REPORT_ID", None) or os.getenv("POWERBI_REPORT_ID") |
1179 | | - ) |
| 1198 | + # Receive report id from GET parameter only; do not use env/settings |
| 1199 | + report_id_param = request.query_params.get("report_id") |
1180 | 1200 | access_token = _pbi_token_via_managed_identity() |
1181 | 1201 |
|
1182 | 1202 | # Optional debug-lite: log selected token claims and config when requested |
1183 | 1203 | debug_flag = str(request.query_params.get("debug", "")).lower() in {"1", "true", "yes", "on"} |
1184 | 1204 | if debug_flag: |
1185 | 1205 | logger.info( |
1186 | | - "AuthPowerBI debug-lite enabled: workspace_id=%s report_id_cfg=%s has_token=%s", |
| 1206 | + "AuthPowerBI debug-lite enabled: workspace_id=%s report_id_param=%s has_token=%s", |
1187 | 1207 | workspace_id, |
1188 | | - report_id_cfg, |
| 1208 | + report_id_param, |
1189 | 1209 | bool(access_token), |
1190 | 1210 | ) |
1191 | 1211 | if access_token: |
1192 | 1212 | _log_token_claims_safe(access_token) |
1193 | 1213 |
|
1194 | 1214 | if access_token and workspace_id: |
1195 | 1215 | try: |
1196 | | - embed_url, report_id, embed_token, expires_at = _pbi_get_embed_info(access_token, workspace_id, report_id_cfg) |
| 1216 | + embed_url, report_id, embed_token, expires_at = _pbi_get_embed_info(access_token, workspace_id, report_id_param) |
1197 | 1217 | return Response( |
1198 | 1218 | { |
1199 | 1219 | "detail": "ok", |
|
0 commit comments