本文整理汇总了TypeScript中powerbi-api.PowerBIToken.createProvisionToken方法的典型用法代码示例。如果您正苦于以下问题:TypeScript PowerBIToken.createProvisionToken方法的具体用法?TypeScript PowerBIToken.createProvisionToken怎么用?TypeScript PowerBIToken.createProvisionToken使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类powerbi-api.PowerBIToken
的用法示例。
在下文中一共展示了PowerBIToken.createProvisionToken方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: CliGetWorkspaces
export default function CliGetWorkspaces() {
let err;
let program = require('commander');
let colors = require('colors');
let pkg = require('../package.json');
let util = require('util');
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('-b --baseUri [baseUri]', 'The base uri to connect to');
program.on('--help', function () {
console.log(' Examples:');
console.log('');
console.log(' $ powerbi get-workspaces -c <collection> -k <accessKey>');
});
program.parse(process.argv);
let settings = config.merge(program);
if (!(settings.collection && settings.accessKey)) {
program.help();
} else {
try {
let token = powerbi.PowerBIToken.createProvisionToken(settings.collection);
let credentials = new msrest.TokenCredentials(token.generate(settings.accessKey), 'AppToken');
let client = new powerbi.PowerBIClient(credentials, settings.baseUri, null);
client.workspaces.getWorkspacesByCollectionName(settings.collection, (err, result) => {
if (err) {
return cli.error(err);
}
let workspaces = result.value;
if (workspaces.length == 0) {
return cli.warn('No workspaces found within collection: %s', settings.collection);
}
cli.print("================================================");
cli.print('Gettings workspaces for Collection: %s', settings.collection);
cli.print("================================================");
result.value.forEach(workspace => {
cli.print(workspace.workspaceId);
});
});
} catch (_error) {
err = _error;
cli.error(err);
}
}
}
示例2: CliCreateWorkspace
export default function CliCreateWorkspace() {
let err;
let program = require('commander');
let colors = require('colors');
let pkg = require('../package.json');
let util = require('util');
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('-b --baseUri [baseUri]', 'The base uri to connect to');
program.on('--help', function () {
console.log(' Examples:');
console.log('');
console.log(' $ powerbi create-workspace -c <collection> -k <accessKey>');
});
program.parse(process.argv);
let settings = config.merge(program);
if (!(settings.collection && settings.accessKey)) {
program.help();
} else {
try {
let token = powerbi.PowerBIToken.createProvisionToken(settings.collection);
let credentials = new msrest.TokenCredentials(token.generate(settings.accessKey), 'AppToken');
let client = new powerbi.PowerBIClient(credentials, settings.baseUri, null);
client.workspaces.postWorkspace(settings.collection, (err, result) => {
if (err) {
return cli.error(err);
}
cli.print('Workspace created: %s', result.workspaceId);
});
} catch (err) {
cli.error(err);
}
}
}
示例3: CliCreateToken
export default function CliCreateToken() {
let err;
let program = require('commander');
let colors = require('colors');
let pkg = require('../package.json');
let util = require('util');
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('-t, --tokenType <tokenType>', 'The type of token to generate')
.option('-w, --workspace [workspaceId]', 'The Power BI workspace id')
.option('-r, --report [reportId]', 'The Power BI report id');
program.on('--help', function () {
console.log(' Examples:');
console.log('');
console.log(' $ powerbi create-token -c <collection>, -w <workspace> -r <report> -k <accessKey>');
});
program.parse(process.argv);
let settings = config.merge(program);
if (!(settings.collection && settings.accessKey)) {
program.help();
} else {
try {
let tokenType: string = null;
let token: powerbi.PowerBIToken = null;
if (!settings.tokenType) {
return cli.error('tokenType param is required');
}
if (!settings.accessKey) {
return cli.error('Access key param is required');
}
switch (settings.tokenType.toLowerCase()) {
case 'embed':
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);
break;
case 'dev':
if (!(settings.collection && settings.workspace)) {
return cli.error('collection & workspace params are required');
}
token = powerbi.PowerBIToken.createDevToken(settings.collection, settings.workspace);
break;
case 'provision':
if (!(settings.collection && settings.workspace)) {
return cli.error('collection param is required');
}
token = powerbi.PowerBIToken.createProvisionToken(settings.collection);
break;
default:
return cli.error('Unknown tokenType specified. Options: provision, dev, embed');
}
let jwt = token.generate(settings.accessKey);
cli.success('%s: ', settings.tokenType, jwt);
} catch (err) {
cli.error(err);
}
}
}