Skip to content

Conversation

@ciaran-finnegan
Copy link
Contributor

@ciaran-finnegan ciaran-finnegan commented Mar 9, 2025

Add DNSSimple provider integration

This PR adds a new provider for DNSSimple, enabling users to enumerate DNS records from their DNSSimple accounts.

Changes

  • Implemented the DNSSimple provider with DNS record retrieval
  • Added proper authentication using the DNSSimple API token
  • Updated provider factory to include the new provider
  • Added documentation in PROVIDERS.md with configuration examples

Testing

To test this provider:

  • Obtain a DNSSimple API token with read access to domains
  • Configure the provider using either environment variables or direct configuration:
DNSSIMPLE_API_TOKEN
  • Run cloudlist to enumerate DNS records from your DNSSimple account
./cloudlist -pc provider-config.yaml -p dnssimple

  _______             _____     __ 
 / ___/ /__  __ _____/ / (_)__ / /_
/ /__/ / _ \/ // / _  / / (_-</ __/
\___/_/\___/\_,_/\_,_/_/_/___/\__/ 

                projectdiscovery.io

[INF] Current cloudlist version 1.2.1 (latest)
[INF] Listing assets from provider: dnssimple services: dns id: main
..redacted
[INF] Found 2 Hosts and 16 IP Addresses for dnssimple (main)

Dependencies

Added the official DNSSimple Go client: github.com/dnsimple/dnsimple-go/dnsimple

Summary by CodeRabbit

  • New Features

    • Introduced integration for the DNSSimple provider, enabling enhanced DNS management capabilities.
  • Documentation

    • Updated configuration guides to include setup instructions and necessary API token details for the DNSSimple provider.

@ehsandeep ehsandeep requested a review from Copilot March 9, 2025 18:05
Copy link

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.

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.

@ehsandeep ehsandeep requested a review from dogancanbakir March 27, 2025 14:37
@dogancanbakir
Copy link
Member

couldn't test it because of the paywall but code lgtm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 28, 2025

Walkthrough

This pull request introduces several configuration and code updates. The .gitignore file now excludes new files, and the PROVIDERS.md documentation has been expanded to include a DNSSimple provider configuration section. New indirect dependencies have been added to the Go module, and the provider management in the inventory package now supports a DNSSimple provider. Two new files under the DNSSimple provider package implement the functionality required to retrieve DNS resources.

Changes

File(s) Change Summary
.gitignore Added three new entries: .env, provider-config.yaml, and cloudlist; retained the existing dist entry.
PROVIDERS.md Added a new configuration section for DNSSimple with a YAML snippet including provider name, optional identifier, and required API token.
go.mod Added two indirect dependencies: github.com/dnsimple/dnsimple-go v1.7.0 and github.com/shopspring/decimal v1.3.1.
pkg/inventory/inventory.go Updated the nameToProvider function to include a new case for the DNSSimple provider.
pkg/providers/dnssimple/...(dns.go & dnssimple.go) Introduced two new files implementing the DNSSimple provider, with methods for handling DNS resource retrieval and provider configuration.

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
Loading

Poem

I’m a nimble little bunny in the codeyard so bright,
Hopping through new entries that keep the bugs out of sight.
DNSSimple joins our garden with DNS fields to explore,
Dependencies and docs updated—oh, there’s always more!
With loads of carrots (and features) causing thrills each day,
My code hops in joy, dancing all along the way!
🐇💻 Hop on, developers!

✨ Finishing Touches
  • 📝 Generate Docstrings

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Member

@Mzack9999 Mzack9999 left a 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

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 integration

The 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 Providers map (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 configuration

The 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 resource

Your 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 listings

The DNSSimple API likely implements pagination for accounts with many domains. While using DomainListOptions is 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 failures

When 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 retrieval

The 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 configuration

The 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 calls

Before 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

📥 Commits

Reviewing files that changed from the base of the PR and between 4890312 and 250ff90.

⛔ Files ignored due to path filters (1)
  • go.sum is 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 .gitignore

The new entries to .gitignore are suitable for this type of project:

  • .env - For securely storing API tokens including the DNSSimple token
  • provider-config.yaml - For local configuration files
  • cloudlist - For the built binary

These 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 integration

The addition of these indirect dependencies is appropriate:

  • github.com/dnsimple/dnsimple-go - Official DNSSimple Go client library
  • github.com/shopspring/decimal - Supporting dependency for the DNSSimple client

Both 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 provider

Correctly added import for the new DNSSimple provider package.

pkg/providers/dnssimple/dnssimple.go (1)

96-110: LGTM: Resources method properly aggregates resources from different services

The 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.

@ehsandeep ehsandeep merged commit 0f83692 into projectdiscovery:dev Mar 29, 2025
9 checks passed
@ehsandeep ehsandeep removed their request for review March 29, 2025 12:17
@ehsandeep ehsandeep mentioned this pull request Mar 29, 2025
@ehsandeep ehsandeep linked an issue Mar 29, 2025 that may be closed by this pull request
@coderabbitai coderabbitai bot mentioned this pull request Aug 12, 2025
visnetodev pushed a commit to visnetotest/cloudlist that referenced this pull request Dec 7, 2025
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DNSSimple provider

4 participants