Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
constructor(application: LuisApplication, options?: LuisPredictionOptions, includeApiResults?: boolean) {
this.application = application;
this.options = {
includeAllIntents: false,
includeInstanceData: true,
log: true,
spellCheck: false,
staging: false, ...options
};
this.includeApiResults = !!includeApiResults;
// Create client
const creds: msRest.TokenCredentials = new msRest.TokenCredentials(application.endpointKey);
const baseUri: string = this.application.endpoint || 'https://westus.api.cognitive.microsoft.com';
this.luisClient = new LuisClient(creds, baseUri);
}
_setCredentials: function() {
if (!this.isPlayback) {
if (process.env['SKIP_CREDENTIAL_CHECK']) {
let token = process.env['AZURE_ACCESS_TOKEN'] || 'token';
this.credentials = new msRest.TokenCredentials('token');
} else if ((process.env['AZURE_PASSWORD'] && process.env['APPLICATION_SECRET']) ||
(!process.env['AZURE_PASSWORD'] && !process.env['APPLICATION_SECRET'])) {
throw new Error('You must either set the envt. variables \'AZURE_USERNAME\' ' +
'and \'AZURE_PASSWORD\' for running tests as a user or set the ' +
'envt. variable \'CLIENT_ID\' and \'APPLICATION_SECRET\' ' +
'for running tests as a service-principal, but not both.');
}
if (process.env['AZURE_PASSWORD']) {
this.credentials = this._createUserCredentials();
} else if (process.env['APPLICATION_SECRET']) {
this.credentials = this._createApplicationCredentials();
}
} else {
//The type of credential object does not matter in playback mode as authentication
//header is not recorded. Hence we always default to UsertokenCredentials.
var verifyAadAuth = function(token, callback) {
var tokenCreds = new msRest.TokenCredentials(token, 'Bearer');
aadClient = new BatchServiceClient(tokenCreds, process.env['AZURE_BATCH_ENDPOINT']);
aadClient.account.listSupportedImages(function (err, result, request, response) {
should.not.exist(err);
should.exist(result);
result.length.should.be.above(0);
response.statusCode.should.equal(200);
should.exist(request.headers.authorization);
request.headers.authorization.should.equal('Bearer ' + token);
callback();
});
};
program.on('--help', function () {
console.log(' Examples:');
console.log('');
console.log(' $ powerbi create-workspace -c -k -n ');
});
program.parse(process.argv);
let settings = config.merge(program);
if (!(settings.collection && settings.accessKey)) {
program.help();
} else {
try {
let credentials = new msrest.TokenCredentials(settings.accessKey, 'AppKey');
let client = new powerbi.PowerBIClient(credentials, settings.baseUri, null);
let workspaceRequest : powerbi.CreateWorkspaceRequest = {
name: settings.newName,
};
let options = { workspaceRequest }
client.workspaces.postWorkspace(settings.collection, options, (err, result) => {
if (err) {
return cli.error(err);
}
cli.print('Workspace created: %s', result.workspaceId);
});
} catch (err) {
cli.error(err);
}
'use strict';
import should = require('should');
import http = require('http');
import assert = require('assert');
import * as msRest from 'ms-rest';
import fs = require('fs');
import stream = require('stream');
import validationClient = require('../Expected/AcceptanceTests/Validation/autoRestValidationTest');
var dummyToken = 'dummy12321343423';
var credentials = new msRest.TokenCredentials(dummyToken);
var clientOptions: msRest.ServiceClientOptions = {};
var baseUri = 'http://localhost:3000';
describe('nodejs', function () {
describe('Swagger BAT Validation', function () {
var testClient = new validationClient("abc123", "12-34-5678", baseUri, clientOptions);
describe('Of Method Parameters', function () {
it('should test the minimum length constraint on resourceGroupName', function (done) {
testClient.validationOfMethodParameters("1", 100, function (err, result) {
should.exist(err);
err.should.match(/.*resourceGroupName.*constraint.*MinLength.*3/ig);
done();
});
});
it('should test the maximum length constraint on resourceGroupName', function (done) {
testClient.validationOfMethodParameters("1234567890A", 100, function (err, result) {
.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 -k ');
});
program.parse(process.argv);
let settings = config.merge(program);
if (!(settings.collection && settings.accessKey)) {
program.help();
} else {
try {
let credentials = new msrest.TokenCredentials(settings.accessKey, 'AppKey');
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("================================================");
program.on('--help', function () {
console.log(' Examples:');
console.log('');
console.log(' $ powerbi import -c -k -w -f -n ');
});
program.parse(process.argv);
let settings = config.merge(program);
if (!(settings.collection && settings.workspace && settings.accessKey && settings.displayName && settings.file)) {
program.help();
} else {
try {
let options: powerbi.ImportFileOptions = {};
let credentials = new msrest.TokenCredentials(settings.accessKey, 'AppKey');
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) {
export async function functionsAdminRequest(client: SiteClient, urlPath: string): Promise {
const adminKey: string = await client.getFunctionsAdminToken();
const url: string = `${client.defaultHostUrl}/admin/${urlPath}`;
const request: requestUtils.Request = await requestUtils.getDefaultRequest(url, new TokenCredentials(adminKey));
return await requestUtils.sendRequest(request);
}
this.credentials = (this.tokens || []).reduce((credentials, token) => Object.assign(credentials, { [token._authority]: new TokenCredentials(token.accessToken) }), {});
}