How to use the @azure/ms-rest-js.ServiceClient function in @azure/ms-rest-js

To help you get started, we’ve selected a few @azure/ms-rest-js 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 / ms-rest-nodeauth / samples / getCredentialsFromAzureCli.ts View on Github external
async function listResourceGroups(creds: AzureCliCredentials): Promise {
  function getUrl(subscriptionId: string): string {
    return `https://management.azure.com/subscriptions/${subscriptionId}/resourcegroups?api-version=2018-05-01`;
  }
  try {
    console.log(">>>>>>> List Resource groups <<<<<<<<<<<");
    // Setting the resource to ARM endpoint.
    creds.resource = "https://management.azure.com";
    const client = new ServiceClient(creds);
    console.log(">>> Subscription associated with the access token: '%s'.",
      creds.tokenInfo.subscription);
    const request: RequestPrepareOptions = {
      url: getUrl(creds.subscriptionInfo.id),
      method: "GET"
    };
    console.log(">>> Request url: '%s'.", request.url);
    const res = await client.sendRequest(request);
    console.log("List of resource groups from subscriptionId '%s': \n%O",
      creds.subscriptionInfo.id, res.parsedBody);

    // Let us change the subscriptionId, which should trigger refreshing the access token.
    const subscriptions = await AzureCliCredentials.listAllSubscriptions();
    creds.subscriptionInfo = subscriptions[1];
    console.log(">>> The new subscription id associated with the credential object is: '%s'.",
      creds.subscriptionInfo.id);
github Azure / ms-rest-nodeauth / samples / getCredentialsFromAzureCli.ts View on Github external
async function listKeyVaultSecrets(creds: AzureCliCredentials): Promise {
  function getKVUrl(kvAccountName: string): string {
    return `https://${kvAccountName}.vault.azure.net/secrets?api-version=7.0`;
  }

  try {
    console.log(">>>>>>> KeyVault <<<<<<<<<<<");
    const client = new ServiceClient(creds);
    console.log(">>> Subscription associated with the access token: '%s'.",
      creds.tokenInfo.subscription);
    const request: RequestPrepareOptions = {
      url: getKVUrl(keyvaultAccountName),
      method: "GET"
    };
    console.log(">>> Request url: '%s'.", request.url);
    const res = await client.sendRequest(request);
    console.log("List of secrets from keyvault account '%s': \n%O",
      keyvaultAccountName, res.parsedBody);
  } catch (err) {
    console.log(err);
  }
}