-
Notifications
You must be signed in to change notification settings - Fork 123
Ovh dns provider #696
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
Open
ysokolovsky
wants to merge
3
commits into
projectdiscovery:dev
Choose a base branch
from
ysokolovsky:ovh-dns-provider
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Ovh dns provider #696
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| package ovh | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "strings" | ||
|
|
||
| "github.com/ovh/go-ovh/ovh" | ||
| "github.com/projectdiscovery/cloudlist/pkg/schema" | ||
| ) | ||
|
|
||
| type dnsProvider struct { | ||
| id string | ||
| client *ovh.Client | ||
| } | ||
|
|
||
| func (d *dnsProvider) name() string { return "dns" } | ||
|
|
||
| type ovhRecord struct { | ||
| ID int64 `json:"id"` | ||
| FieldType string `json:"fieldType"` | ||
| SubDomain string `json:"subDomain"` | ||
| Target string `json:"target"` | ||
| TTL int `json:"ttl"` | ||
| } | ||
|
|
||
| // GetResource returns all DNS resources from OVH | ||
| func (d *dnsProvider) GetResource(ctx context.Context) (*schema.Resources, error) { | ||
| list := schema.NewResources() | ||
|
|
||
| var zones []string | ||
| if err := d.client.GetWithContext(ctx, "/domain/zone", &zones); err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| recordTypes := []string{"A", "AAAA", "CNAME"} | ||
| for _, zone := range zones { | ||
| for _, rt := range recordTypes { | ||
| var ids []int64 | ||
| path := fmt.Sprintf("/domain/zone/%s/record?fieldType=%s", zone, rt) | ||
| if err := d.client.GetWithContext(ctx, path, &ids); err != nil { | ||
| continue | ||
| } | ||
| for _, id := range ids { | ||
| var rec ovhRecord | ||
| if err := d.client.GetWithContext(ctx, fmt.Sprintf("/domain/zone/%s/record/%d", zone, id), &rec); err != nil { | ||
| continue | ||
| } | ||
|
|
||
| name := strings.TrimSpace(rec.SubDomain) | ||
| var fqdn string | ||
| if name == "" || name == "@" { | ||
| fqdn = zone | ||
| } else { | ||
| fqdn = name + "." + zone | ||
| } | ||
|
|
||
| // Append DNS name (public) | ||
| list.Append(&schema.Resource{ | ||
| Public: true, | ||
| Provider: providerName, | ||
| DNSName: fqdn, | ||
| ID: d.id, | ||
| Service: d.name(), | ||
| }) | ||
|
|
||
| // For A/AAAA also append IP resource; skip CNAME target to avoid duplicates | ||
| res := &schema.Resource{ | ||
| Public: true, | ||
| Provider: providerName, | ||
| ID: d.id, | ||
| Service: d.name(), | ||
| } | ||
|
|
||
| if strings.ToUpper(rec.FieldType) == "A" { | ||
| res.PublicIPv4 = rec.Target | ||
| } else if strings.ToUpper(rec.FieldType) == "AAAA" { | ||
| res.PublicIPv6 = rec.Target | ||
| } | ||
|
|
||
| list.Append(res) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return list, nil | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| package ovh | ||
|
|
||
| import ( | ||
| "context" | ||
| "net/http" | ||
| "strings" | ||
| "time" | ||
|
|
||
| "github.com/ovh/go-ovh/ovh" | ||
| "github.com/projectdiscovery/cloudlist/pkg/schema" | ||
| ) | ||
|
|
||
| const providerName = "ovh" | ||
|
|
||
| var Services = []string{"dns"} | ||
|
|
||
| type Provider struct { | ||
| id string | ||
| client *ovh.Client | ||
| httpClient *http.Client | ||
| services schema.ServiceMap | ||
| } | ||
|
|
||
| func New(options schema.OptionBlock) (*Provider, error) { | ||
| id, _ := options.GetMetadata("id") | ||
|
|
||
| // service selection | ||
| supported := map[string]struct{}{"dns": {}} | ||
| services := make(schema.ServiceMap) | ||
| if ss, ok := options.GetMetadata("services"); ok { | ||
| for _, s := range strings.Split(ss, ",") { | ||
| s = strings.TrimSpace(s) | ||
| if _, ok := supported[s]; ok { | ||
| services[s] = struct{}{} | ||
| } | ||
| } | ||
| } | ||
| if len(services) == 0 { | ||
| for _, s := range Services { | ||
| services[s] = struct{}{} | ||
| } | ||
| } | ||
|
|
||
| // OVH endpoint (default ovh-eu) | ||
| endpoint := "ovh-eu" | ||
| if ep, ok := options.GetMetadata("endpoint"); ok && ep != "" { | ||
| endpoint = ep | ||
| } | ||
|
|
||
| // Credentials | ||
| appKey, ok := options.GetMetadata("application_key") | ||
| if !ok || appKey == "" { | ||
| return nil, &schema.ErrNoSuchKey{Name: "application_key"} | ||
| } | ||
| appSecret, ok := options.GetMetadata("application_secret") | ||
| if !ok || appSecret == "" { | ||
| return nil, &schema.ErrNoSuchKey{Name: "application_secret"} | ||
| } | ||
| consumerKey, ok := options.GetMetadata("consumer_key") | ||
| if !ok || consumerKey == "" { | ||
| return nil, &schema.ErrNoSuchKey{Name: "consumer_key"} | ||
| } | ||
|
|
||
| cli, err := ovh.NewClient(endpoint, appKey, appSecret, consumerKey) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| httpClient := &http.Client{Timeout: 30 * time.Second} | ||
| cli.Client = httpClient | ||
|
|
||
| return &Provider{ | ||
| id: id, | ||
| client: cli, | ||
| httpClient: httpClient, | ||
| services: services, | ||
| }, nil | ||
| } | ||
|
|
||
| func (p *Provider) Name() string { return providerName } | ||
| func (p *Provider) ID() string { return p.id } | ||
| func (p *Provider) Services() []string { return p.services.Keys() } | ||
|
|
||
| func (p *Provider) Resources(ctx context.Context) (*schema.Resources, error) { | ||
| out := schema.NewResources() | ||
| if p.services.Has("dns") { | ||
| d := &dnsProvider{id: p.id, client: p.client} | ||
| r, err := d.GetResource(ctx) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| out.Merge(r) | ||
| } | ||
| return out, nil | ||
| } |
Oops, something went wrong.
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.
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.
🛠️ Refactor suggestion
Avoid appending empty IP resources for CNAME records.
The code currently appends an IP resource even for CNAME records, resulting in an empty resource with no IP addresses set. This creates unnecessary entries in the resource list.
Apply this diff to skip appending empty IP resources:
📝 Committable suggestion
🤖 Prompt for AI Agents