feat: add DNS provider Validate method with early credential checking#182
Draft
viniciusdc wants to merge 2 commits into
Draft
feat: add DNS provider Validate method with early credential checking#182viniciusdc wants to merge 2 commits into
viniciusdc wants to merge 2 commits into
Conversation
Addresses issues #111 and #137 with a unified design. ## What changed ### pkg/dnsprovider/provider.go - Add ValidateOptions struct (CheckCreds bool field) - Add Validate(ctx, domain, dnsConfig, opts) method to DNSProvider interface ### pkg/config/config.go - Add DNSConfig.Single() helper returning the sole provider name + config map ### pkg/dnsprovider/cloudflare/provider.go - Implement Validate with two phases: - Config (always): zone_name present, domain within zone - Creds (CheckCreds=true): token set, zone accessible via API ### cmd/nic/validate.go - Add --check-creds flag - Validate DNS config (and optionally credentials) when dns block is present ### cmd/nic/deploy.go - Add validateDNSCredentials shared helper - Call it early in runDeploy, before any tofu operations ### cmd/nic/destroy.go - Call validateDNSCredentials early in runDestroy, before any tofu operations ### pkg/dnsprovider/cloudflare/provider_test.go - Add TestValidate with 9 table-driven cases: missing zone_name, nil config, domain outside zone, domain equal to zone, missing token, inaccessible zone, valid config-only, valid with creds
Contributor
Author
Manual smoke test — real Hetzner + Cloudflare deploymentTested against a live deployment config (Hetzner provider, Cloudflare DNS, domain within a real zone) with the binary built from this branch. 1. Offline config-only validate (default)
2. Config + live credential check (
|
Contributor
Author
|
I want to hold on this ultill #6 gets merged, since that will defined some standards |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
DNS credential errors (missing
CLOUDFLARE_API_TOKEN, badzone_name) were only caught deep in the deploy flow — after infrastructure was already provisioned. Thenic validatecommand had no DNS awareness at all.Supersedes and closes #111 and closes #137 with a unified design.
Design
Separation of concerns (addresses both issues)
nic validate)zone_namepresent, domain within zone--check-credsor deploy/destroyThis keeps
nic validatefast and offline-friendly by default (addresses #137), whilenic deploy/nic destroyalways do the full check before any tofu operations (addresses #111).Changes
pkg/dnsprovider/provider.goValidateOptionsstruct withCheckCreds boolValidate(ctx, domain, dnsConfig, opts)to theDNSProviderinterfacepkg/config/config.goDNSConfig.Single()helper — returns the sole provider name + config map, eliminating repeated map-iteration in CLI handlerspkg/dnsprovider/cloudflare/provider.goValidate: composes existingextractCloudflareConfig,getAPIToken,getClient, andResolveZoneIDinto the two-phase checkcmd/nic/validate.go--check-credsflagdnsblock is present in configcmd/nic/deploy.govalidateDNSCredentialsshared helper (reused by destroy)runDeploy, before any tofu operations, withCheckCreds: truecmd/nic/destroy.govalidateDNSCredentialsearly inrunDestroy, before any tofu operationspkg/dnsprovider/cloudflare/provider_test.goTestValidatewith 9 table-driven cases: missingzone_name, nil config, domain outside zone, domain equal to zone, missing token, inaccessible zone, valid config-only, valid with credsUsage
Testing
All 605 existing tests pass; 9 new tests added for
Validate.