public async Task Update() { if (tenantId == null || clientId == null || secret == null || subscriptionId == null || resourceGroupName == null || zoneName == null || recordSetName == null) { #pragma warning disable CA1303 // Do not pass literals as localized parameters _logger.LogError("Configuration settings not set."); #pragma warning restore CA1303 // Do not pass literals as localized parameters } else { try { using (_telemetryClient.StartOperation <RequestTelemetry>("operation")) { var ipAddress = await GetPublicIP().ConfigureAwait(true); if (null != ipAddress) { // Build the service credentials and DNS management client var serviceCreds = await ApplicationTokenProvider.LoginSilentAsync(tenantId, clientId, secret).ConfigureAwait(true); var dnsClient = new DnsManagementClient(serviceCreds); dnsClient.SubscriptionId = subscriptionId; var currentRecordSet = await dnsClient.RecordSets.GetAsync(resourceGroupName, zoneName, recordSetName, RecordType.A).ConfigureAwait(true); if (currentRecordSet.ARecords.Where(r => r.Ipv4Address == ipAddress).Count() == 1) { _logger.LogInformation("Zone already up to date with IP: " + ipAddress); _telemetryClient.TrackEvent("IP Address already up to date"); } else { // Create record set parameters var recordSetParams = new RecordSet(); recordSetParams.TTL = 300; // Add records to the record set parameter object. recordSetParams.ARecords = new List <ARecord>(); recordSetParams.ARecords.Add(new ARecord(ipAddress)); // Create the actual record set in Azure DNS // Note: no ETAG checks specified, will overwrite existing record set if one exists await dnsClient.RecordSets.CreateOrUpdateAsync(resourceGroupName, zoneName, recordSetName, RecordType.A, recordSetParams).ConfigureAwait(true); _logger.LogInformation("Zone Updated with IP: " + ipAddress); _telemetryClient.TrackEvent("Updated IP Address"); } dnsClient.Dispose(); } } } catch (Exception e) { _logger.LogError(e.ToString()); _telemetryClient.TrackException(e); } } }
public AzureDnsProvider(AcmebotOptions options) { _dnsManagementClient = new DnsManagementClient(new TokenCredentials(new AppAuthenticationTokenProvider())) { SubscriptionId = options.AzureDns?.SubscriptionId ?? options.SubscriptionId }; }
public void UpdateZonePreconditionFailed() { using ( MockContext context = MockContext.Start(this.GetType().FullName) ) { var resourcesHandler = new RecordedDelegatingHandler { StatusCodeToReturn = System.Net.HttpStatusCode.OK }; var dnsHandler = new RecordedDelegatingHandler { StatusCodeToReturn = System.Net.HttpStatusCode.OK }; DnsManagementClient dnsClient = ResourceGroupHelper.GetDnsClient(context, dnsHandler); string zoneName = TestUtilities.GenerateName("hydratest.dnszone.com"); var resourceManagementClient = ResourceGroupHelper.GetResourcesClient( context, resourcesHandler); string location = ResourceGroupHelper.GetResourceLocation( resourceManagementClient, "microsoft.network/dnszones"); ResourceGroup resourceGroup = ResourceGroupHelper.CreateResourceGroup( resourceManagementClient); var createdZone = ResourceGroupHelper.CreateZone( dnsClient, zoneName, location, resourceGroup); // expect Precondition Failed 412 TestHelpers.AssertThrows <CloudException>( () => dnsClient.Zones.CreateOrUpdate( resourceGroup.Name, zoneName, createdZone, "somegibberish", null), ex => ex.Body.Code == "PreconditionFailed"); dnsClient.Zones.Delete( resourceGroup.Name, zoneName, ifMatch: null); dnsClient.Zones.Delete( resourceGroup.Name, "hiya.com", ifMatch: null); //Assert.Null(result); } }
private async Task <DnsManagementClient> CreateDnsManagementClientAsync(AzureAuthenticationOptions options) { var sw = ValueStopwatch.StartNew(); _logger.LogInformation("[Azure Management Client][Started]"); var tokenProvider = new AzureServiceTokenProvider(); var accessToken = await tokenProvider.GetAccessTokenAsync("https://management.azure.com/", options.SubscriptionId); var tokenCredentials = new TokenCredentials(accessToken); var azureCredentials = new AzureCredentials(tokenCredentials, tokenCredentials, options.TenantId, AzureEnvironment.AzureGlobalCloud); var restClient = RestClient .Configure() .WithEnvironment(AzureEnvironment.AzureGlobalCloud) .WithLogLevel(HttpLoggingDelegatingHandler.Level.Basic) .WithCredentials(azureCredentials) .Build(); var dnsClient = new DnsManagementClient(restClient) { SubscriptionId = options.SubscriptionId, }; _logger.LogInformation("[Azure Management Client][Ended] Elapsed: {elapsed}sec", sw.GetElapsedTime().TotalSeconds); return(dnsClient); }
public AzureDnsProvider(AzureDnsOptions options, IAzureEnvironment environment) { _dnsManagementClient = new DnsManagementClient(new Uri(environment.ResourceManager), new TokenCredentials(new AppAuthenticationTokenProvider(environment))) { SubscriptionId = options.SubscriptionId }; }
internal static void CreatePrivateZones( DnsManagementClient dnsClient, ResourceGroup resourceGroup, IList <string> zonesNames, ResourceManagementClient resourcesClient, NetworkManagementClient networkManagementClient) { var location = ResourceGroupHelper.GetResourceLocation(resourcesClient, "microsoft.network/dnszones"); foreach (var zonesName in zonesNames) { var registrationVnets = Enumerable.Range(0, 1).Select(i => ResourceGroupHelper.CreateVirtualNetwork(resourceGroup.Name, networkManagementClient)).ToList(); var resolutionVnets = Enumerable.Range(0, 1).Select(i => ResourceGroupHelper.CreateVirtualNetwork(resourceGroup.Name, networkManagementClient)).ToList(); ResourceGroupHelper.CreatePrivateZone( dnsClient, zonesName, location, registrationVnets.Select(vNet => new SubResource { Id = vNet.Id }).ToList(), resolutionVnets.Select(vNet => new SubResource { Id = vNet.Id }).ToList(), resourceGroup); } }
public async Task <bool> InitProvider(Dictionary <string, string> credentials, Dictionary <string, string> parameters, ILog log = null) { _log = log; _credentials = credentials; // https://docs.microsoft.com/en-us/dotnet/api/overview/azure/dns?view=azure-dotnet var serviceCreds = await ApplicationTokenProvider.LoginSilentAsync( _credentials["tenantid"], _credentials["clientid"], _credentials["secret"] ); _dnsClient = new DnsManagementClient(serviceCreds); _dnsClient.SubscriptionId = _credentials["subscriptionid"]; if (parameters?.ContainsKey("propagationdelay") == true) { if (int.TryParse(parameters["propagationdelay"], out int customPropDelay)) { _customPropagationDelay = customPropDelay; } } return(true); }
public AzureDNSZone(ServiceClientCredentials credentials, string subscriptionId) { _dnsClient = new DnsManagementClient(credentials) { SubscriptionId = subscriptionId }; }
public static void DeleteZones(DnsManagementClient dnsClient, ResourceGroupExtended resourceGroup, string[] zoneNames) { foreach (string zoneName in zoneNames) { dnsClient.Zones.Delete(resourceGroup.Name, zoneName, new ZoneDeleteParameters()); } }
private async Task <DnsManagementClient> GetClient() { if (_azureDnsClient == null) { // Build the service credentials and DNS management client ServiceClientCredentials credentials; // Decide between Managed Service Identity (MSI) // and service principal with client credentials if (_options.UseMsi) { var azureServiceTokenProvider = new AzureServiceTokenProvider(); var accessToken = await azureServiceTokenProvider.GetAccessTokenAsync(_resourceManagerEndpoint.ToString()); credentials = new TokenCredentials(accessToken); } else { credentials = await ApplicationTokenProvider.LoginSilentAsync( _options.TenantId, _options.ClientId, _options.Secret.Value, GetActiveDirectorySettingsForAzureEnvironment()); } _azureDnsClient = new DnsManagementClient(credentials, _proxyService.GetHttpClient(), true) { BaseUri = _resourceManagerEndpoint, SubscriptionId = _options.SubscriptionId }; } return(_azureDnsClient); }
public void UpdateZonePreconditionFailed() { using (UndoContext context = UndoContext.Current) { context.Start(); DnsManagementClient dnsClient = ResourceGroupHelper.GetDnsClient(); string zoneName = TestUtilities.GenerateName("hydratestdnszone"); string location = ResourceGroupHelper.GetResourceLocation(ResourceGroupHelper.GetResourcesClient(), "microsoft.network/dnszones"); ResourceGroupExtended resourceGroup = ResourceGroupHelper.CreateResourceGroup(); ZoneCreateOrUpdateResponse createresponse = ResourceGroupHelper.CreateZone(dnsClient, zoneName, location, resourceGroup); ZoneCreateOrUpdateParameters updateParameters = new ZoneCreateOrUpdateParameters { Zone = createresponse.Zone }; updateParameters.Zone.ETag = "somegibberish"; // expect Precondition Failed 412 TestHelpers.AssertThrows <CloudException>( () => dnsClient.Zones.CreateOrUpdate(resourceGroup.Name, zoneName, updateParameters), ex => ex.Error.Code == "PreconditionFailed"); // expect Precondition Failed 412 TestHelpers.AssertThrows <CloudException>( () => dnsClient.Zones.Delete(resourceGroup.Name, zoneName, new ZoneDeleteParameters { IfMatch = "somemoregib" }), ex => ex.Error.Code == "PreconditionFailed"); dnsClient.Zones.Delete(resourceGroup.Name, zoneName, new ZoneDeleteParameters()); } }
private async Task <DnsManagementClient> GetClient() { if (_azureDnsClient == null) { // Build the service credentials and DNS management client ServiceClientCredentials credentials; // Decide between Managed Service Identity (MSI) and service principal with client credentials if (_options.UseMsi) { var azureServiceTokenProvider = new AzureServiceTokenProvider(); var accessToken = await azureServiceTokenProvider.GetAccessTokenAsync("https://management.azure.com/"); credentials = new TokenCredentials(accessToken); } else { credentials = await ApplicationTokenProvider.LoginSilentAsync( _options.TenantId, _options.ClientId, _options.Secret.Value); } _azureDnsClient = new DnsManagementClient(credentials, _proxyService.GetHttpClient(), true) { SubscriptionId = _options.SubscriptionId }; } return(_azureDnsClient); }
public static void DeleteZones(DnsManagementClient dnsClient, ResourceGroupExtended resourceGroup, string[] zoneNames) { foreach (string zoneName in zoneNames) { dnsClient.Zones.Delete(resourceGroup.Name, zoneName, ifMatch: null, ifNoneMatch: null); } }
public void UpdateZonePreconditionFailed() { using (UndoContext context = UndoContext.Current) { context.Start(); DnsManagementClient dnsClient = ResourceGroupHelper.GetDnsClient(); string zoneName = TestUtilities.GenerateName("hydratestdnszone.com"); string location = ResourceGroupHelper.GetResourceLocation(ResourceGroupHelper.GetResourcesClient(), "microsoft.network/dnszones"); ResourceGroupExtended resourceGroup = ResourceGroupHelper.CreateResourceGroup(); ZoneCreateOrUpdateResponse createresponse = ResourceGroupHelper.CreateZone(dnsClient, zoneName, location, resourceGroup); ZoneCreateOrUpdateParameters updateParameters = new ZoneCreateOrUpdateParameters { Zone = createresponse.Zone }; updateParameters.Zone.ETag = "somegibberish"; // expect Precondition Failed 412 TestHelpers.AssertThrows <CloudException>( () => dnsClient.Zones.CreateOrUpdate(resourceGroup.Name, zoneName, ifMatch: null, ifNoneMatch: null, parameters: updateParameters), ex => ex.Error.Code == "PreconditionFailed"); var result = dnsClient.Zones.Delete(resourceGroup.Name, zoneName, ifMatch: null, ifNoneMatch: null); Assert.Equal(HttpStatusCode.OK, result.StatusCode); result = dnsClient.Zones.Delete(resourceGroup.Name, "hiya.com", ifMatch: null, ifNoneMatch: null); Assert.Equal(HttpStatusCode.NoContent, result.StatusCode); } }
public AzureDnsChallengeHandler(ManagerConfig config) { var cred = new TokenCredentials(new AzureIdentityProvider("https://management.azure.com/")); this.dnsClient = new DnsManagementClient(cred); this.dnsClient.SubscriptionId = config.SubscriptionId; }
public void CrudZoneSetsTheCurrentAndMaxRecordSetNumbersInResponse() { using (UndoContext context = UndoContext.Current) { context.Start(); DnsManagementClient dnsClient = ResourceGroupHelper.GetDnsClient(); string zoneName = TestUtilities.GenerateName("hydratestdnszone"); string location = ResourceGroupHelper.GetResourceLocation(ResourceGroupHelper.GetResourcesClient(), "microsoft.network/dnszones"); ResourceGroupExtended resourceGroup = ResourceGroupHelper.CreateResourceGroup(); // Create the zone clean ZoneCreateOrUpdateResponse createResponse = dnsClient.Zones.CreateOrUpdate( resourceGroup.Name, zoneName, new ZoneCreateOrUpdateParameters { Zone = new Microsoft.Azure.Management.Dns.Models.Zone { Location = location, Name = zoneName, Properties = new Microsoft.Azure.Management.Dns.Models.ZoneProperties { MaxNumberOfRecordSets = 42, // Test that specifying this value does not break Create (it must be ignored on server side). NumberOfRecordSets = 65, // Test that specifying this value does not break Create (it must be ignored on server side). } } }); // Verify RecordSet numbers in the response. Assert.Equal(HttpStatusCode.Created, createResponse.StatusCode); // Retrieve the zone after create ZoneGetResponse getResponse = dnsClient.Zones.Get(resourceGroup.Name, zoneName); // Verify RecordSet numbers in the response. Assert.Equal(HttpStatusCode.OK, getResponse.StatusCode); Assert.True(getResponse.Zone.Properties.NumberOfRecordSets == 2); Zone retrievedZone = getResponse.Zone; retrievedZone.Tags = new Dictionary <string, string> { { "tag1", "value1" } }; retrievedZone.Properties.NumberOfRecordSets = null; retrievedZone.Properties.MaxNumberOfRecordSets = null; // Update the zone ZoneCreateOrUpdateResponse updateResponse = dnsClient.Zones.CreateOrUpdate(resourceGroup.Name, zoneName, new ZoneCreateOrUpdateParameters { Zone = retrievedZone }); // Verify RecordSet numbers in the response. Assert.Equal(HttpStatusCode.OK, updateResponse.StatusCode); // Delete the zone AzureOperationResponse deleteResponse = dnsClient.Zones.Delete(resourceGroup.Name, zoneName, new ZoneDeleteParameters()); Assert.Equal(HttpStatusCode.OK, deleteResponse.StatusCode); } }
private async Task <DnsManagementClient> PrepareDNSClientAsync(string tenantId, string clientId, string secret) { var restCredentials = await ApplicationTokenProvider.LoginSilentAsync(tenantId, clientId, secret); var dnsManagementClient = new DnsManagementClient(restCredentials); return(dnsManagementClient); }
public void SetClient(DomainResourceGroup domainGroup) { _domainRG = domainGroup; _client = new DnsManagementClient(_serviceCreds) { SubscriptionId = _domainRG.AzureSubscriptionId }; }
private void init(ServiceClientCredentials credentials, string SubscriptionID) { dnsManagementClient = new DnsManagementClient(credentials); dnsManagementClient.SubscriptionId = SubscriptionID; IZonesOperations zones = dnsManagementClient.Zones; dnsZone = zones.Get(ResourceGroupName, ZoneName); }
public void CrudZoneSetsTheCurrentAndMaxRecordSetNumbersInResponse() { using ( MockContext context = MockContext.Start(this.GetType().FullName) ) { var resourcesHandler = new RecordedDelegatingHandler { StatusCodeToReturn = System.Net.HttpStatusCode.OK }; var dnsHandler = new RecordedDelegatingHandler { StatusCodeToReturn = System.Net.HttpStatusCode.OK }; DnsManagementClient dnsClient = ResourceGroupHelper.GetDnsClient(context, dnsHandler); string zoneName = TestUtilities.GenerateName("hydratest.dnszone.com"); var resourceManagementClient = ResourceGroupHelper.GetResourcesClient( context, resourcesHandler); string location = ResourceGroupHelper.GetResourceLocation( resourceManagementClient, "microsoft.network/dnszones"); ResourceGroup resourceGroup = ResourceGroupHelper.CreateResourceGroup( resourceManagementClient); // Create the zone clean dnsClient.Zones.CreateOrUpdate( resourceGroup.Name, zoneName, new Zone { Location = location, }); // Retrieve the zone after create Zone retrievedZone = dnsClient.Zones.Get( resourceGroup.Name, zoneName); // Verify RecordSet numbers in the response. Assert.True(retrievedZone.NumberOfRecordSets == 2); retrievedZone.Tags = new Dictionary <string, string> { { "tag1", "value1" } }; // Delete the zone DeleteZones(dnsClient, resourceGroup, new[] { zoneName }); } }
public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, ILogger log) { log.LogInformation("IP Update requested"); string remoteip = req.Query["remoteip"]; string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); dynamic data = JsonConvert.DeserializeObject(requestBody); remoteip = remoteip ?? data?.remoteip; string dnsZone = "domain.com"; string hostname = "vpn"; string resourceGroupName = "DNS"; string appID = "appid"; string appSecret = "appsecret"; string subscriptionID = "subscriptionid"; string tenantID = "tenantid"; // Build the service credentials and DNS management client Microsoft.Rest.ServiceClientCredentials serviceCreds = await ApplicationTokenProvider.LoginSilentAsync(tenantID, appID, appSecret); DnsManagementClient dnsClient = new DnsManagementClient(serviceCreds) { SubscriptionId = subscriptionID }; var recordSet = dnsClient.RecordSets.Get(resourceGroupName, dnsZone, hostname, RecordType.A); // clean up older records if (recordSet.ARecords.Count > 0) { recordSet.ARecords.Clear(); } recordSet.ARecords.Add(new ARecord(remoteip)); // Update the record set in Azure DNS // Note: ETAG check specified, update will be rejected if the record set has changed in the meantime recordSet = await dnsClient.RecordSets.CreateOrUpdateAsync(resourceGroupName, dnsZone, hostname, RecordType.A, recordSet, recordSet.Etag); // update TXT recordSet = dnsClient.RecordSets.Get(resourceGroupName, dnsZone, hostname, RecordType.TXT); recordSet.TxtRecords[0].Value.Clear(); recordSet.TxtRecords[0].Value.Add(DateTime.Now.ToString()); // Update the record set in Azure DNS recordSet = await dnsClient.RecordSets.CreateOrUpdateAsync(resourceGroupName, dnsZone, hostname, RecordType.TXT, recordSet, recordSet.Etag); return(remoteip != null ? (ActionResult) new OkObjectResult($"OK") : new BadRequestObjectResult("Unable to update IP")); }
public static void CreateZones(DnsManagementClient dnsClient, ResourceGroupExtended resourceGroup, string[] zoneNames) { string location = ResourceGroupHelper.GetResourceLocation(ResourceGroupHelper.GetResourcesClient(), "microsoft.network/dnszones"); foreach (string zoneName in zoneNames) { ResourceGroupHelper.CreateZone(dnsClient, zoneName, location, resourceGroup); } }
public DreamhostDnsValidation( LookupClientProvider dnsClient, ILogService logService, DreamhostOptions options, string identifier) : base(dnsClient, logService, options, identifier) { _client = new DnsManagementClient(options.ApiKey.Value, logService); }
public SharedFunctions(IHttpClientFactory httpClientFactory, LookupClient lookupClient, IAcmeProtocolClientFactory acmeProtocolClientFactory, WebSiteManagementClient webSiteManagementClient, DnsManagementClient dnsManagementClient) { _httpClientFactory = httpClientFactory; _lookupClient = lookupClient; _acmeProtocolClientFactory = acmeProtocolClientFactory; _webSiteManagementClient = webSiteManagementClient; _dnsManagementClient = dnsManagementClient; }
public AzureDnsProvider(AzureDnsOptions options, AzureEnvironment environment) { var credential = new DefaultAzureCredential(new DefaultAzureCredentialOptions { AuthorityHost = environment.ActiveDirectory }); _dnsManagementClient = new DnsManagementClient(options.SubscriptionId, environment.ResourceManager, credential); }
public async Task UpdateDnsRecordAsync(IPAddress newAddress) { Logger.LogTrace("Updating {host} to {newAddress}", $"{Options.DnsRelativeRecordSetName}.{Options.DnsZoneName}", newAddress); Logger.LogDebug("Silently logging in to service client"); ServiceClientCredentials serviceClientCredentials = await ApplicationTokenProvider.LoginSilentAsync( Options.ApplicationTenantDomain, Options.ApplicationClientId, Options.ApplicationClientSecret); var dnsManagementClient = new DnsManagementClient(serviceClientCredentials) { SubscriptionId = Options.DnsSubscriptionId }; Logger.LogDebug("Fetching existing A records"); RecordSet existingRecords = await dnsManagementClient.RecordSets.GetAsync( Options.DnsResourceGroup, Options.DnsZoneName, Options.DnsRelativeRecordSetName, RecordType.A); Logger.LogDebug("Clearing {count} existing A records", existingRecords.ARecords.Count); existingRecords.ARecords.Clear(); existingRecords.ARecords.Add(new ARecord(newAddress.ToString())); if (Options.UpdateMetaData) { string nowStr = DateTime.UtcNow.ToString(CultureInfo.InvariantCulture); Logger.LogDebug("Updating \"LastUpdated\" metadata to {nowStr}", nowStr); existingRecords.Metadata ??= new Dictionary <string, string>(); existingRecords.Metadata["LastUpdated"] = nowStr; } Logger.LogTrace("Updating A records"); AzureOperationResponse <RecordSet> operationResponse = await dnsManagementClient.RecordSets.CreateOrUpdateWithHttpMessagesAsync( Options.DnsResourceGroup, Options.DnsZoneName, Options.DnsRelativeRecordSetName, RecordType.A, existingRecords, existingRecords.Etag); HttpStatusCode responseStatus = operationResponse.Response.StatusCode; string responseBody = await operationResponse.Response.Content.ReadAsStringAsync(); if (operationResponse.Response.IsSuccessStatusCode) { Logger.LogDebug("Operation returned {responseStatus}: {responseBody}", responseStatus, responseBody); return; } Logger.LogError("Failed to update IP: {responseStatus} {responseBody}", responseStatus, responseBody); }
public SharedFunctions(IHttpClientFactory httpClientFactory, LookupClient lookupClient, IAcmeProtocolClientFactory acmeProtocolClientFactory, KeyVaultClient keyVaultClient, DnsManagementClient dnsManagementClient) { _httpClientFactory = httpClientFactory; _lookupClient = lookupClient; _acmeProtocolClientFactory = acmeProtocolClientFactory; _keyVaultClient = keyVaultClient; _dnsManagementClient = dnsManagementClient; }
public void ListZones() { using ( MockContext context = MockContext.Start(this.GetType().FullName) ) { var resourcesHandler = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; var dnsHandler = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; DnsManagementClient dnsClient = ResourceGroupHelper.GetDnsClient(context, dnsHandler); var zoneNames = new[] { TestUtilities.GenerateName("hydratest.dnszone.com"), TestUtilities.GenerateName("hydratest.dnszone.com") }; var resourceManagementClient = ResourceGroupHelper.GetResourcesClient( context, resourcesHandler); ResourceGroup resourceGroup = ResourceGroupHelper.CreateResourceGroup( resourceManagementClient); ZoneScenarioTests.CreateZones( dnsClient, resourceGroup, zoneNames, resourceManagementClient); var listresponse = dnsClient.Zones.ListInResourceGroup(resourceGroup.Name); Assert.NotNull(listresponse); Assert.Equal(2, listresponse.Count()); Assert.True( listresponse.Any( zoneReturned => string.Equals(zoneNames[0], zoneReturned.Name)) && listresponse.Any( zoneReturned => string.Equals(zoneNames[1], zoneReturned.Name)), "The response of the List request does not meet expectations."); ZoneScenarioTests.DeleteZones( dnsClient, resourceGroup, zoneNames); } }
public DnsHelper(string subscriptionId) { var azureServiceTokenProvider = new AzureServiceTokenProvider(); var token = azureServiceTokenProvider.GetAccessTokenAsync("https://management.azure.com/").GetAwaiter().GetResult(); dnsManagementClient = new DnsManagementClient(new TokenCredentials(token)) { SubscriptionId = subscriptionId }; }
public static DnsManagementClient GetDnsManagementClient(IAzureDnsEnvironment model) { AuthenticationResult token = GetToken(model); var creds = new TokenCredentials(token.AccessToken); var dnsClient = new DnsManagementClient(model.ManagementEndpoint, creds); dnsClient.SubscriptionId = model.SubscriptionId.ToString(); return(dnsClient); }
public static ZoneCreateOrUpdateResponse CreateZone(DnsManagementClient dnsClient, string zoneName, string location, ResourceGroupExtended resourceGroup) { ZoneCreateOrUpdateResponse response = dnsClient.Zones.CreateOrUpdate( resourceGroup.Name, zoneName, new ZoneCreateOrUpdateParameters { Zone = new Microsoft.Azure.Management.Dns.Models.Zone { Location = location, Name = zoneName, ETag = null, Properties = new Microsoft.Azure.Management.Dns.Models.ZoneProperties { } } }); return response; }
public DnsZoneHelper(SubscriptionCloudCredentials credentials) { _client = new DnsManagementClient(credentials); }
private async void ReloadZones() { if (ActiveSubscription?.Length > 0 && ActiveResourceGroup != null) { _azureContext.Subscription.Id = Guid.Parse(ActiveSubscription); _dnsManagementClient = AzureSession.ClientFactory.CreateClient<DnsManagementClient>(_azureContext, AzureEnvironment.Endpoint.ResourceManager); Zones = new System.Collections.ObjectModel.ObservableCollection<Zone>((await _dnsManagementClient.Zones.ListZonesInResourceGroupAsync(_activeResourceGroup.Name, null)).Zones); if (Zones?.Count > 0) { this.ActiveZone = Zones[0]; } } }