public static void Run( [TimerTrigger("0 */2 * * * *")] TimerInfo myTimer, [Queue("alerts", Connection = "OUTPUT_QUEUE")] IAsyncCollector <string> myQueueItems, ILogger log) { log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}"); try { var spn = new AzureServicePrincipal(); var credentials = SdkContext.AzureCredentialsFactory.FromServicePrincipal(spn.clientId, spn.clientSecret, spn.tenantId, AzureEnvironment.AzureGlobalCloud); var azure = Azure .Configure() .WithLogLevel(HttpLoggingDelegatingHandler.Level.Basic) .Authenticate(credentials) .WithDefaultSubscription(); WalkCosmosAccounts(azure, myQueueItems, log).Wait(); } catch (Exception e) { log.LogInformation(e.Message); log.LogInformation(e.StackTrace); } }
static void Main(string[] args) { //string expectedSubscriptionID = "{b44fdde2-1234-1234-a75b-24429617b2d9}"; AzureServicePrincipal sp = new AzureServicePrincipal(); AuthenticationResult token = null; sp.subscriptionID = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"; sp.tenantID = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"; sp.applicationID = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"; sp.applicationSecret = "xxxxxxxxxxxxxxxx"; if (sp.CheckAllGuidsMembers() == true) { token = sp.GetSecurityToken(); Console.WriteLine("Token acquired. Expires on:" + token.ExpiresOn); } else { Console.WriteLine("To run this test, please enter values for the service principal object in program.cs."); } Console.Write("Press a key to continue...."); Console.ReadLine(); }
public void CheckAllGuidsMembers_uninitializedMembers() { AzureServicePrincipal sp = new AzureServicePrincipal(); //test for uninitialized values Assert.AreEqual(false, sp.CheckAllGuidsMembers()); }
public void ValidateGuidFormat4() { AzureServicePrincipal sp = new AzureServicePrincipal(); //Assert will be handled by the exception sp.subscriptionID = sp.ValidateGuidFormat("1234567-1234-1234-a75b-24429617b2d9"); }
public void ValidateGuidFormat2() { AzureServicePrincipal sp = new AzureServicePrincipal(); //Assert will be handled by the exception sp.subscriptionID = sp.ValidateGuidFormat("b44fdde2-1234-1234-a75b-1234"); }
public void CheckAllGuidsMembers_initializedMembers() { AzureServicePrincipal sp = new AzureServicePrincipal(); sp.applicationID = "{b44fdde2-1234-1234-a75b-24429617b2d9}"; sp.subscriptionID = "{b44fdde2-1234-1234-a75b-24429617b2d9}"; sp.tenantID = "{b44fdde2-1234-1234-a75b-24429617b2d9}"; Assert.AreEqual(true, sp.CheckAllGuidsMembers()); }
public void ValidateGuidFormat() { AzureServicePrincipal sp = new AzureServicePrincipal(); string expectedSubscriptionID = "b44fdde2-1234-1234-a75b-24429617b2d9"; sp.subscriptionID = sp.ValidateGuidFormat("b44fdde2-1234-1234-a75b-24429617b2d9"); //The expected value should match with curly braces Assert.AreEqual(expectedSubscriptionID, sp.subscriptionID, true); }
public static RestClient GetRestClient(AzureServicePrincipal servicePrincipal, AzureSubscription azureSubscription) { var credentials = GetAzureCredentials(servicePrincipal, azureSubscription); return(RestClient .Configure() .WithEnvironment(Microsoft.Azure.Management.ResourceManager.Fluent.AzureEnvironment.FromName(azureSubscription.AzureRegion)) .WithCredentials(credentials) .Build()); }
public AzureWebAppSettings(string webappName, string resourceGroup, AzureServicePrincipal servicePrincipal, AzureSubscription azureSubscription, string siteSlotName = null, string servicePlanResourceGroupName = null, bool useIPBasedSSL = false) { this.WebAppName = webappName; this.ResourceGroupName = resourceGroup; this.AzureServicePrincipal = servicePrincipal; this.AzureSubscription = azureSubscription; this.SiteSlotName = siteSlotName; this.ServicePlanResourceGroupName = servicePlanResourceGroupName; this.UseIPBasedSSL = useIPBasedSSL; }
public static AzureCredentials GetAzureCredentials(AzureServicePrincipal servicePrincipal, AzureSubscription azureSubscription) { if (servicePrincipal == null) { throw new ArgumentNullException(nameof(servicePrincipal)); } if (azureSubscription == null) { throw new ArgumentNullException(nameof(azureSubscription)); } return(new AzureCredentials(servicePrincipal.ServicePrincipalLoginInformation, azureSubscription.Tenant, Microsoft.Azure.Management.ResourceManager.Fluent.AzureEnvironment.FromName(azureSubscription.AzureRegion))); }
static void Main(string[] args) { //string expectedSubscriptionID = "{b44fdde2-1234-1234-a75b-24429617b2d9}"; AzureServicePrincipal sp = new AzureServicePrincipal(); AuthenticationResult token = null; sp.subscriptionID = "bc763005-d3e0-4e3f-b57b-c95bd0f9dc23"; sp.tenantID = "2d38b813-8ed2-4b98-9d2b-ca8c3a732b8e"; sp.applicationID = "570aa489-9df3-475f-8065-bc8fde0267df"; sp.applicationSecret = "myAprilTestPassword89!"; if (sp.CheckAllGuidsMembers() == true) { token = sp.GetSecurityToken(); Console.WriteLine("Token acquired. Expires on:" + token.ExpiresOn); } Console.ReadLine(); }