-
Notifications
You must be signed in to change notification settings - Fork 501
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(azure-resources): Add DNS Record Sets (#10918)
#### Summary Fixes #10847 <!-- Explain what problem this PR addresses --> <!--
- Loading branch information
1 parent
adb89b6
commit 7c56926
Showing
7 changed files
with
108 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
71 changes: 71 additions & 0 deletions
71
plugins/source/azure/resources/services/dns/record_sets.go
This file contains 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,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 | ||
} |
This file contains 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 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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,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`| |
This file contains 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