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


TypeScript powerbi-api.PowerBIToken類代碼示例

本文整理匯總了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;未經允許,請勿轉載。