How to use the @azure/ms-rest-nodeauth.AzureCliCredentials function in @azure/ms-rest-nodeauth

To help you get started, we’ve selected a few @azure/ms-rest-nodeauth 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 pulumi / examples / azure-ts-dynamicresource / cdnCustomDomain.ts View on Github external
let credentials: ServiceClientCredentials;

        // If at least one of them is empty, try looking at the env vars.
        if (!clientID || !clientSecret || !tenantID || !subscriptionID) {
            await pulumi.log.info("Checking env vars for ARM credentials.", undefined, undefined, true);
            clientID = process.env["ARM_CLIENT_ID"];
            clientSecret = process.env["ARM_CLIENT_SECRET"];
            tenantID = process.env["ARM_TENANT_ID"];
            subscriptionID = process.env["ARM_SUBSCRIPTION_ID"];
        }

        // If they are still empty, try to get the creds from Az CLI.
        if (!clientID || !clientSecret || !tenantID || !subscriptionID) {
            await pulumi.log.info("Env vars did not contain ARM credentials. Trying Az CLI.", undefined, undefined, true);
            // `create()` will throw an error if the Az CLI is not installed or `az login` has never been run.
            const cliCredentials = await msRestAzure.AzureCliCredentials.create();
            subscriptionID = cliCredentials.subscriptionInfo.id;
            credentials = cliCredentials;
            await pulumi.log.info("Using credentials from Az CLI.", undefined, undefined, true);
        } else {
            credentials = await msRestAzure.loginWithServicePrincipalSecret(clientID, clientSecret, tenantID);
        }

        return new cdnManagement.CdnManagementClient(credentials, subscriptionID);
    }