本文整理汇总了TypeScript中powerbi-api.PowerBIToken类的典型用法代码示例。如果您正苦于以下问题:TypeScript PowerBIToken类的具体用法?TypeScript PowerBIToken怎么用?TypeScript PowerBIToken使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PowerBIToken类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: CliCreateEmbedToken
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('-d, --dataset <datasetId>', 'The Power BI dataset id')
.option('-s, --scopes [scopes]', 'The permission scopes allowed')
.option('-u, --username [username]', 'The RLS username')
.option('--roles [roles]', 'The RLS roles', list)
.option('-e, --expiration <expiration>', 'The token expiration date');
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,...]');
console.log(' $ powerbi create-embed-token -c <collection>, -w <workspace> -r <reportId> -k <accessKey> -s [scopes]');
console.log(' $ powerbi create-embed-token -c <collection>, -w <workspace> -d <datasetId> -k <accessKey> -s [scopes]');
console.log(' Create report in embedded view needs the following scopes: "Dataset.Read Workspace.Report.Create"');
});
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)) {
return cli.error('collection and workspace params are required');
}
if (!(settings.report || settings.dataset)) {
return cli.error('Either reportId or datasetId must be set');
}
let expiration = settings.expiration ? new Date(settings.expiration) : void 0;
token = powerbi.PowerBIToken.createReportEmbedToken(settings.collection, settings.workspace, settings.report, settings.dataset, settings.scopes, settings.username, settings.roles, expiration);
let jwt = token.generate(settings.accessKey);
cli.success('Embed Token: ', jwt);
} catch (err) {
cli.error(err);
}
}
}
开发者ID:Microsoft,项目名称:PowerBI-Cli,代码行数:59,代码来源:cli-create-embed-token.ts
示例2: 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);
}
}
}
开发者ID:llenroc,项目名称:PowerBI-Cli,代码行数:55,代码来源:cli-get-reports.ts
示例3: 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);
}
}
}
开发者ID:llenroc,项目名称:PowerBI-Cli,代码行数:54,代码来源:cli-get-workspaces.ts
示例4: 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);
}
}
}
开发者ID:llenroc,项目名称:PowerBI-Cli,代码行数:44,代码来源:cli-delete-dataset.ts
示例5: 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);
}
}
}
开发者ID:llenroc,项目名称:PowerBI-Cli,代码行数:42,代码来源:cli-create-workspace.ts
示例6: 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);
}
});
}
}
开发者ID:llenroc,项目名称:PowerBI-Cli,代码行数:87,代码来源:cli-import.ts
示例7: 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);
//.........这里部分代码省略.........
开发者ID:llenroc,项目名称:PowerBI-Cli,代码行数:101,代码来源:cli-update-connection.ts
示例8: 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);
}
}
}
开发者ID:llenroc,项目名称:PowerBI-Cli,代码行数:70,代码来源:cli-create-token.ts
注:本文中的powerbi-api.PowerBIToken类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论