How to use ms-rest-azure - 10 common examples

To help you get started, we’ve selected a few ms-rest-azure examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Azure-Samples / cognitive-services-node-sdk-samples / Samples / computerVision.js View on Github external
// Add your Computer Vision endpoint and subscription key to your environment variables.
let keyVar = 'COMPUTER_VISION_SUBSCRIPTION_KEY';
let endpoint = process.env['COMPUTER_VISION_ENDPOINT']

if (!process.env[keyVar]) {
  throw new Error('Please set/export the following environment variable: ' + keyVar);
}

let serviceKey = process.env[keyVar];


///////////////////////////////////////////
//     Entrypoint for sample script      //
///////////////////////////////////////////

let credentials = new CognitiveServicesCredentials(serviceKey);
let computerVisionApiClient = new Vision.ComputerVisionAPIClient(credentials, endpoint);
let cvModels = computerVisionApiClient.models;

function sample() {
  async.series([
    async function () {
      console.log("1. This will analyze a house image and describe it.");
      let fileStream = fs.createReadStream('Data/house.jpg');

      let result = await computerVisionApiClient.analyzeImageInStream(fileStream, {
        visualFeatures: ["Categories", "Tags", "Description", "Color", "Faces", "ImageType"]
      });

      // Description Results
      if (((result.description || {}).captions || {}).length > 0){
        console.log(`The image can be described as: ${result.description.captions[0].text}`);
github Azure-Samples / cognitive-services-node-sdk-samples / Samples / imageSearch.js View on Github external
const CognitiveServicesCredentials = require('ms-rest-azure').CognitiveServicesCredentials;

let keyVar = 'AZURE_IMAGE_SEARCH_KEY';

if (!process.env[keyVar]) {
  throw new Error('please set/export the following environment variable: ' + keyVar);
}

let serviceKey = process.env[keyVar];


///////////////////////////////////////////
//     Entrypoint for sample script      //
///////////////////////////////////////////

let credentials = new CognitiveServicesCredentials(serviceKey);
let imageSearchApiClient = new Search.ImageSearchAPIClient(credentials);

function sample() {
  async.series([
    async function () {
      console.log("1. This will search images for (canadian rockies) then verify number of results and print out first image result, pivot suggestion, and query expansion");

      let imageResults = await imageSearchApiClient.imagesOperations.search("canadian rockies");
      console.log("Search images for query \"canadian rockies\"");

      if (imageResults == null) {
        console.log("No image result data.");
      }
      else {
        // Image results
        if (imageResults.value.length > 0) {
github Azure-Samples / cognitive-services-node-sdk-samples / Samples / visualSearch.js View on Github external
const CognitiveServicesCredentials = require('ms-rest-azure').CognitiveServicesCredentials;

// Add your Bing Search V7 subscription key to your environment variables.
let keyVar = process.env['BING_SEARCH_V7_SUBSCRIPTION_KEY']

if (!process.env[keyVar]) {
  throw new Error('please set/export the following environment variable: ' + keyVar);
}

let serviceKey = process.env[keyVar];

///////////////////////////////////////////
//     Entrypoint for sample script      //
///////////////////////////////////////////

let credentials = new CognitiveServicesCredentials(serviceKey);
let visualSearchApiClient = new Search.VisualSearchAPIClient(credentials);
let visualModels = visualSearchApiClient.models;

function sample() {
  async.series([
    async function () {
      let fileStream = fs.createReadStream('Data/image.jpg');
      let visualSearchRequest = JSON.stringify({});
      let visualSearchResults;
      try {
        visualSearchResults = await visualSearchApiClient.images.visualSearch({
          image: fileStream,
          knowledgeRequest: visualSearchRequest
        });
        console.log("Search visual search request with binary of dog image");
      } catch (err) {
github Azure-Samples / cognitive-services-node-sdk-samples / Samples / autoSuggest.js View on Github external
// Add your Bing Autosuggest subscription key to your environment variables.
const keyVar = process.env['BING_AUTOSUGGEST_SUBSCRIPTION_KEY']

if (!process.env[keyVar]) {
  throw new Error('please set/export the following environment variable: ' + keyVar);
}

const serviceKey = process.env[keyVar];

const query = "Satya Nadella";

///////////////////////////////////////////
//     Entrypoint for sample script      //
///////////////////////////////////////////

const credentials = new CognitiveServicesCredentials(serviceKey);
const autoSuggestApiClient = new Search.AutoSuggestAPIClient(credentials);
const autoSuggestModels = autoSuggestApiClient.models;

function sample() {
  async.series([
    async function () {
      let autoSuggestResults;
      try {
        autoSuggestResults = await autoSuggestApiClient.autoSuggest(query);
        console.log("Request autosuggestions for '" + query + "'");
      } catch (err) {
        console.log("Encountered exception. " + err.message);
      }
      if (!autoSuggestResults) {
        console.log("No autosuggest result data. ");
      } else {
github Azure-Samples / cognitive-services-node-sdk-samples / Samples / entitySearch.js View on Github external
const CognitiveServicesCredentials = require('ms-rest-azure').CognitiveServicesCredentials;

let keyVar = 'AZURE_ENTITY_SEARCH_KEY';

if (!process.env[keyVar]) {
  throw new Error('please set/export the following environment variable: ' + keyVar);
}

let serviceKey = process.env[keyVar];


///////////////////////////////////////////
//     Entrypoint for sample script      //
///////////////////////////////////////////

let credentials = new CognitiveServicesCredentials(serviceKey);
let entitySearchApiClient = new Search.EntitySearchAPIClient(credentials);
let entityModels = entitySearchApiClient.models;

function sample() {
  async.series([
    async function () {
      console.log("1. This will look up a single entity (Satya Nadella) and print out a short description about them.");
      let result;
      try {
        result = await entitySearchApiClient.entitiesOperations.search("Satya Nadella");
      } catch (err) {
        if (err instanceof entityModels.ErrorResponse) {
          console.log("Encountered exception. " + err.message);
        }
      }
      if (((result.entities || {}).value || {}).length > 0) {
github Azure-Samples / resource-manager-node-template-deployment / index.js View on Github external
var secret = process.env['APPLICATION_SECRET'];
var subscriptionId = process.env['AZURE_SUBSCRIPTION_ID'];
var publicSSHKeyPath = process.argv[2] || "~/.ssh/id_rsa.pub";
var resourceClient;
//Sample Config
var randomIds = {};
var location = 'eastus';
var resourceGroupName = _generateRandomId('testrg', randomIds);
var deploymentName = _generateRandomId('testdeployment', randomIds);
var dnsLabelPrefix = _generateRandomId('testdnslable', randomIds);

///////////////////////////////////////
//Entrypoint for the sample script   //
///////////////////////////////////////

msRestAzure.loginWithServicePrincipalSecret(clientId, secret, domain, function (err, credentials) {
  if (err) return console.log(err);
  resourceClient = new ResourceManagementClient(credentials, subscriptionId);
  // Work flow of this sample:
  // 1. create a resource group 
  // 2. load a VM template and deploy it.
  // 3. delete deployed resource(optional)
  // 4. delete a resource group(optional)
  
  async.series([
    function (callback) {
      //Task 1
      createResourceGroup(function (err, result, request, response) {
        if (err) {
          return callback(err);
        }
        callback(null, result);
github Azure-Samples / resource-manager-node-resources-and-groups / index.js View on Github external
//Sample Config
var randomIds = {};
var location = 'westus';
var resourceGroupName = _generateRandomId('testrg', randomIds);
var resourceName = _generateRandomId('testresource', randomIds);

var resourceProviderNamespace = 'Microsoft.KeyVault';
var parentResourcePath = '';
var resourceType = 'vaults';
var apiVersion = '2015-06-01';

///////////////////////////////////////
//Entrypoint for the sample script   //
///////////////////////////////////////

msRestAzure.loginWithServicePrincipalSecret(clientId, secret, domain, function (err, credentials) {
  if (err) return console.log(err);
  resourceClient = new ResourceManagementClient(credentials, subscriptionId);
  // Work flow of this sample:
  // 1. create a resource group 
  // 2. list resource groups
  // 3. update a resource group
  // 4. create a key vault resource in the resource group
  // 5. get details for a given resource
  // 6. export the resource group template
  // 7. delete a resource(optional)
  // 8. delete a resource group(optional)
  
  async.series([
    function (callback) {
      //Task 1
      createResourceGroup(function (err, result, request, response) {
github Azure / autorest / src / generator / AutoRest.NodeJS.Azure.Tests / AcceptanceTests / azureSpecialProperties.js View on Github external
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

'use strict';

var should = require('should');
var http = require('http');
var assert = require('assert');
var msRestAzure = require('ms-rest-azure');

var specialsClient = require('../Expected/AcceptanceTests/AzureSpecials/autoRestAzureSpecialParametersTestClient');
var dummySubscriptionId = '1234-5678-9012-3456';
var dummyToken = 'dummy12321343423';
var credentials = new msRestAzure.TokenCredentials(dummyToken);

var clientOptions = {};
var baseUri = 'http://localhost:3000';

describe('nodejs', function () {

  describe('Azure Special Properties', function () {
    var testClient = new specialsClient(credentials, dummySubscriptionId, baseUri, clientOptions);
    it('should use the default api-version when no api-version parameter is present', function (done) {
      testClient.apiVersionDefault.getMethodGlobalValid(function (error, result, request, response) {
        should.not.exist(error);
        response.statusCode.should.equal(200);
        testClient.apiVersionDefault.getMethodGlobalNotProvidedValid(function (error, result, request, response) {
          should.not.exist(error);
          response.statusCode.should.equal(200);
          testClient.apiVersionDefault.getPathGlobalValid(function (error, result, request, response) {
github Azure / azure-sdk-for-java / AutoRest / Generators / NodeJS / Azure.NodeJS.Tests / AcceptanceTests / azureSpecialProperties.js View on Github external
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

'use strict';

var should = require('should');
var http = require('http');
var util = require('util');
var assert = require('assert');
var msRestAzure = require('ms-rest-azure');

var specialsClient = require('../Expected/AcceptanceTests/AzureSpecials/autoRestAzureSpecialParametersTestClient');
var dummySubscriptionId = '1234-5678-9012-3456';
var dummyToken = 'dummy12321343423';
var credentials = new msRestAzure.TokenCredentials(dummyToken);

var clientOptions = {};
var baseUri = 'http://localhost:3000';

describe('nodejs', function () {

  describe('Azure Special Properties', function () {
    var testClient = new specialsClient(credentials, dummySubscriptionId, baseUri, clientOptions);
    it('should use the default api-version when no api-version parameter is present', function (done) {
      testClient.apiVersionDefault.getMethodGlobalValid(function (error, result, request, response) {
        should.not.exist(error);
        response.statusCode.should.equal(200);
        testClient.apiVersionDefault.getMethodGlobalNotProvidedValid(function (error, result, request, response) {
          should.not.exist(error);
          response.statusCode.should.equal(200);
          testClient.apiVersionDefault.getPathGlobalValid(function (error, result, request, response) {
github Azure / autorest / src / generator / AutoRest.NodeJS.Azure.Tests / AcceptanceTests / subscriptionIdApiVersion.js View on Github external
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

'use strict';

var should = require('should');
var http = require('http');
var assert = require('assert');
var msRestAzure = require('ms-rest-azure');

var azureUrlClient = require('../Expected/AcceptanceTests/SubscriptionIdApiVersion/microsoftAzureTestUrl');
var dummySubscriptionId = 'a878ae02-6106-429z-9397-58091ee45g98';
var dummyToken = 'dummy12321343423';
var credentials = new msRestAzure.TokenCredentials(dummyToken);

var clientOptions = {};
var baseUri = 'http://localhost:3000';

describe('nodejs', function () {

  describe('Azure Swagger Url', function () {
    var testClient = new azureUrlClient(credentials, dummySubscriptionId, baseUri, clientOptions);

    it('should correctly send the subscriptionId as path parameter and api-version ' +
      'as a query parameter in the request url', function (done) {
      testClient.group.getSampleResourceGroup('testgroup101', function (error, result, request, response) {
        should.not.exist(error);
        response.statusCode.should.equal(200);
        done();
      });