當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript PowerBIToken.createProvisionToken方法代碼示例

本文整理匯總了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);
        }
    }
}
開發者ID:llenroc,項目名稱:PowerBI-Cli,代碼行數:54,代碼來源:cli-get-workspaces.ts

示例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);
        }
    }
}
開發者ID:llenroc,項目名稱:PowerBI-Cli,代碼行數:42,代碼來源:cli-create-workspace.ts

示例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);
        }
    }
}
開發者ID:llenroc,項目名稱:PowerBI-Cli,代碼行數:70,代碼來源:cli-create-token.ts


注:本文中的powerbi-api.PowerBIToken.createProvisionToken方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。