How to use azure.loginWithServicePrincipalSecret method in qawolf

Best JavaScript code snippet using qawolf

aci-runner.js

Source:aci-runner.js Github

copy

Full Screen

1(function() {2var msRestAzure = require('ms-rest-azure');3var resourceManagementClient = require('azure-arm-resource');4var containerInstanceManagementClient = require('azure-arm-containerinstance');5var localOptions = null;6function deleteContainer(aciClient, name) {7 aciClient.containerGroups.deleteMethod(localOptions.resourceGroup, name)8 .then(cg => {9 console.log(`Deleted container group ${name}`);10 })11 .catch(err => {12 console.log(`Failed to deleted container group ${name}`);13 });14}15function getContainerLogs(aciClient, name) {16 aciClient.containerLogs.list(localOptions.resourceGroup, name, name)17 .then(log => {18 console.log('===== Tail logs start =====');19 console.log(log.content);20 console.log('===== Tail logs end =====');21 })22 .catch(err => {23 console.log(`Failed to fetch log for container group ${name}; logs might not be ready yet.`);24 })25}26function createContainer(rgClient, aciClient, img, name, options) {27 rgClient.resourceGroups.get(options.resourceGroup)28 .then(resourceGroup => {29 let ipAddress = null;30 let ports = null;31 if (options && options.public) {32 ipAddress = {33 type: 'Public'34 };35 if (options.ports) {36 ports = options.ports.map((p) => {37 return {port: p, protocol: 'TCP'};38 });39 ipAddress.ports = ports;40 }41 }42 let containerGroup = {43 name: name,44 location: resourceGroup.location,45 osType: 'Linux',46 restartPolicy: 'Never',47 ipAddress: ipAddress,48 containers: [{49 name: name,50 image: img,51 resources: {requests: {memoryInGB: 1.5, cpu: 1.0}},52 environmentVariables:53 [{name: 'METAPARTICLE_IN_CONTAINER', value: 'true'}],54 ports: ports55 }]56 };57 aciClient.containerGroups58 .createOrUpdate(options.resourceGroup, name, containerGroup)59 .then(cg => {60 console.log(`Created container group with id ${cg.id}`);61 setInterval(() => {62 getContainerLogs(aciClient, name);63 }, 5000);64 })65 .catch(err => {66 console.log(`Failed to create container group: ${err.message}`);67 });68 })69 .catch(err => {70 console.log(`Failed to get resource group ${options.resourceGroup}: ${err.message}`);71 })72}73module.exports.run = (img, name, options) => {74 localOptions = options;75 msRestAzure76 .loginWithServicePrincipalSecret(77 options.clientId, options.clientSecret, options.tenantId)78 .then(credential => {79 const rgClient = new resourceManagementClient.ResourceManagementClient(80 credential, options.subscriptionId);81 const aciClient = new containerInstanceManagementClient(82 credential, options.subscriptionId);83 createContainer(rgClient, aciClient, img, name, options);84 })85 .catch(err => {86 console.log(`Failed to authenticate: ${err.message}`);87 });88};89module.exports.cancel = (name) => {90 msRestAzure91 .loginWithServicePrincipalSecret(92 localOptions.clientId, localOptions.clientSecret, localOptions.tenantId)93 .then(credential => {94 const aciClient = new containerInstanceManagementClient(95 credential, localOptions.subscriptionId);96 deleteContainer(aciClient, name);97 })98 .catch(err => {99 console.log(`Failed to authenticate: ${err.message}`);100 });101};...

Full Screen

Full Screen

azure-api.js

Source:azure-api.js Github

copy

Full Screen

1"use strict";2const azure_creds = require("./azure_creds.json")3const msRestAzure = require("@azure/ms-rest-nodeauth");4const { ComputeManagementClient } = require("@azure/arm-compute");5const { StorageManagementClient } = require("@azure/arm-storage");6const { NetworkManagementClient } = require("@azure/arm-network");7const { ResourceManagementClient } = require("@azure/arm-resources");8const clientID = azure_creds.CLIENT_ID;9const tenantID = azure_creds.TENANT_ID;10const subscriptionID = azure_creds.SUBSCRIPTION_ID;11const secret = azure_creds.APPLICATION_SECRET;12// resourceClient = new ResourceManagementClient(credentials, subscriptionID);13// computeClient = new ComputeManagementClient(credentials, subscriptionID);14// storageClient = new StorageManagementClient(credentials, subscriptionID);15// networkClient = new NetworkManagementClient(credentials, subscriptionID);16function subnetName() {17 return "Subnet-001"; // hardcoded here for now because too lazy18}19module.exports.showVM = async(vmName, resourceGroupName) => {20 21 const credentials = await msRestAzure.loginWithServicePrincipalSecret(clientID, secret, tenantID);22 const computeClient = new ComputeManagementClient(credentials, subscriptionID);23 return await computeClient.virtualMachines.get(resourceGroupName, vmName);24};25module.exports.listVMs = async () => {26 27 const credentials = await msRestAzure.loginWithServicePrincipalSecret(clientID, secret, tenantID);28 const computeClient = new ComputeManagementClient(credentials, subscriptionID);29 return await computeClient.virtualMachines.listAll();30 31};32module.exports.createRG = async(name, location, tags) => {33 const params = { location: location, tags: tags};34 const credentials = await msRestAzure.loginWithServicePrincipalSecret(clientID, secret, tenantID);35 const resourceClient = new ResourceManagementClient(credentials, subscriptionID);36 return await resourceClient.resourceGroups.createOrUpdate(name, params);37 38};39module.exports.deleteRG = async(name) => {40 // const response = https://management.azure.com/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}?api-version=2021-04-0141 const credentials = await msRestAzure.loginWithServicePrincipalSecret(clientID, secret, tenantID);42 const resourceClient = new ResourceManagementClient(credentials, subscriptionID);43 return await resourceClient.resourceGroups.beginDeleteMethod(name);44}45module.exports.createVNET = async(resourceGroup, name, params) => {46 const par = params!==null ? params : {47 location: location,48 addressSpace: {49 addressPrefixes: ['10.0.0.0/16']50 },51 dhcpOptions: {52 dnsServers: ['10.1.1.1', '10.1.2.4']53 },54 subnets: [{ name: subnetName(), addressPrefix: '10.0.0.0/24' }],55 };56 const credentials = msRestAzure.loginWithServicePrincipalSecret(clientID, secret, tenantID);57 const computeClient = new ComputeManagementClient(credentials, subscriptionID);58 return await computeClient.virtualNetworks.createOrUpdate(resourceGroup, name, par);59 ...

Full Screen

Full Screen

azure.js

Source:azure.js Github

copy

Full Screen

...26 * @param {*} server The server to start.27 * @returns {Promise} A promise that resolves when the server has been started.28 */29 static async start(server) {30 const credentials = await azure.loginWithServicePrincipalSecret(settings.clientId, settings.secret, settings.domain),31 client = new Compute(credentials, settings.subscriptionId);32 return client.virtualMachines.start(server.resourceGroupName, server.vmName);33 }34 // #35 // #36 // ### ### ## ###37 // ## # # # # #38 // ## # # # # #39 // ### ## ## ###40 // #41 /**42 * Stops an Azure VM.43 * @param {*} server The server to stop.44 * @returns {Promise} A promise that resolves when the server has been stopped.45 */46 static async stop(server) {47 const credentials = await azure.loginWithServicePrincipalSecret(settings.clientId, settings.secret, settings.domain),48 client = new Compute(credentials, settings.subscriptionId);49 return client.virtualMachines.deallocate(server.resourceGroupName, server.vmName);50 }51}...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { loginWithServicePrincipalSecret } = require("@azure/ms-rest-nodeauth");2const { ResourceManagementClient } = require("@azure/arm-resources");3const { SubscriptionClient } = require("@azure/arm-subscriptions");4const subscriptionId = process.env.AZURE_SUBSCRIPTION_ID;5const client_id = process.env.AZURE_CLIENT_ID;6const tenant_id = process.env.AZURE_TENANT_ID;7const secret = process.env.AZURE_SECRET;8const resourceGroupName = "myResourceGroup";9const accountName = "myaccount";10async function main() {11 const credentials = await loginWithServicePrincipalSecret(12 );13 const client = new ResourceManagementClient(credentials, subscriptionId);14 const subscriptionClient = new SubscriptionClient(credentials);15 const subscription = await subscriptionClient.subscriptions.get(16 );17 console.log("Subscription: ", subscription);18 const resourceGroup = await client.resourceGroups.get(resourceGroupName);19 console.log("Resource Group: ", resourceGroup);20 const account = await client.resources.get(21 );22 console.log("Storage Account: ", account);23}24main()25 .then(() => {26 console.log("Done");27 })28 .catch((err) => {29 console.error("The script failed with an error:", err);30 });

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run qawolf automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful