Skip to content

Commit

Permalink
feat(azure-resources): Add DNS Record Sets (#10918)
Browse files Browse the repository at this point in the history

#### Summary
Fixes #10847
<!--
Explain what problem this PR addresses
-->

<!--
  • Loading branch information
yvardhineni committed May 31, 2023
1 parent adb89b6 commit 7c56926
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 1 deletion.
1 change: 1 addition & 0 deletions plugins/source/azure/docs/tables/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
- [azure_devhub_workflow](../../../../../website/tables/azure/azure_devhub_workflow.md)
- [azure_devops_pipeline_template_definitions](../../../../../website/tables/azure/azure_devops_pipeline_template_definitions.md)
- [azure_dns_zones](../../../../../website/tables/azure/azure_dns_zones.md)
- [azure_dns_record_sets](../../../../../website/tables/azure/azure_dns_record_sets.md)
- [azure_dnsresolver_dns_forwarding_rulesets](../../../../../website/tables/azure/azure_dnsresolver_dns_forwarding_rulesets.md)
- [azure_dnsresolver_dns_resolvers](../../../../../website/tables/azure/azure_dnsresolver_dns_resolvers.md)
- [azure_elastic_monitors](../../../../../website/tables/azure/azure_elastic_monitors.md)
Expand Down
71 changes: 71 additions & 0 deletions plugins/source/azure/resources/services/dns/record_sets.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package dns

import (
"context"
"encoding/json"
"net/http"

"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/dns/armdns"
"github.com/cloudquery/cloudquery/plugins/source/azure/client"
"github.com/cloudquery/plugin-sdk/v3/faker"
"github.com/cloudquery/plugin-sdk/v3/schema"
"github.com/cloudquery/plugin-sdk/v3/transformers"
"github.com/gorilla/mux"
)

func recordSets() *schema.Table {
return &schema.Table{
Name: "azure_dns_record_sets",
Resolver: fetchRecordSets,
Description: "https://learn.microsoft.com/en-us/rest/api/dns/record-sets/list-by-dns-zone?tabs=HTTP#recordset",
Multiplex: client.SubscriptionMultiplexRegisteredNamespace("azure_dns_record_sets", client.Namespacemicrosoft_network),
Transform: transformers.TransformWithStruct(&armdns.RecordSet{}, transformers.WithPrimaryKeys("ID")),
Columns: schema.ColumnList{client.SubscriptionID},
}
}

func fetchRecordSets(ctx context.Context, meta schema.ClientMeta, parent *schema.Resource, res chan<- any) error {
cl := meta.(*client.Client)
zone := parent.Item.(*armdns.Zone)
svc, err := armdns.NewRecordSetsClient(cl.SubscriptionId, cl.Creds, cl.Options)
if err != nil {
return err
}
group, err := client.ParseResourceGroup(*zone.ID)
if err != nil {
return err
}
pager := svc.NewListByDNSZonePager(group, *zone.Name, nil)
for pager.More() {
p, err := pager.NextPage(ctx)
if err != nil {
return err
}
res <- p.Value
}
return nil
}

func createMockRecordSets(router *mux.Router) error {
var item armdns.RecordSetsClientListByDNSZoneResponse
if err := faker.FakeObject(&item); err != nil {
return err
}

emptyStr := ""
item.NextLink = &emptyStr

router.HandleFunc("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/dnsZones/{zoneName}/recordsets", func(w http.ResponseWriter, r *http.Request) {
b, err := json.Marshal(&item)
if err != nil {
http.Error(w, "unable to marshal request: "+err.Error(), http.StatusBadRequest)
return
}
if _, err := w.Write(b); err != nil {
http.Error(w, "failed to write", http.StatusBadRequest)
return
}
})

return nil
}
3 changes: 3 additions & 0 deletions plugins/source/azure/resources/services/dns/zones.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ func Zones() *schema.Table {
Multiplex: client.SubscriptionMultiplexRegisteredNamespace("azure_dns_zones", client.Namespacemicrosoft_network),
Transform: transformers.TransformWithStruct(&armdns.Zone{}, transformers.WithPrimaryKeys("ID")),
Columns: schema.ColumnList{client.SubscriptionID},
Relations: []*schema.Table{
recordSets(),
},
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func createZones(router *mux.Router) error {
}
})

return nil
return createMockRecordSets(router)
}

func TestZones(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions website/pages/docs/plugins/sources/azure/tables.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions website/tables/azure/azure_dns_record_sets.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Table: azure_dns_record_sets

This table shows data for Azure DNS Record Sets.

https://learn.microsoft.com/en-us/rest/api/dns/record-sets/list-by-dns-zone?tabs=HTTP#recordset

The primary key for this table is **id**.

## Relations

This table depends on [azure_dns_zones](azure_dns_zones).

## Columns

| Name | Type |
| ------------- | ------------- |
|_cq_source_name|`utf8`|
|_cq_sync_time|`timestamp[us, tz=UTC]`|
|_cq_id|`uuid`|
|_cq_parent_id|`uuid`|
|subscription_id|`utf8`|
|etag|`utf8`|
|properties|`json`|
|id (PK)|`utf8`|
|name|`utf8`|
|type|`utf8`|
5 changes: 5 additions & 0 deletions website/tables/azure/azure_dns_zones.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ https://learn.microsoft.com/en-us/rest/api/dns/zones/list?tabs=HTTP#zone

The primary key for this table is **id**.

## Relations

The following tables depend on azure_dns_zones:
- [azure_dns_record_sets](azure_dns_record_sets)

## Columns

| Name | Type |
Expand Down

0 comments on commit 7c56926

Please sign in to comment.