Skip to content

Refactor DNS provider implementations to use CancellationToken for async methods#989

Merged
shibayan merged 3 commits intomasterfrom
fix-nullable
Mar 18, 2026
Merged

Refactor DNS provider implementations to use CancellationToken for async methods#989
shibayan merged 3 commits intomasterfrom
fix-nullable

Conversation

@shibayan
Copy link
Member

This pull request introduces several improvements and refactorings across the codebase, focusing on stricter nullability enforcement, improved cancellation support, and enhanced type safety. The most significant changes are the addition of cancellation token support to asynchronous methods, stricter nullability requirements for key models and options, and minor bug fixes and code simplifications.

Nullability and Type Safety Improvements:

  • Added <WarningsAsErrors>nullable</WarningsAsErrors> to all project files to enforce strict nullability checks during compilation. [1] [2] [3]
  • Updated models such as AcmeChallengeResult, CertificateItem, and DNS provider options to use required properties and non-nullable types, improving type safety and reducing the risk of null reference errors. [1] [2] [3] [4] [5]

Cancellation Token Support:

  • Added CancellationToken parameters to many async extension methods and function activities, ensuring that long-running operations can be cancelled gracefully. This includes DNS provider zone listing, HTTP client methods, and DNS challenge orchestration activities. [1] [2] [3] [4] [5] [6] [7] [8] [9]

Functional and Logical Updates:

  • Changed logic in orchestrators and activities to use strongly-typed enums (e.g., AcmeOrderStatuses.Ready instead of string literals), and improved input validation for certificate issuance. [1] [2] [3] [4]
  • Refined DNS challenge handling by ensuring only non-null zone lists are processed and by updating propagation delay calculations to use PropagationDelay.TotalSeconds. [1] [2] [3]

Minor Bug Fixes and Code Simplification:

  • Fixed a potential bug in SaveState by ensuring directory existence checks handle null or empty paths.
  • Simplified code in ContactsEqual and other minor refactorings for clarity and correctness. [1] [2] [3] [4]

These changes collectively improve code robustness, maintainability, and reliability, especially in asynchronous and distributed scenarios.

Close #913

…ync methods

- Updated all IDnsProvider implementations to include CancellationToken in ListZonesAsync, CreateTxtRecordAsync, and DeleteTxtRecordAsync methods.
- Changed PropagationSeconds property to PropagationDelay of type TimeSpan for better clarity.
- Refactored HTTP requests to use new async methods with CancellationToken support.
- Improved error handling in DeleteTxtRecordAsync methods across providers to ignore NotFound exceptions.
- Introduced new internal classes for TXT record parameters and domain pagination handling.
- Enhanced code readability and consistency across different DNS provider implementations.
@shibayan shibayan self-assigned this Mar 15, 2026
@shibayan shibayan added the enhancement New feature or request label Mar 15, 2026
Copilot AI review requested due to automatic review settings March 15, 2026 17:54
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors DNS provider implementations and orchestration code to support cancellation-aware async operations, while tightening nullability/type-safety across models and options (and addressing renewal/DNS-challenge robustness for #913).

Changes:

  • Update IDnsProvider to use TimeSpan PropagationDelay and add CancellationToken parameters across DNS provider async APIs.
  • Enforce stricter nullability/type-safety via required properties and WarningsAsErrors for nullable warnings.
  • Improve DNS challenge orchestration and provider implementations (including “record not found” handling and enum-based ACME status checks).

Reviewed changes

Copilot reviewed 32 out of 32 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
src/Acmebot.App/Providers/IDnsProvider.cs Add CancellationToken + PropagationDelay API.
src/Acmebot.App/Providers/AkamaiEdgeDnsProvider.cs Implement new provider interface + cancellation.
src/Acmebot.App/Providers/AzureDnsProvider.cs Implement new provider interface + cancellation.
src/Acmebot.App/Providers/AzurePrivateDnsProvider.cs Implement new provider interface + cancellation; adjust visibility.
src/Acmebot.App/Providers/CloudflareProvider.cs Refactor Cloudflare client, paging, cancellation, and record ops.
src/Acmebot.App/Providers/CustomDnsProvider.cs Switch to System.Net.Http.Json + cancellation + 404 ignore.
src/Acmebot.App/Providers/DnsMadeEasyProvider.cs Refactor API client to Json helpers + cancellation + new models.
src/Acmebot.App/Providers/DnsZone.cs Strengthen equality/hash semantics for zones.
src/Acmebot.App/Providers/GandiLiveDnsProvider.cs Add cancellation + improved null handling in API responses.
src/Acmebot.App/Providers/GoDaddyProvider.cs Add cancellation + async paging for domains; ignore 404 deletes.
src/Acmebot.App/Providers/GoogleDnsProvider.cs Add cancellation support to Google DNS calls.
src/Acmebot.App/Providers/Route53Provider.cs Add cancellation support; safer delete behavior.
src/Acmebot.App/Providers/TransIpProvider.cs Add cancellation support; move to System.Text.Json + token handling tweaks.
src/Acmebot.App/Options/CloudflareOptions.cs Make option properties required (non-nullable).
src/Acmebot.App/Options/DnsMadeEasyOptions.cs Make option properties required (non-nullable).
src/Acmebot.App/Options/GandiLiveDnsOptions.cs Make option properties required (non-nullable).
src/Acmebot.App/Options/GoDaddyOptions.cs Make option properties required (non-nullable).
src/Acmebot.App/Options/GoogleDnsOptions.cs Make option properties required (non-nullable).
src/Acmebot.App/Options/Route53Options.cs Make option properties required (non-nullable).
src/Acmebot.App/Options/TransIpOptions.cs Make option properties required (non-nullable).
src/Acmebot.App/Models/AcmeChallengeResult.cs Tighten types (Uri, required) for challenge payloads.
src/Acmebot.App/Models/CertificateItem.cs Tighten types (required) for certificate model.
src/Acmebot.App/Functions/Orchestration/DnsChallengeActivities.cs Pass cancellation through DNS challenge activities; handle null zone lists.
src/Acmebot.App/Functions/Orchestration/CertificateIssuanceOrchestrator.cs Use typed ACME statuses + extra input validation.
src/Acmebot.App/Functions/Orchestration/AcmeOrderActivities.cs Use Uri directly for challenge operations.
src/Acmebot.App/Functions/Orchestration/RenewCertificates.cs Null-safety simplification for logging.
src/Acmebot.App/Extensions/DnsProvidersExtensions.cs Add cancellation + make zone list nullable on provider failures.
src/Acmebot.App/Extensions/HttpClientExtensions.cs Add CancellationToken plumbing to extension methods.
src/Acmebot.App/Acme/AcmeClientFactory.cs Minor refactors + safer directory creation in state persistence.
src/Acmebot.App/Acmebot.App.csproj Treat nullable warnings as errors.
src/Acmebot.Acme/Acmebot.Acme.csproj Treat nullable warnings as errors.
src/Acmebot.Acme.Tests/Acmebot.Acme.Tests.csproj Treat nullable warnings as errors.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

@shibayan shibayan merged commit c774c3c into master Mar 18, 2026
4 checks passed
@shibayan shibayan deleted the fix-nullable branch March 18, 2026 15:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

v4 - Renew Certificate fails when there is no challenge record to delete

2 participants