Skip to content
This repository has been archived by the owner on Dec 22, 2020. It is now read-only.

Commit

Permalink
Update to V1 APIs and Add RLS Support (#15)
Browse files Browse the repository at this point in the history
* Update CLI to use AppKey

* Updating Create-Token to Create-Embed-Token

* Bump version and update dependency

* Add support for generating RLS embed tokens

* Update Readme

* Update version dependencies
  • Loading branch information
aluong authored Jul 8, 2016
1 parent 5f4ca0d commit 94076b1
Show file tree
Hide file tree
Showing 15 changed files with 70 additions and 95 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"name": "Launch",
"type": "node",
"request": "launch",
"program": "${workspaceRoot}\\bin\\cli-create-token",
"program": "${workspaceRoot}\\bin\\cli-create-embed-token",
"stopOnEntry": false,
"args": [
],
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,4 @@ Updates connection strings and/or credentials for an existing dataset
#### create-token
Creates a Power BI app token

`powerbi create-token -t <tokenType> -c <collection> -k <accessKey> -w [workspaceId] -r [reportId]`
`powerbi create-token -t <tokenType> -c <collection> -k <accessKey> -w <workspaceId> -r <reportId> -u [username] --roles [roles1,roles2,...]`
2 changes: 2 additions & 0 deletions bin/cli-create-embed-token
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env node
require('../lib/cli-create-embed-token.js').default();
2 changes: 0 additions & 2 deletions bin/cli-create-token

This file was deleted.

54 changes: 54 additions & 0 deletions lib/cli-create-embed-token.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import * as powerbi from 'powerbi-api';
import * as msrest from 'ms-rest';
import {Cli as cli} from './cli';
import {Config as config} from './config';
import * as program from 'commander';

export default function CliCreateEmbedToken() {
let pkg = require('../package.json');

function list(val) {
return val.split(',');
}

program.version(pkg.version)
.option('-c, --collection <collection>', 'The Power BI workspace collection')
.option('-k, --accessKey <accessKey>', 'The Power BI workspace collection access key')
.option('-w, --workspace <workspaceId>', 'The Power BI workspace id')
.option('-r, --report <reportId>', 'The Power BI report id')
.option('-u, --username [username]', 'The RLS username')
.option('--roles [roles]', 'The RLS roles', list);

program.on('--help', function () {
console.log(' Examples:');
console.log('');
console.log(' $ powerbi create-embed-token -c <collection>, -w <workspace> -r <reportId> -k <accessKey> -u [username] --roles [roles1,roles2,...]');
});

program.parse(process.argv);

let settings = config.merge(program);

if (!(settings.collection && settings.accessKey)) {
program.help();
} else {
try {
let token: powerbi.PowerBIToken = null;

if (!settings.accessKey) {
return cli.error('Access key param is required');
}

if (!(settings.collection && settings.workspace && settings.report)) {
return cli.error('collection, workspace and report params are required');
}
token = powerbi.PowerBIToken.createReportEmbedToken(settings.collection, settings.workspace, settings.report, settings.username, settings.roles);

let jwt = token.generate(settings.accessKey);
cli.success('Embed Token: ', jwt);

} catch (err) {
cli.error(err);
}
}
}
72 changes: 0 additions & 72 deletions lib/cli-create-token.ts

This file was deleted.

3 changes: 1 addition & 2 deletions lib/cli-create-workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ export default function CliCreateWorkspace() {
program.help();
} else {
try {
let token = powerbi.PowerBIToken.createProvisionToken(settings.collection);
let credentials = new msrest.TokenCredentials(token.generate(settings.accessKey), 'AppToken');
let credentials = new msrest.TokenCredentials(settings.accessKey, 'AppKey');
let client = new powerbi.PowerBIClient(credentials, settings.baseUri, null);

client.workspaces.postWorkspace(settings.collection, (err, result) => {
Expand Down
3 changes: 1 addition & 2 deletions lib/cli-delete-dataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ export default function CliDeleteDataset() {
program.help();
} else {
try {
let token = powerbi.PowerBIToken.createDevToken(settings.collection, settings.workspace);
let credentials = new msrest.TokenCredentials(token.generate(settings.accessKey), 'AppToken');
let credentials = new msrest.TokenCredentials(settings.accessKey, 'AppKey');
let client = new powerbi.PowerBIClient(credentials, settings.baseUri, null);

client.datasets.deleteDatasetById(settings.collection, settings.workspace, settings.dataset, (err, result) => {
Expand Down
3 changes: 1 addition & 2 deletions lib/cli-get-datasets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ export default function CliGetDatasets() {
program.help();
} else {
try {
let token = powerbi.PowerBIToken.createDevToken(settings.collection, settings.workspace);
let credentials = new msrest.TokenCredentials(token.generate(settings.accessKey), 'AppToken');
let credentials = new msrest.TokenCredentials(settings.accessKey, 'AppKey');
let client = new powerbi.PowerBIClient(credentials, settings.baseUri, null);

client.datasets.getDatasets(settings.collection, settings.workspace, (err, result) => {
Expand Down
3 changes: 1 addition & 2 deletions lib/cli-get-reports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ export default function CliGetReports() {
program.help();
} else {
try {
let token = powerbi.PowerBIToken.createDevToken(settings.collection, settings.workspace);
let credentials = new msrest.TokenCredentials(token.generate(settings.accessKey), 'AppToken');
let credentials = new msrest.TokenCredentials(settings.accessKey, 'AppKey');
let client = new powerbi.PowerBIClient(credentials, settings.baseUri, null);

client.reports.getReports(settings.collection, settings.workspace, (err, result) => {
Expand Down
3 changes: 1 addition & 2 deletions lib/cli-get-workspaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ export default function CliGetWorkspaces() {
program.help();
} else {
try {
let token = powerbi.PowerBIToken.createProvisionToken(settings.collection);
let credentials = new msrest.TokenCredentials(token.generate(settings.accessKey), 'AppToken');
let credentials = new msrest.TokenCredentials(settings.accessKey, 'AppKey');
let client = new powerbi.PowerBIClient(credentials, settings.baseUri, null);

client.workspaces.getWorkspacesByCollectionName(settings.collection, (err, result) => {
Expand Down
3 changes: 1 addition & 2 deletions lib/cli-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ export default function CliImport() {
} else {
try {
let options: powerbi.ImportFileOptions = {};
let token = powerbi.PowerBIToken.createDevToken(settings.collection, settings.workspace);
let credentials = new msrest.TokenCredentials(token.generate(settings.accessKey), 'AppToken');
let credentials = new msrest.TokenCredentials(settings.accessKey, 'AppKey');
let client = new powerbi.PowerBIClient(credentials, settings.baseUri, null);

if (!_.isUndefined(settings.overwrite) && settings.overwrite) {
Expand Down
3 changes: 1 addition & 2 deletions lib/cli-update-connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ export default function CliUpdateConnection() {
program.help();
} else {
try {
let token = powerbi.PowerBIToken.createDevToken(settings.collection, settings.workspace);
let credentials = new msrest.TokenCredentials(token.generate(settings.accessKey), 'AppToken');
let credentials = new msrest.TokenCredentials(settings.accessKey, 'AppKey');
let client = new powerbi.PowerBIClient(credentials, settings.baseUri, null);

client.datasets.getDatasetById(settings.collection, settings.workspace, settings.dataset, (err, result) => {
Expand Down
6 changes: 3 additions & 3 deletions lib/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import CliGetDatasets from './cli-get-datasets';
import CliGetReports from './cli-get-reports';
import CliUpdateConnection from './cli-update-connection';
import CliDeleteDataset from './cli-delete-dataset';
import CliCreateToken from './cli-create-token';
import CliCreateEmbedToken from './cli-create-embed-token';
import * as program from 'commander';

export module Main {
Expand All @@ -22,8 +22,8 @@ export module Main {
.command('get-datasets', 'Gets a list of datasets within a workspace')
.command('get-reports', 'Gets a list of reports within a workspace')
.command('update-connection', 'Update the connection string for a datasource')
.command('delete-dataset', 'Deletes a dataset from a workspace')
.command('create-token', 'Creates a Power BI app token');
.command('delete-dataset', 'Deletes a dataset from a workspace')
.command('create-embed-token', 'Creates a Power BI embed token');

program.on('--help', function () {
console.log('See help on sub commands');
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "powerbi-cli",
"version": "0.1.5",
"version": "1.0.0",
"main": "./index.js",
"typings": "./index.d.ts",
"scripts": {
Expand All @@ -20,7 +20,7 @@
"commander": "^2.9.0",
"lodash": "^4.11.1",
"ms-rest": "^1.12.0",
"powerbi-api": "^0.1.3"
"powerbi-api": "^1.0.0"
},
"devDependencies": {},
"repository": {
Expand Down

0 comments on commit 94076b1

Please sign in to comment.