Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function main(): Promise {
// For now the interactive user needs to explicitly be assigned
// the role of a constributor/owner even if the user is a subscription owner.
// azure role assignment create -o contributor --scope /subscriptions//resourceGroups//providers/Microsoft.EventHub/namespaces/ --signInName
const credentials = await interactiveLogin({tokenAudience: aadEventHubsAudience});
const client = EventHubClient.createFromAadTokenCredentials(address, path, credentials);
const partitionIds = await client.getPartitionIds();
await client.send({ body: "Hello awesome world!!" }, partitionIds[0]);
const result: EventData[] = await client.receiveBatch(partitionIds[0], 2, 5, { eventPosition: EventPosition.fromEnqueuedTime(Date.now()) });
let i = 0;
for (const data of result) {
console.log("### Actual message (%d):", ++i, data.body);
}
await client.close();
}
async function quickstart() {
const credentials = await msRestNodeAuth.loginWithServicePrincipalSecret (service_principal_application_id, service_principal_secret, tenant_id);
const client = new Arm.CognitiveServicesManagementClient (credentials, subscription_id);
// Note Azure resources are also sometimes referred to as accounts.
const accounts_client = new Arm.Accounts (client);
const resource_skus_client = new Arm.ResourceSkus (client);
//
//
// Uncomment this to list all available resource kinds, SKUs, and locations for your Azure account.
list_available_kinds_skus_locations (resource_skus_client);
// Create a resource with kind Text Translation, SKU F0 (free tier), location global.
await create_resource (accounts_client, "test_resource", "TextTranslation", "F0", "Global");
// Uncomment this to list all resources for your Azure account.
list_resources (accounts_client);
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);
}
async function main(): Promise {
const clientId = process.env["CLIENT_ID"] || "";
const clientSecret = process.env["CLIENT_SECRET"] || "";
const tenantId = process.env["TENANT_ID"] || "";
const vaultName = process.env["KEYVAULT_NAME"] || ""
const url = `https://${vaultName}.vault.azure.net`;
// Authenticate with Azure AD interactively
// const authResponse = await msRestNodeAuth.interactiveLoginWithAuthResponse({
// tokenAudience: 'https://vault.azure.net'
// });
// Or authenticate with Azure AD using MSI to get TokenCredential.
const credential = await msRestNodeAuth.loginWithServicePrincipalSecret(
clientId,
clientSecret,
tenantId,
{
tokenAudience: 'https://vault.azure.net'
}
);
const client = new SecretsClient(url, credential);
// The client can be configured using NewPipelineOptions
// const client = new SecretsClient(url, credential, {
// telemetry: { value: "Customized-user-agent/0.1"},
// retryOptions: { retryCount: 5 }
// });
let auth = (await globalConfig.get(AUTH)) as AuthResponse | null;
// if old AUTH config is not found, we trigger a new login flow
if (auth === null) {
auth = await retryLogin(auth);
} else {
const creds = auth.credentials as DeviceTokenCredentials;
const { clientId, domain, username, tokenAudience, environment } = creds;
// if old AUTH config was found, we extract and check if the required fields are valid
if (creds && clientId && domain && username && tokenAudience && environment) {
const cache = new MemoryCache();
cache.add(creds.tokenCache._entries, () => {});
// we need to regenerate a proper object from the saved credentials
auth.credentials = new DeviceTokenCredentials(
clientId,
domain,
username,
tokenAudience,
new Environment(environment),
cache
);
const token = await auth.credentials.getToken();
// if extracted token has expired, we request a new login flow
if (new Date(token.expiresOn).getTime() < Date.now()) {
logger.info(`Your stored credentials have expired; you'll have to log in again`);
auth = await retryLogin(auth);
}
} else {
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);
}
async function main(): Promise {
const credentials = await loginWithServicePrincipalSecret(clientId, secret, domain, { tokenAudience: aadEventHubsAudience });
const client = EventHubClient.createFromAadTokenCredentials(address, path, credentials);
const partitionIds = await client.getPartitionIds();
await client.send({ body: "Hello awesome world!!" }, partitionIds[0]);
const result: EventData[] = await client.receiveBatch(partitionIds[0], 2, 5, { eventPosition: EventPosition.fromEnqueuedTime(Date.now()) });
let i = 0;
for (const data of result) {
console.log("### Actual message (%d):", ++i, data.body);
}
await client.close();
}
async login() {
try {
const authResponse = await msRestNodeAuth.loginWithServicePrincipalSecretWithAuthResponse(this.clientId, this.clientSecret, this.tenantId);
this.credentials = authResponse.credentials
} catch (err) {
console.log(err);
}
}
async function main() {
const tokenCreds = await loginWithServicePrincipalSecret(clientId, clientSecret, tenantId, {
tokenAudience: "https://servicebus.azure.net/"
});
const sbClient = ServiceBusClient.createFromAadTokenCredentials(serviceBusEndpoint, tokenCreds);
/*
Refer to other samples, and place your code here
to create queue clients, and send/receive messages
*/
await sbClient.close();
}
export async function login(): Promise {
const creds = await msRestNodeAuth.loginWithServicePrincipalSecret(clientId, secret, tenant)
const websites = new appservice.WebSiteManagementClient(creds as any, subscriptionId)
return {
websites,
webapps: new appservice.WebApps(websites),
secrets: new SecretClient(`https://majavashakki-vault.vault.azure.net`, new EnvironmentCredential()),
cosmosdb: new cosmosdb.CosmosDBManagementClient(creds as any, subscriptionId),
containerregistry: new ContainerRegistryManagementClient(creds as any, subscriptionId),
}
}