本文整理汇总了TypeScript中powerbi-api.PowerBIToken.createDevToken方法的典型用法代码示例。如果您正苦于以下问题:TypeScript PowerBIToken.createDevToken方法的具体用法?TypeScript PowerBIToken.createDevToken怎么用?TypeScript PowerBIToken.createDevToken使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类powerbi-api.PowerBIToken
的用法示例。
在下文中一共展示了PowerBIToken.createDevToken方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: CliGetReports
export default function CliGetReports() {
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('-w, --workspace <workspace>', 'The Power BI workspace')
.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-reports -c <collection> -w <workspace> -k <accessKey>');
});
program.parse(process.argv);
let settings = config.merge(program);
if (!(settings.collection && settings.accessKey && settings.workspace)) {
program.help();
} else {
try {
let token = powerbi.PowerBIToken.createDevToken(settings.collection, settings.workspace);
let credentials = new msrest.TokenCredentials(token.generate(settings.accessKey), 'AppToken');
let client = new powerbi.PowerBIClient(credentials, settings.baseUri, null);
client.reports.getReports(settings.collection, settings.workspace, (err, result) => {
if (err) {
return cli.error(err);
}
let reports = result.value;
if (reports.length === 0) {
return cli.warn('No reports found within workspace: %s', settings.workspace);
}
cli.print('=========================================');
cli.print('Gettings reports for Collection: %s', settings.workspace);
cli.print('=========================================');
reports.forEach(report => {
cli.print('ID: %s | Name: %s', report.id, report.name);
});
});
} catch (err) {
cli.error(err);
}
}
}
示例2: CliDeleteDataset
export default function CliDeleteDataset() {
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('-w, --workspace <workspace>', 'The Power BI workspace')
.option('-k, --accessKey <accessKey>', 'The Power BI workspace collection access key')
.option('-d, --dataset <dataset>', 'The dataset id')
.option('-b --baseUri [baseUri]', 'The base uri to connect to');
program.on('--help', function () {
console.log(' Examples:');
console.log('');
console.log(' $ powerbi delete-dataset -c <collection> -w <workspace> -d <dataset> -k <accessKey>');
});
program.parse(process.argv);
let settings = config.merge(program);
if (!(settings.collection && settings.accessKey && settings.workspace)) {
program.help();
} else {
try {
let token = powerbi.PowerBIToken.createDevToken(settings.collection, settings.workspace);
let credentials = new msrest.TokenCredentials(token.generate(settings.accessKey), 'AppToken');
let client = new powerbi.PowerBIClient(credentials, settings.baseUri, null);
client.datasets.deleteDatasetById(settings.collection, settings.workspace, settings.dataset, (err, result) => {
if (err) {
return cli.error(err);
}
cli.success('Dataset %s deleted successfully', settings.dataset);
});
} catch (err) {
cli.error(err);
}
}
}
示例3: CliImport
export default function CliImport() {
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('-w, --workspace <workspaceId>', 'The Power BI workspace')
.option('-k, --accessKey <accessKey>', 'The Power BI workspace collection access key')
.option('-n, --displayName <displayName>', 'The dataset display name')
.option('-f, --file <file>', 'The PBIX file to upload')
.option('-o, --overwrite [overwrite]', 'Whether to overwrite a dataset with the same name. Default is false')
.option('-b --baseUri [baseUri]', 'The base uri to connect to');
program.on('--help', function () {
console.log(' Examples:');
console.log('');
console.log(' $ powerbi import -c <collection> -k <accessKey> -w <workspace> -f <file>');
});
program.parse(process.argv);
let settings = config.merge(program);
if (process.argv.length === 2) {
program.help();
} 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 client = new powerbi.PowerBIClient(credentials, settings.baseUri, null);
if (!_.isUndefined(settings.overwrite) && settings.overwrite) {
options.nameConflict = 'Overwrite';
}
options.datasetDisplayName = settings.displayName;
if (!fs.existsSync(settings.file)) {
throw new Error(util.format('File "%s" not found', settings.file));
}
cli.print('Importing %s to workspace: %s', settings.file, settings.workspace);
client.imports.uploadFile(settings.collection, settings.workspace, settings.file, options, (err, result, request, response) => {
if (err) {
return cli.error(err);
}
let importResult: powerbi.ImportModel = result;
cli.print('File uploaded successfully');
cli.print('Import ID: %s', importResult.id);
checkImportState(client, importResult, (importStateErr, importStateResult) => {
if (importStateErr) {
return cli.print(importStateErr);
}
cli.print('Import succeeded');
});
});
} catch (err) {
cli.error(err);
}
}
/**
* Checks the import state of the requested import id
*/
function checkImportState(client: powerbi.PowerBIClient, importResult: powerbi.ImportModel, callback) {
client.imports.getImportById(settings.collection, settings.workspace, importResult.id, (err, result) => {
importResult = result;
cli.print('Checking import state: %s', importResult.importState);
if (importResult.importState === 'Succeeded' || importResult.importState === 'Failed') {
callback(null, importResult);
} else {
setTimeout(() => {
checkImportState(client, importResult, callback);
}, 500);
}
});
}
}
示例4: CliUpdateConnection
export default function CliUpdateConnection() {
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('-w, --workspace <workspaceId>', 'The Power BI workspace')
.option('-k, --accessKey <accessKey>', 'The Power BI workspace collection access key')
.option('-d, --dataset <datasetId>', 'The dataset to update')
.option('-s, --connectionString [connectionString]', 'The connection string to access the datasource')
.option('-u, --username [username]', 'The username to access the datasource')
.option('-p, --password [password]', 'The password to access the datasource')
.option('-b --baseUri [baseUri]', 'The base uri to connect to');
program.on('--help', function () {
console.log(' Examples:');
console.log('');
console.log(' $ powerbi update-connection -c <collection> -k <accessKey> -w <workspace> -u [username] -p [password] -s [connectionString]');
});
program.parse(process.argv);
let settings = config.merge(program);
if (process.argv.length === 2) {
program.help();
} else {
try {
let token = powerbi.PowerBIToken.createDevToken(settings.collection, settings.workspace);
let credentials = new msrest.TokenCredentials(token.generate(settings.accessKey), 'AppToken');
let client = new powerbi.PowerBIClient(credentials, settings.baseUri, null);
client.datasets.getDatasetById(settings.collection, settings.workspace, settings.dataset, (err, result) => {
if (err) {
return cli.error(err);
}
cli.success('Found dataset!');
cli.print('Id: %s', result.id);
cli.print('Name: %s', result.name);
if (settings.connectionString) {
updateConnectionString(client, settings);
}
if (settings.username && settings.password) {
updateCredentials(client, settings)
}
});
} catch (err) {
cli.error(err);
}
}
function updateConnectionString(client: powerbi.PowerBIClient, settings: any, callback?): void {
let params: { [propertyName: string]: any } = {
connectionString: settings.connectionString
};
client.datasets.setAllConnections(settings.collection, settings.workspace, settings.dataset, params, (err, result) => {
if (err) {
cli.error('Error updating connection string');
cli.error(err);
return;
}
cli.success('Connection string successfully updated');
cli.print('Dataset: ', settings.dataset);
cli.print('ConnectionString: ', settings.connectionString);
if (callback) {
callback(null, result);
}
});
}
function updateCredentials(client: powerbi.PowerBIClient, settings: any, callback?): void {
client.datasets.getGatewayDatasources(settings.collection, settings.workspace, settings.dataset, (err, result) => {
if (err) {
return callback(err);
}
let datasources = result.value;
if (datasources.length === 0) {
return cli.warn('No datasources found within dataset: %s', settings.dataset);
}
if (datasources.length > 0) {
cli.success('Found %s Datasources for Dataset %s', datasources.length, settings.dataset);
cli.print('--------------------------------------------------------------------');
}
datasources.forEach(datasource => {
cli.print('Datesource ID: ', datasource.id);
cli.print('Gateway ID: ', datasource.gatewayId);
cli.print('Credential Type: ', datasource.credentialType);
cli.print('Datasource Type: ', datasource.datasourceType);
//.........这里部分代码省略.........
示例5: 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);
}
}
}