-
Notifications
You must be signed in to change notification settings - Fork 123
DNSSimple provider #665
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DNSSimple provider #665
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR Overview
This pull request introduces a new provider integration for DNSSimple, enabling users to retrieve DNS records from their DNSSimple accounts.
- Implemented a new DNSSimple provider with proper authentication and DNS resource retrieval
- Added the DNSSimple provider to the provider factory and updated the documentation with configuration examples
Reviewed Changes
| File | Description |
|---|---|
| pkg/providers/dnssimple/dnssimple.go | Implements the core DNSSimple provider with authentication and account retrieval |
| pkg/providers/dnssimple/dns.go | Provides the DNS resource extraction logic for DNSSimple |
| PROVIDERS.md | Updates documentation with the DNSSimple provider configuration examples |
| pkg/inventory/inventory.go | Includes DNSSimple in the provider mapping for inventory collection |
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
|
couldn't test it because of the paywall but code lgtm |
WalkthroughThis pull request introduces several configuration and code updates. The Changes
Sequence Diagram(s)sequenceDiagram
participant I as Inventory System
participant F as Provider Factory (nameToProvider)
participant P as DNSSimple Provider
participant C as DNSimple Client
I->>F: Request provider instance ("dnssimple")
F->>P: Instantiate DNSSimple provider
I->>P: Call Resources() method for DNS retrieval
P->>C: Initialize & authenticate with API token
P->>C: List domains associated with the account
C-->>P: Return domains
loop For each domain
P->>C: Fetch zone records (A, CNAME, AAAA)
C-->>P: Return DNS records
end
P->>I: Return aggregated DNS resources
Poem
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Mzack9999
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm - tested with apikey
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (8)
pkg/inventory/inventory.go (1)
132-133: LGTM: DNSSimple provider integrationThe new case properly integrates the DNSSimple provider into the provider factory. The implementation correctly passes the configuration block to the DNSSimple provider's New function.
Consider updating the
Providersmap (lines 53-75) to include DNSSimple services for consistency with other providers. This would allow users to list available DNSSimple services.var Providers = map[string][]string{ + "dnssimple": dnssimple.Services, // other providers... }PROVIDERS.md (1)
410-428: LGTM: Well-documented DNSSimple provider configurationThe DNSSimple provider documentation follows the same format as other providers and includes:
- Clear configuration example
- Explanation of required credentials
- References to DNSSimple's documentation
Format URLs as markdown links for consistency with documentation standards:
References - -1. https://developer.dnsimple.com/v2/ -2. https://support.dnsimple.com/articles/api-access-token/ +1. [DNSSimple API v2 Documentation](https://developer.dnsimple.com/v2/) +2. [DNSSimple API Access Token Guide](https://support.dnsimple.com/articles/api-access-token/)🧰 Tools
🪛 markdownlint-cli2 (0.17.2)
426-426: Bare URL used
null(MD034, no-bare-urls)
427-427: Bare URL used
null(MD034, no-bare-urls)
pkg/providers/dnssimple/dns.go (3)
44-46: Consider handling CNAME record content in the resourceYour filtering includes CNAME records, but the code doesn't capture or represent the CNAME target value. While you're correctly handling A and AAAA records by setting their IP addresses, CNAME records contain a hostname rather than an IP, which isn't being stored in the resource.
Consider adding specific handling for CNAME records:
// Set IP addresses based on record type if record.Type == "A" { resource.PublicIPv4 = record.Content } else if record.Type == "AAAA" { resource.PublicIPv6 = record.Content + } else if record.Type == "CNAME" { + // Store CNAME target in a field or perhaps as metadata + // Depending on schema.Resource capabilities, you might need to: + // resource.Metadata["cname_target"] = record.Content }
26-35: Consider handling pagination for domain listingsThe DNSSimple API likely implements pagination for accounts with many domains. While using
DomainListOptionsis correct, there doesn't appear to be any handling for retrieving results beyond the first page.Consider implementing pagination handling:
// List all domains - using DomainListOptions instead of ListOptions domainOptions := &dnsimple.DomainListOptions{} - domains, err := d.client.Domains.ListDomains(ctx, d.account, domainOptions) - if err != nil { - return nil, err - } + var allDomains []dnsimple.Domain + + // Handle pagination + for { + domains, err := d.client.Domains.ListDomains(ctx, d.account, domainOptions) + if err != nil { + return nil, err + } + + allDomains = append(allDomains, domains.Data...) + + // Check if we've reached the last page + if domains.Pagination.CurrentPage >= domains.Pagination.TotalPages { + break + } + + // Set up for next page + domainOptions.Page = domains.Pagination.NextPage + }Similarly, you may want to implement the same pagination handling for the zone records retrieval.
37-40: Add error context when logging record retrieval failuresWhen logging errors for record retrieval failures, it would be helpful to include more context about why the failure occurred.
zoneRecords, err := d.client.Zones.ListRecords(ctx, d.account, domain.Name, recordOptions) if err != nil { - log.Printf("Could not get records for domain %s: %s\n", domain.Name, err) + log.Printf("Could not get records for domain %s: %v (account: %s)\n", domain.Name, err, d.account) continue }pkg/providers/dnssimple/dnssimple.go (3)
80-91: Improve error handling in account ID retrievalThe account ID retrieval and error handling could be clarified and improved.
The current code properly checks for authentication errors and empty account information, but there's a blank line in the middle of the error return block (line 88-89) which should be removed. Also, consider providing more context in your error message about what the user should check.
// Get and store account ID whoamiResponse, err := client.Identity.Whoami(context.Background()) if err != nil { - return nil, errorutil.NewWithErr(err).Msgf("failed to authenticate with DNSSimple") + return nil, errorutil.NewWithErr(err).Msgf("failed to authenticate with DNSSimple: check your API token validity") } if whoamiResponse.Data.Account == nil { - return nil, errorutil.New("no account information found in DNSSimple response") - + return nil, errorutil.New("no account information found in DNSSimple response: your token may not have account access") } provider.account = fmt.Sprintf("%d", whoamiResponse.Data.Account.ID)
53-53: Consider adding client timeout configurationThe DNSSimple client is created without explicit timeout settings, which could lead to long-running connections in case of API issues.
// Set up the client - client := dnsimple.NewClient(dnsimple.StaticTokenHTTPClient(context.Background(), token)) + // Create context with timeout + clientCtx, cancel := context.WithTimeout(context.Background(), 30*time.Second) + defer cancel() + client := dnsimple.NewClient(dnsimple.StaticTokenHTTPClient(clientCtx, token))Don't forget to add the time package to your imports:
import ( "context" "fmt" "strings" + "time" "github.com/dnsimple/dnsimple-go/dnsimple" // other imports... )
44-94: Consider validating the token format before making API callsBefore making API calls, it would be beneficial to validate that the token format matches DNSSimple's requirements to provide better error messages.
func New(options schema.OptionBlock) (*Provider, error) { token, ok := options.GetMetadata(apiToken) if !ok { return nil, &schema.ErrNoSuchKey{Name: apiToken} } + // Basic validation of token format + token = strings.TrimSpace(token) + if token == "" { + return nil, errorutil.New("empty DNSSimple API token provided") + } id, _ := options.GetMetadata("id") // Rest of the function... }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
go.sumis excluded by!**/*.sum
📒 Files selected for processing (6)
.gitignore(1 hunks)PROVIDERS.md(1 hunks)go.mod(2 hunks)pkg/inventory/inventory.go(2 hunks)pkg/providers/dnssimple/dns.go(1 hunks)pkg/providers/dnssimple/dnssimple.go(1 hunks)
🧰 Additional context used
🧬 Code Definitions (3)
pkg/inventory/inventory.go (1)
pkg/providers/dnssimple/dnssimple.go (1)
New(45-94)
pkg/providers/dnssimple/dns.go (1)
pkg/providers/dnssimple/dnssimple.go (1)
Provider(22-27)
pkg/providers/dnssimple/dnssimple.go (1)
pkg/inventory/inventory.go (1)
New(36-51)
🪛 markdownlint-cli2 (0.17.2)
PROVIDERS.md
426-426: Bare URL used
null
(MD034, no-bare-urls)
427-427: Bare URL used
null
(MD034, no-bare-urls)
⏰ Context from checks skipped due to timeout of 90000ms (6)
- GitHub Check: Test Builds (1.22.x, macOS-latest)
- GitHub Check: Lint Test
- GitHub Check: Test Builds (1.22.x, windows-latest)
- GitHub Check: Test Builds (1.22.x, ubuntu-latest)
- GitHub Check: Analyze (go)
- GitHub Check: release-test
🔇 Additional comments (4)
.gitignore (1)
4-6: Appropriate additions to .gitignoreThe new entries to .gitignore are suitable for this type of project:
.env- For securely storing API tokens including the DNSSimple tokenprovider-config.yaml- For local configuration filescloudlist- For the built binaryThese additions align with security best practices by preventing sensitive credentials and local artifacts from being committed to source control.
go.mod (1)
199-199: LGTM: Required dependencies for DNSSimple integrationThe addition of these indirect dependencies is appropriate:
github.com/dnsimple/dnsimple-go- Official DNSSimple Go client librarygithub.com/shopspring/decimal- Supporting dependency for the DNSSimple clientBoth dependencies are properly versioned and marked as indirect.
Also applies to: 208-208
pkg/inventory/inventory.go (1)
14-14: LGTM: Import for the new DNSSimple providerCorrectly added import for the new DNSSimple provider package.
pkg/providers/dnssimple/dnssimple.go (1)
96-110: LGTM: Resources method properly aggregates resources from different servicesThe Resources method is well-structured and follows the pattern of checking for requested services and aggregating resources from multiple sources. The error handling is appropriate, and the code is extensible for future service types.
* feat(provider): add DNSSimple DNS provider integration (untested) * fix(dnssimple): resolve API client integration issues * . --------- Co-authored-by: Ciaran Finnegan <ciaran.finnegan@cmd.com.au> Co-authored-by: Mzack9999 <mzack9999@protonmail.com>
Add DNSSimple provider integration
This PR adds a new provider for DNSSimple, enabling users to enumerate DNS records from their DNSSimple accounts.
Changes
Testing
To test this provider:
Dependencies
Added the official DNSSimple Go client: github.com/dnsimple/dnsimple-go/dnsimple
Summary by CodeRabbit
New Features
Documentation