public Microsoft.Azure.Management.Fluent.IAzure LoginAzure() { var credentials = SdkContext.AzureCredentialsFactory .FromFile("C:/Users/admin12345/projects/azure-sdk-practices-netcore/authFile.json"); Microsoft.Azure.Management.Fluent.IAzure azure = Azure .Configure() .WithLogLevel(Microsoft.Azure.Management.ResourceManager.Fluent.Core.HttpLoggingDelegatingHandler.Level.Basic) .Authenticate(credentials) .WithDefaultSubscription(); return(azure); }
private static async Task <IServiceBusNamespace> RequireNamespace(Microsoft.Azure.Management.Fluent.IAzure azure, string nameSpaceName) { System.Console.WriteLine("Require namespace -> {0}", nameSpaceName); var namespaces = await azure.ServiceBusNamespaces.ListAsync(); Dump(namespaces); var nameSpace = namespaces.Where(ns => ns.Name == nameSpaceName).FirstOrDefault(); if (nameSpace == null) { throw new ArgumentException($"Unable to find namespace {nameSpaceName}"); } return(nameSpace); }
private void init(string subscriptionId, string clientsecrett, string clientId, string tenantId) { this.subscriptionId = subscriptionId; this.clientsecrett = clientsecrett; this.clientId = clientId; this.tenantId = tenantId; Console.WriteLine("clientId"); Console.WriteLine(clientId); Console.WriteLine("tenantId"); Console.WriteLine(tenantId); credentials = SdkContext.AzureCredentialsFactory.FromServicePrincipal(clientId , clientsecrett, tenantId , AzureEnvironment.AzureGlobalCloud); azure = Microsoft.Azure.Management.Fluent.Azure.Configure() .Authenticate(credentials).WithSubscription(subscriptionId); foreach (ISubscription sub in azure.Subscriptions.List()) { Console.WriteLine(sub.DisplayName); } }
public static void Run([TimerTrigger("0 * * * * *")] TimerInfo myTimer, ILogger log) { try { log.LogInformation($"Fault Injector - VM function started at: {DateTime.Now}"); string subListStr = Environment.GetEnvironmentVariable("targetSubscriptionIDList"); string rgListStr = Environment.GetEnvironmentVariable("targetRGList"); string clientId = Environment.GetEnvironmentVariable("clientId"); string tenantId = Environment.GetEnvironmentVariable("tenantId"); string clientPwd = Environment.GetEnvironmentVariable("clientPassword"); string ingestConn = Environment.GetEnvironmentVariable("ingestConn"); log.LogInformation($"Params: SubscriptionIDList: {subListStr}; RGList: {rgListStr}"); ServicePrincipalLoginInformation spi = new ServicePrincipalLoginInformation { ClientId = clientId, ClientSecret = clientPwd }; AzureCredentials myAzCreds = new AzureCredentials(spi, tenantId, AzureEnvironment.AzureGlobalCloud); Microsoft.Azure.Management.Fluent.IAzure myAz = Azure.Configure().Authenticate(myAzCreds).WithSubscription(subListStr); foreach (string curRGName in rgListStr.Split(",")) { log.LogInformation($"Iterating over RG {curRGName}"); FIVM vmFuzzer = new FIVM(log, myAz, curRGName, ingestConn, "annandale", "faultInjections"); vmFuzzer.Fuzz(1); FINSG nsgFuzzer = new FINSG(log, myAz, curRGName, ingestConn, "annandale", "faultInjections"); nsgFuzzer.Fuzz(25); } log.LogInformation($"Fault Injector - VM function finished at: {DateTime.Now}"); } catch (Exception err) { log.LogError(err.ToString()); } }
private void InitAzureEnvironment() { var credentials = default(AzureCredentials); // Read required environment variables this.subscriptionId = Environment.GetEnvironmentVariable(TEST_SUBSCRIPTION_ID); this.resourceGroupName = Environment.GetEnvironmentVariable(TEST_RG_NAME_ENV); // For local dev, rely on an auth file, otherwise on a service principal set in the environment of the build agent. var localAuthFile = Environment.GetEnvironmentVariable(LOCAL_DEV_ENV); if (string.IsNullOrWhiteSpace(localAuthFile)) { var clientId = Environment.GetEnvironmentVariable(CLIENT_ID_ENV); var clientSecret = Environment.GetEnvironmentVariable(CLIENT_SECRET_ENV); var tenantId = Environment.GetEnvironmentVariable(TENANT_ID_ENV); credentials = credFactory.FromServicePrincipal(clientId, clientSecret, tenantId, AzureEnvironment.AzureGlobalCloud); } else { // Create the file with "az ad sp create-for-rbac --sdk-auth" credentials = credFactory.FromFile(localAuthFile); // Assign the default subscription ID if none has been provided in the environment if (string.IsNullOrWhiteSpace(this.subscriptionId)) { this.subscriptionId = credentials.DefaultSubscriptionId; } } // Create the rest client based on the authentication above. TestAzure = Az.Azure.Configure() .WithLogLevel(Microsoft.Azure.Management.ResourceManager.Fluent.Core.HttpLoggingDelegatingHandler.Level.Headers) .Authenticate(credentials) .WithDefaultSubscription(); }