static async Task MainAsync() { // Set Environment - Choose between Azure public cloud, china cloud and US govt. cloud _environment = AzureEnvironment.PublicEnvironments[EnvironmentName.AzureCloud]; // Get the credentials TokenCloudCredentials cloudCreds = GetCredsFromServicePrincipal(); var tokenCreds = new TokenCredentials(cloudCreds.Token); var loggingHandler = new LoggingHandler(new HttpClientHandler()); // Create our own HttpClient so we can do logging var httpClient = new HttpClient(loggingHandler); // Use the creds to create the clients we need _resourceGroupClient = new ResourceManagementClient(_environment.GetEndpointAsUri(AzureEnvironment.Endpoint.ResourceManager), tokenCreds, loggingHandler); _resourceGroupClient.SubscriptionId = cloudCreds.SubscriptionId; _websiteClient = new WebSiteManagementClient(_environment.GetEndpointAsUri(AzureEnvironment.Endpoint.ResourceManager), tokenCreds, loggingHandler); _websiteClient.SubscriptionId = cloudCreds.SubscriptionId; _dnsClient = new DnsManagementClient(tokenCreds); await ListResourceGroupsAndSites(); // Note: site names are globally unique, so you may need to change it to avoid conflicts await CreateSite("MyResourceGroup", "MyAppServicePlan", "SampleSiteFromAPI798", "West US"); // NOTE: uncomment lines below and change parameters as appropriate // if you have a configured Azure DNS Zone you can add subdomains (i.e. subdomain.mydomain.com ) //await CreateOrUpdateCNAME("MyResourceGroup", "My DNS Zone", "subdomain", "mywebsite.azurewebsites.net"); // Upload certificate to resource group //await UpdateLoadCertificate("MyResourceGroup", "CertificateName", "West US", "PathToPfxFile", "CertificatePassword"); // Bind certificate to resource group //await BindCertificateToSite("MyResourceGroup", "SiteName", "CertificateName", "hostName"); }
static async Task MainAsync() { // Get the credentials TokenCloudCredentials cloudCreds = GetCredsFromServicePrincipal(); var tokenCreds = new TokenCredentials(cloudCreds.Token); var loggingHandler = new LoggingHandler(new HttpClientHandler()); // Create our own HttpClient so we can do logging var httpClient = new HttpClient(loggingHandler); // Use the creds to create the clients we need _resourceGroupClient = new ResourceManagementClient(cloudCreds, httpClient); _websiteClient = new WebSiteManagementClient(tokenCreds, loggingHandler); _websiteClient.SubscriptionId = cloudCreds.SubscriptionId; await ListResourceGroupsAndSites(); // Note: site names are globally unique, so you may need to change it to avoid conflicts await CreateSite("MyResourceGroup", "MyAppServicePlan", "SampleSiteFromAPI", "West US"); }
static async Task MainAsync() { // Set Environment - Choose between Azure public cloud, china cloud and US govt. cloud _environment = AzureEnvironment.PublicEnvironments[EnvironmentName.AzureCloud]; // Get the credentials TokenCloudCredentials cloudCreds = GetCredsFromServicePrincipal(); var tokenCreds = new TokenCredentials(cloudCreds.Token); var loggingHandler = new LoggingHandler(new HttpClientHandler()); // Create our own HttpClient so we can do logging var httpClient = new HttpClient(loggingHandler); // Use the creds to create the clients we need _resourceGroupClient = new ResourceManagementClient(cloudCreds, _environment.GetEndpointAsUri(AzureEnvironment.Endpoint.ResourceManager), httpClient); _websiteClient = new WebSiteManagementClient(_environment.GetEndpointAsUri(AzureEnvironment.Endpoint.ResourceManager), tokenCreds, loggingHandler); _websiteClient.SubscriptionId = cloudCreds.SubscriptionId; await ListResourceGroupsAndSites(); // Note: site names are globally unique, so you may need to change it to avoid conflicts await CreateSite("MyResourceGroup", "MyAppServicePlan", "SampleSiteFromAPI", "West US"); // Upload certificate to resource group await UpdateLoadCertificate("MyResourceGroup", "CertificateName", "West US", "PathToPfxFile", "CertificatePassword"); }