Skip to content

Commit

Permalink
fix: [PROD-11540] Multiple PBI Workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
ardvi committed May 23, 2023
1 parent b6f5860 commit 7c9927e
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 20 deletions.
5 changes: 3 additions & 2 deletions api/GetEmbedInfo/embedConfigService.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ const fetch = (...args) => import('node-fetch').then(({ default: fetch }) => fet
* Generate embed token and embed urls for reports
* @return Details like Embed URL, Access token and Expiry
*/
async function getEmbedInfo(reportsIds) {
async function getEmbedInfo(reportsIds, workspaceId) {
// Get the Report Embed details
try {
// Get report details and embed token
const embedParams = await getEmbedParamsForSelectedReports(process.env.POWER_BI_WORKSPACE_ID, reportsIds);
const workspacePBIId = workspaceId ?? process.env.POWER_BI_WORKSPACE_ID;
const embedParams = await getEmbedParamsForSelectedReports(workspacePBIId, reportsIds);
return {
accesses: {
accessToken: embedParams.embedToken.token,
Expand Down
3 changes: 2 additions & 1 deletion api/GetEmbedInfo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ module.exports = async function (context, req) {
};
} else {
const reportsIds = req?.body?.reports;
const result = await embedToken.getEmbedInfo(reportsIds);
const workspaceId = req?.body?.workspaceId;
const result = await embedToken.getEmbedInfo(reportsIds, workspaceId);
context.res = { status: 200, body: result };
}
}
Expand Down
11 changes: 0 additions & 11 deletions api/GetEmbedInfo/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,6 @@ function validateConfig() {
);
}

if (!process.env.POWER_BI_WORKSPACE_ID) {
return 'WorkspaceId is empty. Please select a group you own and fill its Id in the environment variables.';
}

if (!guid.isGuid(process.env.POWER_BI_WORKSPACE_ID)) {
return (
'WorkspaceId must be a Guid object. Please select a workspace you own and fill its Id in the environment ' +
'variables.'
);
}

if (!process.env.POWER_BI_CLIENT_SECRET || !process.env.POWER_BI_CLIENT_SECRET.trim()) {
return 'ClientSecret is empty. Please fill Power BI ServicePrincipal ClientSecret in the environment variables.';
}
Expand Down
5 changes: 0 additions & 5 deletions doc/powerBI.md
Original file line number Diff line number Diff line change
Expand Up @@ -632,15 +632,11 @@ below:
| ------------------------ | ------------------------------------------------------------------------------------- |
| `POWER_BI_SCOPE` | "https://analysis.windows.net/powerbi/api/.default" |
| `POWER_BI_CLIENT_ID` | client id of the webapp app registration (visible in the _Overview_ blade) |
| `POWER_BI_WORKSPACE_ID` | id of the Power BI workspace containing your reports |
| `POWER_BI_AUTHORITY_URI` | "https://login.microsoftonline.com/common/v2.0" |
| `POWER_BI_CLIENT_SECRET` | a client secret generated in your app registration for PowerBI |
| `POWER_BI_TENANT_ID` | tenant id of your app registration (visible in the _Overview_ blade) |
| `CSM_API_TOKEN_AUDIENCE` | (optional) if defined, queries whose token don't match this audience will be rejected |

The value for `POWER_BI_WORKSPACE_ID` can be found in the PowerBI service URL: when your report is opened, the workspace
id is visible after `/groups/` in the URL (e.g. "https://app.powerbi.com/groups/YOUR_WORKSPACE_ID/").

For `POWER_BI_CLIENT_SECRET`, you can create a new client secret from
_Azure Portal_ > _App Registrations_ > _[name of your webapp app registration]_ > _Certificates & secrets_.

Expand All @@ -661,7 +657,6 @@ JSON file. Create a _**local.settings.json**_ file in the **api** folder with th
"Values": {
"POWER_BI_SCOPE": "https://analysis.windows.net/powerbi/api/.default",
"POWER_BI_CLIENT_ID": "INSERT CLIENT ID HERE",
"POWER_BI_WORKSPACE_ID": "INSERT POWER BI WORKSPACE ID HERE",
"POWER_BI_AUTHORITY_URI": "https://login.microsoftonline.com/common/v2.0",
"POWER_BI_CLIENT_SECRET": "INSERT CLIENT SECRET HERE",
"POWER_BI_TENANT_ID": "INSERT TENANT ID HERE",
Expand Down
2 changes: 1 addition & 1 deletion src/services/powerbi/PowerBIService.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const getPowerBIDataWithServiceAccount = async (powerBIWorkspaceId, reportsIds)
const { headers } = await getAuthenticationInfo(COSMOTECH_API_SCOPE);
const { data } = await clientApi.post(
GET_EMBED_INFO_URL,
{ reports: reportsIds },
{ reports: reportsIds, workspaceId: powerBIWorkspaceId },
{ headers: { 'csm-authorization': headers.Authorization } }
);
return {
Expand Down

0 comments on commit 7c9927e

Please sign in to comment.