From b704533792944705b375cdf205bd1cd3e69de92f Mon Sep 17 00:00:00 2001 From: hc-github-team-tf-azure <> Date: Wed, 10 Jul 2024 09:22:12 +0000 Subject: [PATCH] Updating based on ea653c3e --- .../privatedns/2024-06-01/client.go | 46 +++ .../2024-06-01/privatezones/README.md | 117 ++++++ .../2024-06-01/privatezones/client.go | 26 ++ .../2024-06-01/privatezones/constants.go | 63 ++++ .../privatezones/id_privatednszone.go | 130 +++++++ .../privatezones/id_privatednszone_test.go | 282 +++++++++++++++ .../privatezones/method_createorupdate.go | 108 ++++++ .../2024-06-01/privatezones/method_delete.go | 99 +++++ .../2024-06-01/privatezones/method_get.go | 54 +++ .../2024-06-01/privatezones/method_list.go | 134 +++++++ .../method_listbyresourcegroup.go | 134 +++++++ .../2024-06-01/privatezones/method_update.go | 103 ++++++ .../privatezones/model_privatezone.go | 14 + .../model_privatezoneproperties.go | 15 + .../2024-06-01/privatezones/predicates.go | 37 ++ .../2024-06-01/privatezones/version.go | 12 + .../2024-06-01/recordsets/README.md | 128 +++++++ .../2024-06-01/recordsets/client.go | 26 ++ .../2024-06-01/recordsets/constants.go | 69 ++++ .../recordsets/id_privatednszone.go | 130 +++++++ .../recordsets/id_privatednszone_test.go | 282 +++++++++++++++ .../2024-06-01/recordsets/id_privatezone.go | 146 ++++++++ .../recordsets/id_privatezone_test.go | 312 ++++++++++++++++ .../2024-06-01/recordsets/id_recordtype.go | 154 ++++++++ .../recordsets/id_recordtype_test.go | 342 ++++++++++++++++++ .../recordsets/method_createorupdate.go | 92 +++++ .../2024-06-01/recordsets/method_delete.go | 76 ++++ .../2024-06-01/recordsets/method_get.go | 54 +++ .../2024-06-01/recordsets/method_list.go | 137 +++++++ .../recordsets/method_listbytype.go | 137 +++++++ .../2024-06-01/recordsets/method_update.go | 87 +++++ .../2024-06-01/recordsets/model_aaaarecord.go | 8 + .../2024-06-01/recordsets/model_arecord.go | 8 + .../recordsets/model_cnamerecord.go | 8 + .../2024-06-01/recordsets/model_mxrecord.go | 9 + .../2024-06-01/recordsets/model_ptrrecord.go | 8 + .../2024-06-01/recordsets/model_recordset.go | 12 + .../recordsets/model_recordsetproperties.go | 19 + .../2024-06-01/recordsets/model_soarecord.go | 14 + .../2024-06-01/recordsets/model_srvrecord.go | 11 + .../2024-06-01/recordsets/model_txtrecord.go | 8 + .../2024-06-01/recordsets/predicates.go | 32 ++ .../2024-06-01/recordsets/version.go | 12 + .../2024-06-01/virtualnetworklinks/README.md | 99 +++++ .../2024-06-01/virtualnetworklinks/client.go | 26 ++ .../virtualnetworklinks/constants.go | 145 ++++++++ .../virtualnetworklinks/id_privatednszone.go | 130 +++++++ .../id_privatednszone_test.go | 282 +++++++++++++++ .../id_virtualnetworklink.go | 139 +++++++ .../id_virtualnetworklink_test.go | 327 +++++++++++++++++ .../method_createorupdate.go | 108 ++++++ .../virtualnetworklinks/method_delete.go | 99 +++++ .../virtualnetworklinks/method_get.go | 54 +++ .../virtualnetworklinks/method_list.go | 133 +++++++ .../virtualnetworklinks/method_update.go | 103 ++++++ .../virtualnetworklinks/model_subresource.go | 8 + .../model_virtualnetworklink.go | 14 + .../model_virtualnetworklinkproperties.go | 12 + .../virtualnetworklinks/predicates.go | 37 ++ .../2024-06-01/virtualnetworklinks/version.go | 12 + 60 files changed, 5423 insertions(+) create mode 100644 resource-manager/privatedns/2024-06-01/client.go create mode 100644 resource-manager/privatedns/2024-06-01/privatezones/README.md create mode 100644 resource-manager/privatedns/2024-06-01/privatezones/client.go create mode 100644 resource-manager/privatedns/2024-06-01/privatezones/constants.go create mode 100644 resource-manager/privatedns/2024-06-01/privatezones/id_privatednszone.go create mode 100644 resource-manager/privatedns/2024-06-01/privatezones/id_privatednszone_test.go create mode 100644 resource-manager/privatedns/2024-06-01/privatezones/method_createorupdate.go create mode 100644 resource-manager/privatedns/2024-06-01/privatezones/method_delete.go create mode 100644 resource-manager/privatedns/2024-06-01/privatezones/method_get.go create mode 100644 resource-manager/privatedns/2024-06-01/privatezones/method_list.go create mode 100644 resource-manager/privatedns/2024-06-01/privatezones/method_listbyresourcegroup.go create mode 100644 resource-manager/privatedns/2024-06-01/privatezones/method_update.go create mode 100644 resource-manager/privatedns/2024-06-01/privatezones/model_privatezone.go create mode 100644 resource-manager/privatedns/2024-06-01/privatezones/model_privatezoneproperties.go create mode 100644 resource-manager/privatedns/2024-06-01/privatezones/predicates.go create mode 100644 resource-manager/privatedns/2024-06-01/privatezones/version.go create mode 100644 resource-manager/privatedns/2024-06-01/recordsets/README.md create mode 100644 resource-manager/privatedns/2024-06-01/recordsets/client.go create mode 100644 resource-manager/privatedns/2024-06-01/recordsets/constants.go create mode 100644 resource-manager/privatedns/2024-06-01/recordsets/id_privatednszone.go create mode 100644 resource-manager/privatedns/2024-06-01/recordsets/id_privatednszone_test.go create mode 100644 resource-manager/privatedns/2024-06-01/recordsets/id_privatezone.go create mode 100644 resource-manager/privatedns/2024-06-01/recordsets/id_privatezone_test.go create mode 100644 resource-manager/privatedns/2024-06-01/recordsets/id_recordtype.go create mode 100644 resource-manager/privatedns/2024-06-01/recordsets/id_recordtype_test.go create mode 100644 resource-manager/privatedns/2024-06-01/recordsets/method_createorupdate.go create mode 100644 resource-manager/privatedns/2024-06-01/recordsets/method_delete.go create mode 100644 resource-manager/privatedns/2024-06-01/recordsets/method_get.go create mode 100644 resource-manager/privatedns/2024-06-01/recordsets/method_list.go create mode 100644 resource-manager/privatedns/2024-06-01/recordsets/method_listbytype.go create mode 100644 resource-manager/privatedns/2024-06-01/recordsets/method_update.go create mode 100644 resource-manager/privatedns/2024-06-01/recordsets/model_aaaarecord.go create mode 100644 resource-manager/privatedns/2024-06-01/recordsets/model_arecord.go create mode 100644 resource-manager/privatedns/2024-06-01/recordsets/model_cnamerecord.go create mode 100644 resource-manager/privatedns/2024-06-01/recordsets/model_mxrecord.go create mode 100644 resource-manager/privatedns/2024-06-01/recordsets/model_ptrrecord.go create mode 100644 resource-manager/privatedns/2024-06-01/recordsets/model_recordset.go create mode 100644 resource-manager/privatedns/2024-06-01/recordsets/model_recordsetproperties.go create mode 100644 resource-manager/privatedns/2024-06-01/recordsets/model_soarecord.go create mode 100644 resource-manager/privatedns/2024-06-01/recordsets/model_srvrecord.go create mode 100644 resource-manager/privatedns/2024-06-01/recordsets/model_txtrecord.go create mode 100644 resource-manager/privatedns/2024-06-01/recordsets/predicates.go create mode 100644 resource-manager/privatedns/2024-06-01/recordsets/version.go create mode 100644 resource-manager/privatedns/2024-06-01/virtualnetworklinks/README.md create mode 100644 resource-manager/privatedns/2024-06-01/virtualnetworklinks/client.go create mode 100644 resource-manager/privatedns/2024-06-01/virtualnetworklinks/constants.go create mode 100644 resource-manager/privatedns/2024-06-01/virtualnetworklinks/id_privatednszone.go create mode 100644 resource-manager/privatedns/2024-06-01/virtualnetworklinks/id_privatednszone_test.go create mode 100644 resource-manager/privatedns/2024-06-01/virtualnetworklinks/id_virtualnetworklink.go create mode 100644 resource-manager/privatedns/2024-06-01/virtualnetworklinks/id_virtualnetworklink_test.go create mode 100644 resource-manager/privatedns/2024-06-01/virtualnetworklinks/method_createorupdate.go create mode 100644 resource-manager/privatedns/2024-06-01/virtualnetworklinks/method_delete.go create mode 100644 resource-manager/privatedns/2024-06-01/virtualnetworklinks/method_get.go create mode 100644 resource-manager/privatedns/2024-06-01/virtualnetworklinks/method_list.go create mode 100644 resource-manager/privatedns/2024-06-01/virtualnetworklinks/method_update.go create mode 100644 resource-manager/privatedns/2024-06-01/virtualnetworklinks/model_subresource.go create mode 100644 resource-manager/privatedns/2024-06-01/virtualnetworklinks/model_virtualnetworklink.go create mode 100644 resource-manager/privatedns/2024-06-01/virtualnetworklinks/model_virtualnetworklinkproperties.go create mode 100644 resource-manager/privatedns/2024-06-01/virtualnetworklinks/predicates.go create mode 100644 resource-manager/privatedns/2024-06-01/virtualnetworklinks/version.go diff --git a/resource-manager/privatedns/2024-06-01/client.go b/resource-manager/privatedns/2024-06-01/client.go new file mode 100644 index 00000000000..2fa270fd360 --- /dev/null +++ b/resource-manager/privatedns/2024-06-01/client.go @@ -0,0 +1,46 @@ +package v2024_06_01 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/resource-manager/privatedns/2024-06-01/privatezones" + "github.com/hashicorp/go-azure-sdk/resource-manager/privatedns/2024-06-01/recordsets" + "github.com/hashicorp/go-azure-sdk/resource-manager/privatedns/2024-06-01/virtualnetworklinks" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +type Client struct { + PrivateZones *privatezones.PrivateZonesClient + RecordSets *recordsets.RecordSetsClient + VirtualNetworkLinks *virtualnetworklinks.VirtualNetworkLinksClient +} + +func NewClientWithBaseURI(sdkApi sdkEnv.Api, configureFunc func(c *resourcemanager.Client)) (*Client, error) { + privateZonesClient, err := privatezones.NewPrivateZonesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building PrivateZones client: %+v", err) + } + configureFunc(privateZonesClient.Client) + + recordSetsClient, err := recordsets.NewRecordSetsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building RecordSets client: %+v", err) + } + configureFunc(recordSetsClient.Client) + + virtualNetworkLinksClient, err := virtualnetworklinks.NewVirtualNetworkLinksClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building VirtualNetworkLinks client: %+v", err) + } + configureFunc(virtualNetworkLinksClient.Client) + + return &Client{ + PrivateZones: privateZonesClient, + RecordSets: recordSetsClient, + VirtualNetworkLinks: virtualNetworkLinksClient, + }, nil +} diff --git a/resource-manager/privatedns/2024-06-01/privatezones/README.md b/resource-manager/privatedns/2024-06-01/privatezones/README.md new file mode 100644 index 00000000000..f2759cbb106 --- /dev/null +++ b/resource-manager/privatedns/2024-06-01/privatezones/README.md @@ -0,0 +1,117 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/privatedns/2024-06-01/privatezones` Documentation + +The `privatezones` SDK allows for interaction with the Azure Resource Manager Service `privatedns` (API Version `2024-06-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/privatedns/2024-06-01/privatezones" +``` + + +### Client Initialization + +```go +client := privatezones.NewPrivateZonesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `PrivateZonesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := privatezones.NewPrivateDnsZoneID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateDnsZoneValue") + +payload := privatezones.PrivateZone{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload, privatezones.DefaultCreateOrUpdateOperationOptions()); err != nil { + // handle the error +} +``` + + +### Example Usage: `PrivateZonesClient.Delete` + +```go +ctx := context.TODO() +id := privatezones.NewPrivateDnsZoneID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateDnsZoneValue") + +if err := client.DeleteThenPoll(ctx, id, privatezones.DefaultDeleteOperationOptions()); err != nil { + // handle the error +} +``` + + +### Example Usage: `PrivateZonesClient.Get` + +```go +ctx := context.TODO() +id := privatezones.NewPrivateDnsZoneID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateDnsZoneValue") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `PrivateZonesClient.List` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.List(ctx, id, privatezones.DefaultListOperationOptions())` can be used to do batched pagination +items, err := client.ListComplete(ctx, id, privatezones.DefaultListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `PrivateZonesClient.ListByResourceGroup` + +```go +ctx := context.TODO() +id := commonids.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +// alternatively `client.ListByResourceGroup(ctx, id, privatezones.DefaultListByResourceGroupOperationOptions())` can be used to do batched pagination +items, err := client.ListByResourceGroupComplete(ctx, id, privatezones.DefaultListByResourceGroupOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `PrivateZonesClient.Update` + +```go +ctx := context.TODO() +id := privatezones.NewPrivateDnsZoneID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateDnsZoneValue") + +payload := privatezones.PrivateZone{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload, privatezones.DefaultUpdateOperationOptions()); err != nil { + // handle the error +} +``` diff --git a/resource-manager/privatedns/2024-06-01/privatezones/client.go b/resource-manager/privatedns/2024-06-01/privatezones/client.go new file mode 100644 index 00000000000..3cc24a351cc --- /dev/null +++ b/resource-manager/privatedns/2024-06-01/privatezones/client.go @@ -0,0 +1,26 @@ +package privatezones + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateZonesClient struct { + Client *resourcemanager.Client +} + +func NewPrivateZonesClientWithBaseURI(sdkApi sdkEnv.Api) (*PrivateZonesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "privatezones", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating PrivateZonesClient: %+v", err) + } + + return &PrivateZonesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/privatedns/2024-06-01/privatezones/constants.go b/resource-manager/privatedns/2024-06-01/privatezones/constants.go new file mode 100644 index 00000000000..9ce4e5ddbb9 --- /dev/null +++ b/resource-manager/privatedns/2024-06-01/privatezones/constants.go @@ -0,0 +1,63 @@ +package privatezones + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProvisioningState string + +const ( + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateCreating ProvisioningState = "Creating" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateCanceled), + string(ProvisioningStateCreating), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateSucceeded), + string(ProvisioningStateUpdating), + } +} + +func (s *ProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "canceled": ProvisioningStateCanceled, + "creating": ProvisioningStateCreating, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "succeeded": ProvisioningStateSucceeded, + "updating": ProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProvisioningState(input) + return &out, nil +} diff --git a/resource-manager/privatedns/2024-06-01/privatezones/id_privatednszone.go b/resource-manager/privatedns/2024-06-01/privatezones/id_privatednszone.go new file mode 100644 index 00000000000..803996b79bf --- /dev/null +++ b/resource-manager/privatedns/2024-06-01/privatezones/id_privatednszone.go @@ -0,0 +1,130 @@ +package privatezones + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&PrivateDnsZoneId{}) +} + +var _ resourceids.ResourceId = &PrivateDnsZoneId{} + +// PrivateDnsZoneId is a struct representing the Resource ID for a Private Dns Zone +type PrivateDnsZoneId struct { + SubscriptionId string + ResourceGroupName string + PrivateDnsZoneName string +} + +// NewPrivateDnsZoneID returns a new PrivateDnsZoneId struct +func NewPrivateDnsZoneID(subscriptionId string, resourceGroupName string, privateDnsZoneName string) PrivateDnsZoneId { + return PrivateDnsZoneId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + PrivateDnsZoneName: privateDnsZoneName, + } +} + +// ParsePrivateDnsZoneID parses 'input' into a PrivateDnsZoneId +func ParsePrivateDnsZoneID(input string) (*PrivateDnsZoneId, error) { + parser := resourceids.NewParserFromResourceIdType(&PrivateDnsZoneId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PrivateDnsZoneId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParsePrivateDnsZoneIDInsensitively parses 'input' case-insensitively into a PrivateDnsZoneId +// note: this method should only be used for API response data and not user input +func ParsePrivateDnsZoneIDInsensitively(input string) (*PrivateDnsZoneId, error) { + parser := resourceids.NewParserFromResourceIdType(&PrivateDnsZoneId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PrivateDnsZoneId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *PrivateDnsZoneId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.PrivateDnsZoneName, ok = input.Parsed["privateDnsZoneName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "privateDnsZoneName", input) + } + + return nil +} + +// ValidatePrivateDnsZoneID checks that 'input' can be parsed as a Private Dns Zone ID +func ValidatePrivateDnsZoneID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParsePrivateDnsZoneID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Private Dns Zone ID +func (id PrivateDnsZoneId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/privateDnsZones/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.PrivateDnsZoneName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Private Dns Zone ID +func (id PrivateDnsZoneId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftNetwork", "Microsoft.Network", "Microsoft.Network"), + resourceids.StaticSegment("staticPrivateDnsZones", "privateDnsZones", "privateDnsZones"), + resourceids.UserSpecifiedSegment("privateDnsZoneName", "privateDnsZoneValue"), + } +} + +// String returns a human-readable description of this Private Dns Zone ID +func (id PrivateDnsZoneId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Private Dns Zone Name: %q", id.PrivateDnsZoneName), + } + return fmt.Sprintf("Private Dns Zone (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/privatedns/2024-06-01/privatezones/id_privatednszone_test.go b/resource-manager/privatedns/2024-06-01/privatezones/id_privatednszone_test.go new file mode 100644 index 00000000000..8a01f4aebaf --- /dev/null +++ b/resource-manager/privatedns/2024-06-01/privatezones/id_privatednszone_test.go @@ -0,0 +1,282 @@ +package privatezones + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &PrivateDnsZoneId{} + +func TestNewPrivateDnsZoneID(t *testing.T) { + id := NewPrivateDnsZoneID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateDnsZoneValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.PrivateDnsZoneName != "privateDnsZoneValue" { + t.Fatalf("Expected %q but got %q for Segment 'PrivateDnsZoneName'", id.PrivateDnsZoneName, "privateDnsZoneValue") + } +} + +func TestFormatPrivateDnsZoneID(t *testing.T) { + actual := NewPrivateDnsZoneID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateDnsZoneValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network/privateDnsZones/privateDnsZoneValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParsePrivateDnsZoneID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateDnsZoneId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network/privateDnsZones", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network/privateDnsZones/privateDnsZoneValue", + Expected: &PrivateDnsZoneId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + PrivateDnsZoneName: "privateDnsZoneValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network/privateDnsZones/privateDnsZoneValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateDnsZoneID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.PrivateDnsZoneName != v.Expected.PrivateDnsZoneName { + t.Fatalf("Expected %q but got %q for PrivateDnsZoneName", v.Expected.PrivateDnsZoneName, actual.PrivateDnsZoneName) + } + + } +} + +func TestParsePrivateDnsZoneIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateDnsZoneId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.nEtWoRk", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network/privateDnsZones", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.nEtWoRk/pRiVaTeDnSzOnEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network/privateDnsZones/privateDnsZoneValue", + Expected: &PrivateDnsZoneId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + PrivateDnsZoneName: "privateDnsZoneValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network/privateDnsZones/privateDnsZoneValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.nEtWoRk/pRiVaTeDnSzOnEs/pRiVaTeDnSzOnEvAlUe", + Expected: &PrivateDnsZoneId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + PrivateDnsZoneName: "pRiVaTeDnSzOnEvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.nEtWoRk/pRiVaTeDnSzOnEs/pRiVaTeDnSzOnEvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateDnsZoneIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.PrivateDnsZoneName != v.Expected.PrivateDnsZoneName { + t.Fatalf("Expected %q but got %q for PrivateDnsZoneName", v.Expected.PrivateDnsZoneName, actual.PrivateDnsZoneName) + } + + } +} + +func TestSegmentsForPrivateDnsZoneId(t *testing.T) { + segments := PrivateDnsZoneId{}.Segments() + if len(segments) == 0 { + t.Fatalf("PrivateDnsZoneId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/privatedns/2024-06-01/privatezones/method_createorupdate.go b/resource-manager/privatedns/2024-06-01/privatezones/method_createorupdate.go new file mode 100644 index 00000000000..e470f519e8c --- /dev/null +++ b/resource-manager/privatedns/2024-06-01/privatezones/method_createorupdate.go @@ -0,0 +1,108 @@ +package privatezones + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *PrivateZone +} + +type CreateOrUpdateOperationOptions struct { + IfMatch *string + IfNoneMatch *string +} + +func DefaultCreateOrUpdateOperationOptions() CreateOrUpdateOperationOptions { + return CreateOrUpdateOperationOptions{} +} + +func (o CreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + if o.IfNoneMatch != nil { + out.Append("If-None-Match", fmt.Sprintf("%v", *o.IfNoneMatch)) + } + return &out +} + +func (o CreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o CreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// CreateOrUpdate ... +func (c PrivateZonesClient) CreateOrUpdate(ctx context.Context, id PrivateDnsZoneId, input PrivateZone, options CreateOrUpdateOperationOptions) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c PrivateZonesClient) CreateOrUpdateThenPoll(ctx context.Context, id PrivateDnsZoneId, input PrivateZone, options CreateOrUpdateOperationOptions) error { + result, err := c.CreateOrUpdate(ctx, id, input, options) + if err != nil { + return fmt.Errorf("performing CreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after CreateOrUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/privatedns/2024-06-01/privatezones/method_delete.go b/resource-manager/privatedns/2024-06-01/privatezones/method_delete.go new file mode 100644 index 00000000000..d03a01bfb98 --- /dev/null +++ b/resource-manager/privatedns/2024-06-01/privatezones/method_delete.go @@ -0,0 +1,99 @@ +package privatezones + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +type DeleteOperationOptions struct { + IfMatch *string +} + +func DefaultDeleteOperationOptions() DeleteOperationOptions { + return DeleteOperationOptions{} +} + +func (o DeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o DeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o DeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Delete ... +func (c PrivateZonesClient) Delete(ctx context.Context, id PrivateDnsZoneId, options DeleteOperationOptions) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c PrivateZonesClient) DeleteThenPoll(ctx context.Context, id PrivateDnsZoneId, options DeleteOperationOptions) error { + result, err := c.Delete(ctx, id, options) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} diff --git a/resource-manager/privatedns/2024-06-01/privatezones/method_get.go b/resource-manager/privatedns/2024-06-01/privatezones/method_get.go new file mode 100644 index 00000000000..ed785598de2 --- /dev/null +++ b/resource-manager/privatedns/2024-06-01/privatezones/method_get.go @@ -0,0 +1,54 @@ +package privatezones + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PrivateZone +} + +// Get ... +func (c PrivateZonesClient) Get(ctx context.Context, id PrivateDnsZoneId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model PrivateZone + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/privatedns/2024-06-01/privatezones/method_list.go b/resource-manager/privatedns/2024-06-01/privatezones/method_list.go new file mode 100644 index 00000000000..a97a9c885b5 --- /dev/null +++ b/resource-manager/privatedns/2024-06-01/privatezones/method_list.go @@ -0,0 +1,134 @@ +package privatezones + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]PrivateZone +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []PrivateZone +} + +type ListOperationOptions struct { + Top *int64 +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c PrivateZonesClient) List(ctx context.Context, id commonids.SubscriptionId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.Network/privateDnsZones", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]PrivateZone `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c PrivateZonesClient) ListComplete(ctx context.Context, id commonids.SubscriptionId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, PrivateZoneOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c PrivateZonesClient) ListCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, options ListOperationOptions, predicate PrivateZoneOperationPredicate) (result ListCompleteResult, err error) { + items := make([]PrivateZone, 0) + + resp, err := c.List(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/privatedns/2024-06-01/privatezones/method_listbyresourcegroup.go b/resource-manager/privatedns/2024-06-01/privatezones/method_listbyresourcegroup.go new file mode 100644 index 00000000000..be1d3300f4e --- /dev/null +++ b/resource-manager/privatedns/2024-06-01/privatezones/method_listbyresourcegroup.go @@ -0,0 +1,134 @@ +package privatezones + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByResourceGroupOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]PrivateZone +} + +type ListByResourceGroupCompleteResult struct { + LatestHttpResponse *http.Response + Items []PrivateZone +} + +type ListByResourceGroupOperationOptions struct { + Top *int64 +} + +func DefaultListByResourceGroupOperationOptions() ListByResourceGroupOperationOptions { + return ListByResourceGroupOperationOptions{} +} + +func (o ListByResourceGroupOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByResourceGroupOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByResourceGroupOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListByResourceGroupCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByResourceGroupCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByResourceGroup ... +func (c PrivateZonesClient) ListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions) (result ListByResourceGroupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByResourceGroupCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.Network/privateDnsZones", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]PrivateZone `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByResourceGroupComplete retrieves all the results into a single object +func (c PrivateZonesClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions) (ListByResourceGroupCompleteResult, error) { + return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, options, PrivateZoneOperationPredicate{}) +} + +// ListByResourceGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c PrivateZonesClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions, predicate PrivateZoneOperationPredicate) (result ListByResourceGroupCompleteResult, err error) { + items := make([]PrivateZone, 0) + + resp, err := c.ListByResourceGroup(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByResourceGroupCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/privatedns/2024-06-01/privatezones/method_update.go b/resource-manager/privatedns/2024-06-01/privatezones/method_update.go new file mode 100644 index 00000000000..0f4953dfc0d --- /dev/null +++ b/resource-manager/privatedns/2024-06-01/privatezones/method_update.go @@ -0,0 +1,103 @@ +package privatezones + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *PrivateZone +} + +type UpdateOperationOptions struct { + IfMatch *string +} + +func DefaultUpdateOperationOptions() UpdateOperationOptions { + return UpdateOperationOptions{} +} + +func (o UpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o UpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o UpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Update ... +func (c PrivateZonesClient) Update(ctx context.Context, id PrivateDnsZoneId, input PrivateZone, options UpdateOperationOptions) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// UpdateThenPoll performs Update then polls until it's completed +func (c PrivateZonesClient) UpdateThenPoll(ctx context.Context, id PrivateDnsZoneId, input PrivateZone, options UpdateOperationOptions) error { + result, err := c.Update(ctx, id, input, options) + if err != nil { + return fmt.Errorf("performing Update: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Update: %+v", err) + } + + return nil +} diff --git a/resource-manager/privatedns/2024-06-01/privatezones/model_privatezone.go b/resource-manager/privatedns/2024-06-01/privatezones/model_privatezone.go new file mode 100644 index 00000000000..f980ff9f672 --- /dev/null +++ b/resource-manager/privatedns/2024-06-01/privatezones/model_privatezone.go @@ -0,0 +1,14 @@ +package privatezones + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateZone struct { + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PrivateZoneProperties `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/privatedns/2024-06-01/privatezones/model_privatezoneproperties.go b/resource-manager/privatedns/2024-06-01/privatezones/model_privatezoneproperties.go new file mode 100644 index 00000000000..ffa6eea38cf --- /dev/null +++ b/resource-manager/privatedns/2024-06-01/privatezones/model_privatezoneproperties.go @@ -0,0 +1,15 @@ +package privatezones + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateZoneProperties struct { + InternalId *string `json:"internalId,omitempty"` + MaxNumberOfRecordSets *int64 `json:"maxNumberOfRecordSets,omitempty"` + MaxNumberOfVirtualNetworkLinks *int64 `json:"maxNumberOfVirtualNetworkLinks,omitempty"` + MaxNumberOfVirtualNetworkLinksWithRegistration *int64 `json:"maxNumberOfVirtualNetworkLinksWithRegistration,omitempty"` + NumberOfRecordSets *int64 `json:"numberOfRecordSets,omitempty"` + NumberOfVirtualNetworkLinks *int64 `json:"numberOfVirtualNetworkLinks,omitempty"` + NumberOfVirtualNetworkLinksWithRegistration *int64 `json:"numberOfVirtualNetworkLinksWithRegistration,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/privatedns/2024-06-01/privatezones/predicates.go b/resource-manager/privatedns/2024-06-01/privatezones/predicates.go new file mode 100644 index 00000000000..5c765bcc300 --- /dev/null +++ b/resource-manager/privatedns/2024-06-01/privatezones/predicates.go @@ -0,0 +1,37 @@ +package privatezones + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateZoneOperationPredicate struct { + Etag *string + Id *string + Location *string + Name *string + Type *string +} + +func (p PrivateZoneOperationPredicate) Matches(input PrivateZone) bool { + + if p.Etag != nil && (input.Etag == nil || *p.Etag != *input.Etag) { + return false + } + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Location != nil && (input.Location == nil || *p.Location != *input.Location) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/privatedns/2024-06-01/privatezones/version.go b/resource-manager/privatedns/2024-06-01/privatezones/version.go new file mode 100644 index 00000000000..08a3e86da79 --- /dev/null +++ b/resource-manager/privatedns/2024-06-01/privatezones/version.go @@ -0,0 +1,12 @@ +package privatezones + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-06-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/privatezones/%s", defaultApiVersion) +} diff --git a/resource-manager/privatedns/2024-06-01/recordsets/README.md b/resource-manager/privatedns/2024-06-01/recordsets/README.md new file mode 100644 index 00000000000..cceea4ff4e4 --- /dev/null +++ b/resource-manager/privatedns/2024-06-01/recordsets/README.md @@ -0,0 +1,128 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/privatedns/2024-06-01/recordsets` Documentation + +The `recordsets` SDK allows for interaction with the Azure Resource Manager Service `privatedns` (API Version `2024-06-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/privatedns/2024-06-01/recordsets" +``` + + +### Client Initialization + +```go +client := recordsets.NewRecordSetsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `RecordSetsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := recordsets.NewRecordTypeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateDnsZoneValue", "A", "relativeRecordSetValue") + +payload := recordsets.RecordSet{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload, recordsets.DefaultCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `RecordSetsClient.Delete` + +```go +ctx := context.TODO() +id := recordsets.NewRecordTypeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateDnsZoneValue", "A", "relativeRecordSetValue") + +read, err := client.Delete(ctx, id, recordsets.DefaultDeleteOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `RecordSetsClient.Get` + +```go +ctx := context.TODO() +id := recordsets.NewRecordTypeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateDnsZoneValue", "A", "relativeRecordSetValue") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `RecordSetsClient.List` + +```go +ctx := context.TODO() +id := recordsets.NewPrivateDnsZoneID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateDnsZoneValue") + +// alternatively `client.List(ctx, id, recordsets.DefaultListOperationOptions())` can be used to do batched pagination +items, err := client.ListComplete(ctx, id, recordsets.DefaultListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `RecordSetsClient.ListByType` + +```go +ctx := context.TODO() +id := recordsets.NewPrivateZoneID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateDnsZoneValue", "A") + +// alternatively `client.ListByType(ctx, id, recordsets.DefaultListByTypeOperationOptions())` can be used to do batched pagination +items, err := client.ListByTypeComplete(ctx, id, recordsets.DefaultListByTypeOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `RecordSetsClient.Update` + +```go +ctx := context.TODO() +id := recordsets.NewRecordTypeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateDnsZoneValue", "A", "relativeRecordSetValue") + +payload := recordsets.RecordSet{ + // ... +} + + +read, err := client.Update(ctx, id, payload, recordsets.DefaultUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/privatedns/2024-06-01/recordsets/client.go b/resource-manager/privatedns/2024-06-01/recordsets/client.go new file mode 100644 index 00000000000..18ff6ef4956 --- /dev/null +++ b/resource-manager/privatedns/2024-06-01/recordsets/client.go @@ -0,0 +1,26 @@ +package recordsets + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecordSetsClient struct { + Client *resourcemanager.Client +} + +func NewRecordSetsClientWithBaseURI(sdkApi sdkEnv.Api) (*RecordSetsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "recordsets", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating RecordSetsClient: %+v", err) + } + + return &RecordSetsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/privatedns/2024-06-01/recordsets/constants.go b/resource-manager/privatedns/2024-06-01/recordsets/constants.go new file mode 100644 index 00000000000..23dfad2ab78 --- /dev/null +++ b/resource-manager/privatedns/2024-06-01/recordsets/constants.go @@ -0,0 +1,69 @@ +package recordsets + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecordType string + +const ( + RecordTypeA RecordType = "A" + RecordTypeAAAA RecordType = "AAAA" + RecordTypeCNAME RecordType = "CNAME" + RecordTypeMX RecordType = "MX" + RecordTypePTR RecordType = "PTR" + RecordTypeSOA RecordType = "SOA" + RecordTypeSRV RecordType = "SRV" + RecordTypeTXT RecordType = "TXT" +) + +func PossibleValuesForRecordType() []string { + return []string{ + string(RecordTypeA), + string(RecordTypeAAAA), + string(RecordTypeCNAME), + string(RecordTypeMX), + string(RecordTypePTR), + string(RecordTypeSOA), + string(RecordTypeSRV), + string(RecordTypeTXT), + } +} + +func (s *RecordType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRecordType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRecordType(input string) (*RecordType, error) { + vals := map[string]RecordType{ + "a": RecordTypeA, + "aaaa": RecordTypeAAAA, + "cname": RecordTypeCNAME, + "mx": RecordTypeMX, + "ptr": RecordTypePTR, + "soa": RecordTypeSOA, + "srv": RecordTypeSRV, + "txt": RecordTypeTXT, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RecordType(input) + return &out, nil +} diff --git a/resource-manager/privatedns/2024-06-01/recordsets/id_privatednszone.go b/resource-manager/privatedns/2024-06-01/recordsets/id_privatednszone.go new file mode 100644 index 00000000000..65ba5903e02 --- /dev/null +++ b/resource-manager/privatedns/2024-06-01/recordsets/id_privatednszone.go @@ -0,0 +1,130 @@ +package recordsets + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&PrivateDnsZoneId{}) +} + +var _ resourceids.ResourceId = &PrivateDnsZoneId{} + +// PrivateDnsZoneId is a struct representing the Resource ID for a Private Dns Zone +type PrivateDnsZoneId struct { + SubscriptionId string + ResourceGroupName string + PrivateDnsZoneName string +} + +// NewPrivateDnsZoneID returns a new PrivateDnsZoneId struct +func NewPrivateDnsZoneID(subscriptionId string, resourceGroupName string, privateDnsZoneName string) PrivateDnsZoneId { + return PrivateDnsZoneId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + PrivateDnsZoneName: privateDnsZoneName, + } +} + +// ParsePrivateDnsZoneID parses 'input' into a PrivateDnsZoneId +func ParsePrivateDnsZoneID(input string) (*PrivateDnsZoneId, error) { + parser := resourceids.NewParserFromResourceIdType(&PrivateDnsZoneId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PrivateDnsZoneId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParsePrivateDnsZoneIDInsensitively parses 'input' case-insensitively into a PrivateDnsZoneId +// note: this method should only be used for API response data and not user input +func ParsePrivateDnsZoneIDInsensitively(input string) (*PrivateDnsZoneId, error) { + parser := resourceids.NewParserFromResourceIdType(&PrivateDnsZoneId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PrivateDnsZoneId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *PrivateDnsZoneId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.PrivateDnsZoneName, ok = input.Parsed["privateDnsZoneName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "privateDnsZoneName", input) + } + + return nil +} + +// ValidatePrivateDnsZoneID checks that 'input' can be parsed as a Private Dns Zone ID +func ValidatePrivateDnsZoneID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParsePrivateDnsZoneID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Private Dns Zone ID +func (id PrivateDnsZoneId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/privateDnsZones/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.PrivateDnsZoneName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Private Dns Zone ID +func (id PrivateDnsZoneId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftNetwork", "Microsoft.Network", "Microsoft.Network"), + resourceids.StaticSegment("staticPrivateDnsZones", "privateDnsZones", "privateDnsZones"), + resourceids.UserSpecifiedSegment("privateDnsZoneName", "privateDnsZoneValue"), + } +} + +// String returns a human-readable description of this Private Dns Zone ID +func (id PrivateDnsZoneId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Private Dns Zone Name: %q", id.PrivateDnsZoneName), + } + return fmt.Sprintf("Private Dns Zone (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/privatedns/2024-06-01/recordsets/id_privatednszone_test.go b/resource-manager/privatedns/2024-06-01/recordsets/id_privatednszone_test.go new file mode 100644 index 00000000000..f10a20d8ad6 --- /dev/null +++ b/resource-manager/privatedns/2024-06-01/recordsets/id_privatednszone_test.go @@ -0,0 +1,282 @@ +package recordsets + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &PrivateDnsZoneId{} + +func TestNewPrivateDnsZoneID(t *testing.T) { + id := NewPrivateDnsZoneID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateDnsZoneValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.PrivateDnsZoneName != "privateDnsZoneValue" { + t.Fatalf("Expected %q but got %q for Segment 'PrivateDnsZoneName'", id.PrivateDnsZoneName, "privateDnsZoneValue") + } +} + +func TestFormatPrivateDnsZoneID(t *testing.T) { + actual := NewPrivateDnsZoneID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateDnsZoneValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network/privateDnsZones/privateDnsZoneValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParsePrivateDnsZoneID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateDnsZoneId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network/privateDnsZones", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network/privateDnsZones/privateDnsZoneValue", + Expected: &PrivateDnsZoneId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + PrivateDnsZoneName: "privateDnsZoneValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network/privateDnsZones/privateDnsZoneValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateDnsZoneID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.PrivateDnsZoneName != v.Expected.PrivateDnsZoneName { + t.Fatalf("Expected %q but got %q for PrivateDnsZoneName", v.Expected.PrivateDnsZoneName, actual.PrivateDnsZoneName) + } + + } +} + +func TestParsePrivateDnsZoneIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateDnsZoneId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.nEtWoRk", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network/privateDnsZones", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.nEtWoRk/pRiVaTeDnSzOnEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network/privateDnsZones/privateDnsZoneValue", + Expected: &PrivateDnsZoneId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + PrivateDnsZoneName: "privateDnsZoneValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network/privateDnsZones/privateDnsZoneValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.nEtWoRk/pRiVaTeDnSzOnEs/pRiVaTeDnSzOnEvAlUe", + Expected: &PrivateDnsZoneId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + PrivateDnsZoneName: "pRiVaTeDnSzOnEvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.nEtWoRk/pRiVaTeDnSzOnEs/pRiVaTeDnSzOnEvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateDnsZoneIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.PrivateDnsZoneName != v.Expected.PrivateDnsZoneName { + t.Fatalf("Expected %q but got %q for PrivateDnsZoneName", v.Expected.PrivateDnsZoneName, actual.PrivateDnsZoneName) + } + + } +} + +func TestSegmentsForPrivateDnsZoneId(t *testing.T) { + segments := PrivateDnsZoneId{}.Segments() + if len(segments) == 0 { + t.Fatalf("PrivateDnsZoneId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/privatedns/2024-06-01/recordsets/id_privatezone.go b/resource-manager/privatedns/2024-06-01/recordsets/id_privatezone.go new file mode 100644 index 00000000000..2c9cd137e38 --- /dev/null +++ b/resource-manager/privatedns/2024-06-01/recordsets/id_privatezone.go @@ -0,0 +1,146 @@ +package recordsets + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&PrivateZoneId{}) +} + +var _ resourceids.ResourceId = &PrivateZoneId{} + +// PrivateZoneId is a struct representing the Resource ID for a Private Zone +type PrivateZoneId struct { + SubscriptionId string + ResourceGroupName string + PrivateDnsZoneName string + RecordType RecordType +} + +// NewPrivateZoneID returns a new PrivateZoneId struct +func NewPrivateZoneID(subscriptionId string, resourceGroupName string, privateDnsZoneName string, recordType RecordType) PrivateZoneId { + return PrivateZoneId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + PrivateDnsZoneName: privateDnsZoneName, + RecordType: recordType, + } +} + +// ParsePrivateZoneID parses 'input' into a PrivateZoneId +func ParsePrivateZoneID(input string) (*PrivateZoneId, error) { + parser := resourceids.NewParserFromResourceIdType(&PrivateZoneId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PrivateZoneId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParsePrivateZoneIDInsensitively parses 'input' case-insensitively into a PrivateZoneId +// note: this method should only be used for API response data and not user input +func ParsePrivateZoneIDInsensitively(input string) (*PrivateZoneId, error) { + parser := resourceids.NewParserFromResourceIdType(&PrivateZoneId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PrivateZoneId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *PrivateZoneId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.PrivateDnsZoneName, ok = input.Parsed["privateDnsZoneName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "privateDnsZoneName", input) + } + + if v, ok := input.Parsed["recordType"]; true { + if !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "recordType", input) + } + + recordType, err := parseRecordType(v) + if err != nil { + return fmt.Errorf("parsing %q: %+v", v, err) + } + id.RecordType = *recordType + } + + return nil +} + +// ValidatePrivateZoneID checks that 'input' can be parsed as a Private Zone ID +func ValidatePrivateZoneID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParsePrivateZoneID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Private Zone ID +func (id PrivateZoneId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/privateDnsZones/%s/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.PrivateDnsZoneName, string(id.RecordType)) +} + +// Segments returns a slice of Resource ID Segments which comprise this Private Zone ID +func (id PrivateZoneId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftNetwork", "Microsoft.Network", "Microsoft.Network"), + resourceids.StaticSegment("staticPrivateDnsZones", "privateDnsZones", "privateDnsZones"), + resourceids.UserSpecifiedSegment("privateDnsZoneName", "privateDnsZoneValue"), + resourceids.ConstantSegment("recordType", PossibleValuesForRecordType(), "A"), + } +} + +// String returns a human-readable description of this Private Zone ID +func (id PrivateZoneId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Private Dns Zone Name: %q", id.PrivateDnsZoneName), + fmt.Sprintf("Record Type: %q", string(id.RecordType)), + } + return fmt.Sprintf("Private Zone (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/privatedns/2024-06-01/recordsets/id_privatezone_test.go b/resource-manager/privatedns/2024-06-01/recordsets/id_privatezone_test.go new file mode 100644 index 00000000000..5d4f6aa02ba --- /dev/null +++ b/resource-manager/privatedns/2024-06-01/recordsets/id_privatezone_test.go @@ -0,0 +1,312 @@ +package recordsets + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &PrivateZoneId{} + +func TestNewPrivateZoneID(t *testing.T) { + id := NewPrivateZoneID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateDnsZoneValue", "A") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.PrivateDnsZoneName != "privateDnsZoneValue" { + t.Fatalf("Expected %q but got %q for Segment 'PrivateDnsZoneName'", id.PrivateDnsZoneName, "privateDnsZoneValue") + } + + if id.RecordType != "A" { + t.Fatalf("Expected %q but got %q for Segment 'RecordType'", id.RecordType, "A") + } +} + +func TestFormatPrivateZoneID(t *testing.T) { + actual := NewPrivateZoneID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateDnsZoneValue", "A").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network/privateDnsZones/privateDnsZoneValue/A" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParsePrivateZoneID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateZoneId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network/privateDnsZones", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network/privateDnsZones/privateDnsZoneValue", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network/privateDnsZones/privateDnsZoneValue/A", + Expected: &PrivateZoneId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + PrivateDnsZoneName: "privateDnsZoneValue", + RecordType: "A", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network/privateDnsZones/privateDnsZoneValue/A/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateZoneID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.PrivateDnsZoneName != v.Expected.PrivateDnsZoneName { + t.Fatalf("Expected %q but got %q for PrivateDnsZoneName", v.Expected.PrivateDnsZoneName, actual.PrivateDnsZoneName) + } + + if actual.RecordType != v.Expected.RecordType { + t.Fatalf("Expected %q but got %q for RecordType", v.Expected.RecordType, actual.RecordType) + } + + } +} + +func TestParsePrivateZoneIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateZoneId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.nEtWoRk", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network/privateDnsZones", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.nEtWoRk/pRiVaTeDnSzOnEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network/privateDnsZones/privateDnsZoneValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.nEtWoRk/pRiVaTeDnSzOnEs/pRiVaTeDnSzOnEvAlUe", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network/privateDnsZones/privateDnsZoneValue/A", + Expected: &PrivateZoneId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + PrivateDnsZoneName: "privateDnsZoneValue", + RecordType: "A", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network/privateDnsZones/privateDnsZoneValue/A/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.nEtWoRk/pRiVaTeDnSzOnEs/pRiVaTeDnSzOnEvAlUe/a", + Expected: &PrivateZoneId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + PrivateDnsZoneName: "pRiVaTeDnSzOnEvAlUe", + RecordType: "A", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.nEtWoRk/pRiVaTeDnSzOnEs/pRiVaTeDnSzOnEvAlUe/a/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateZoneIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.PrivateDnsZoneName != v.Expected.PrivateDnsZoneName { + t.Fatalf("Expected %q but got %q for PrivateDnsZoneName", v.Expected.PrivateDnsZoneName, actual.PrivateDnsZoneName) + } + + if actual.RecordType != v.Expected.RecordType { + t.Fatalf("Expected %q but got %q for RecordType", v.Expected.RecordType, actual.RecordType) + } + + } +} + +func TestSegmentsForPrivateZoneId(t *testing.T) { + segments := PrivateZoneId{}.Segments() + if len(segments) == 0 { + t.Fatalf("PrivateZoneId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/privatedns/2024-06-01/recordsets/id_recordtype.go b/resource-manager/privatedns/2024-06-01/recordsets/id_recordtype.go new file mode 100644 index 00000000000..a866a37ab87 --- /dev/null +++ b/resource-manager/privatedns/2024-06-01/recordsets/id_recordtype.go @@ -0,0 +1,154 @@ +package recordsets + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&RecordTypeId{}) +} + +var _ resourceids.ResourceId = &RecordTypeId{} + +// RecordTypeId is a struct representing the Resource ID for a Record Type +type RecordTypeId struct { + SubscriptionId string + ResourceGroupName string + PrivateDnsZoneName string + RecordType RecordType + RelativeRecordSetName string +} + +// NewRecordTypeID returns a new RecordTypeId struct +func NewRecordTypeID(subscriptionId string, resourceGroupName string, privateDnsZoneName string, recordType RecordType, relativeRecordSetName string) RecordTypeId { + return RecordTypeId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + PrivateDnsZoneName: privateDnsZoneName, + RecordType: recordType, + RelativeRecordSetName: relativeRecordSetName, + } +} + +// ParseRecordTypeID parses 'input' into a RecordTypeId +func ParseRecordTypeID(input string) (*RecordTypeId, error) { + parser := resourceids.NewParserFromResourceIdType(&RecordTypeId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RecordTypeId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseRecordTypeIDInsensitively parses 'input' case-insensitively into a RecordTypeId +// note: this method should only be used for API response data and not user input +func ParseRecordTypeIDInsensitively(input string) (*RecordTypeId, error) { + parser := resourceids.NewParserFromResourceIdType(&RecordTypeId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RecordTypeId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *RecordTypeId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.PrivateDnsZoneName, ok = input.Parsed["privateDnsZoneName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "privateDnsZoneName", input) + } + + if v, ok := input.Parsed["recordType"]; true { + if !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "recordType", input) + } + + recordType, err := parseRecordType(v) + if err != nil { + return fmt.Errorf("parsing %q: %+v", v, err) + } + id.RecordType = *recordType + } + + if id.RelativeRecordSetName, ok = input.Parsed["relativeRecordSetName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "relativeRecordSetName", input) + } + + return nil +} + +// ValidateRecordTypeID checks that 'input' can be parsed as a Record Type ID +func ValidateRecordTypeID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseRecordTypeID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Record Type ID +func (id RecordTypeId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/privateDnsZones/%s/%s/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.PrivateDnsZoneName, string(id.RecordType), id.RelativeRecordSetName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Record Type ID +func (id RecordTypeId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftNetwork", "Microsoft.Network", "Microsoft.Network"), + resourceids.StaticSegment("staticPrivateDnsZones", "privateDnsZones", "privateDnsZones"), + resourceids.UserSpecifiedSegment("privateDnsZoneName", "privateDnsZoneValue"), + resourceids.ConstantSegment("recordType", PossibleValuesForRecordType(), "A"), + resourceids.UserSpecifiedSegment("relativeRecordSetName", "relativeRecordSetValue"), + } +} + +// String returns a human-readable description of this Record Type ID +func (id RecordTypeId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Private Dns Zone Name: %q", id.PrivateDnsZoneName), + fmt.Sprintf("Record Type: %q", string(id.RecordType)), + fmt.Sprintf("Relative Record Set Name: %q", id.RelativeRecordSetName), + } + return fmt.Sprintf("Record Type (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/privatedns/2024-06-01/recordsets/id_recordtype_test.go b/resource-manager/privatedns/2024-06-01/recordsets/id_recordtype_test.go new file mode 100644 index 00000000000..8478db2f36d --- /dev/null +++ b/resource-manager/privatedns/2024-06-01/recordsets/id_recordtype_test.go @@ -0,0 +1,342 @@ +package recordsets + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &RecordTypeId{} + +func TestNewRecordTypeID(t *testing.T) { + id := NewRecordTypeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateDnsZoneValue", "A", "relativeRecordSetValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.PrivateDnsZoneName != "privateDnsZoneValue" { + t.Fatalf("Expected %q but got %q for Segment 'PrivateDnsZoneName'", id.PrivateDnsZoneName, "privateDnsZoneValue") + } + + if id.RecordType != "A" { + t.Fatalf("Expected %q but got %q for Segment 'RecordType'", id.RecordType, "A") + } + + if id.RelativeRecordSetName != "relativeRecordSetValue" { + t.Fatalf("Expected %q but got %q for Segment 'RelativeRecordSetName'", id.RelativeRecordSetName, "relativeRecordSetValue") + } +} + +func TestFormatRecordTypeID(t *testing.T) { + actual := NewRecordTypeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateDnsZoneValue", "A", "relativeRecordSetValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network/privateDnsZones/privateDnsZoneValue/A/relativeRecordSetValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseRecordTypeID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RecordTypeId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network/privateDnsZones", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network/privateDnsZones/privateDnsZoneValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network/privateDnsZones/privateDnsZoneValue/A", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network/privateDnsZones/privateDnsZoneValue/A/relativeRecordSetValue", + Expected: &RecordTypeId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + PrivateDnsZoneName: "privateDnsZoneValue", + RecordType: "A", + RelativeRecordSetName: "relativeRecordSetValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network/privateDnsZones/privateDnsZoneValue/A/relativeRecordSetValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRecordTypeID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.PrivateDnsZoneName != v.Expected.PrivateDnsZoneName { + t.Fatalf("Expected %q but got %q for PrivateDnsZoneName", v.Expected.PrivateDnsZoneName, actual.PrivateDnsZoneName) + } + + if actual.RecordType != v.Expected.RecordType { + t.Fatalf("Expected %q but got %q for RecordType", v.Expected.RecordType, actual.RecordType) + } + + if actual.RelativeRecordSetName != v.Expected.RelativeRecordSetName { + t.Fatalf("Expected %q but got %q for RelativeRecordSetName", v.Expected.RelativeRecordSetName, actual.RelativeRecordSetName) + } + + } +} + +func TestParseRecordTypeIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RecordTypeId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.nEtWoRk", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network/privateDnsZones", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.nEtWoRk/pRiVaTeDnSzOnEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network/privateDnsZones/privateDnsZoneValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.nEtWoRk/pRiVaTeDnSzOnEs/pRiVaTeDnSzOnEvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network/privateDnsZones/privateDnsZoneValue/A", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.nEtWoRk/pRiVaTeDnSzOnEs/pRiVaTeDnSzOnEvAlUe/a", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network/privateDnsZones/privateDnsZoneValue/A/relativeRecordSetValue", + Expected: &RecordTypeId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + PrivateDnsZoneName: "privateDnsZoneValue", + RecordType: "A", + RelativeRecordSetName: "relativeRecordSetValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network/privateDnsZones/privateDnsZoneValue/A/relativeRecordSetValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.nEtWoRk/pRiVaTeDnSzOnEs/pRiVaTeDnSzOnEvAlUe/a/rElAtIvErEcOrDsEtVaLuE", + Expected: &RecordTypeId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + PrivateDnsZoneName: "pRiVaTeDnSzOnEvAlUe", + RecordType: "A", + RelativeRecordSetName: "rElAtIvErEcOrDsEtVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.nEtWoRk/pRiVaTeDnSzOnEs/pRiVaTeDnSzOnEvAlUe/a/rElAtIvErEcOrDsEtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRecordTypeIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.PrivateDnsZoneName != v.Expected.PrivateDnsZoneName { + t.Fatalf("Expected %q but got %q for PrivateDnsZoneName", v.Expected.PrivateDnsZoneName, actual.PrivateDnsZoneName) + } + + if actual.RecordType != v.Expected.RecordType { + t.Fatalf("Expected %q but got %q for RecordType", v.Expected.RecordType, actual.RecordType) + } + + if actual.RelativeRecordSetName != v.Expected.RelativeRecordSetName { + t.Fatalf("Expected %q but got %q for RelativeRecordSetName", v.Expected.RelativeRecordSetName, actual.RelativeRecordSetName) + } + + } +} + +func TestSegmentsForRecordTypeId(t *testing.T) { + segments := RecordTypeId{}.Segments() + if len(segments) == 0 { + t.Fatalf("RecordTypeId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/privatedns/2024-06-01/recordsets/method_createorupdate.go b/resource-manager/privatedns/2024-06-01/recordsets/method_createorupdate.go new file mode 100644 index 00000000000..da283847699 --- /dev/null +++ b/resource-manager/privatedns/2024-06-01/recordsets/method_createorupdate.go @@ -0,0 +1,92 @@ +package recordsets + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *RecordSet +} + +type CreateOrUpdateOperationOptions struct { + IfMatch *string + IfNoneMatch *string +} + +func DefaultCreateOrUpdateOperationOptions() CreateOrUpdateOperationOptions { + return CreateOrUpdateOperationOptions{} +} + +func (o CreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + if o.IfNoneMatch != nil { + out.Append("If-None-Match", fmt.Sprintf("%v", *o.IfNoneMatch)) + } + return &out +} + +func (o CreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o CreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// CreateOrUpdate ... +func (c RecordSetsClient) CreateOrUpdate(ctx context.Context, id RecordTypeId, input RecordSet, options CreateOrUpdateOperationOptions) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model RecordSet + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/privatedns/2024-06-01/recordsets/method_delete.go b/resource-manager/privatedns/2024-06-01/recordsets/method_delete.go new file mode 100644 index 00000000000..bac259d0f30 --- /dev/null +++ b/resource-manager/privatedns/2024-06-01/recordsets/method_delete.go @@ -0,0 +1,76 @@ +package recordsets + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type DeleteOperationOptions struct { + IfMatch *string +} + +func DefaultDeleteOperationOptions() DeleteOperationOptions { + return DeleteOperationOptions{} +} + +func (o DeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o DeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o DeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Delete ... +func (c RecordSetsClient) Delete(ctx context.Context, id RecordTypeId, options DeleteOperationOptions) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/privatedns/2024-06-01/recordsets/method_get.go b/resource-manager/privatedns/2024-06-01/recordsets/method_get.go new file mode 100644 index 00000000000..4cea3370054 --- /dev/null +++ b/resource-manager/privatedns/2024-06-01/recordsets/method_get.go @@ -0,0 +1,54 @@ +package recordsets + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *RecordSet +} + +// Get ... +func (c RecordSetsClient) Get(ctx context.Context, id RecordTypeId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model RecordSet + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/privatedns/2024-06-01/recordsets/method_list.go b/resource-manager/privatedns/2024-06-01/recordsets/method_list.go new file mode 100644 index 00000000000..9c2a2020943 --- /dev/null +++ b/resource-manager/privatedns/2024-06-01/recordsets/method_list.go @@ -0,0 +1,137 @@ +package recordsets + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]RecordSet +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []RecordSet +} + +type ListOperationOptions struct { + Recordsetnamesuffix *string + Top *int64 +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Recordsetnamesuffix != nil { + out.Append("$recordsetnamesuffix", fmt.Sprintf("%v", *o.Recordsetnamesuffix)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c RecordSetsClient) List(ctx context.Context, id PrivateDnsZoneId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/aLL", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]RecordSet `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c RecordSetsClient) ListComplete(ctx context.Context, id PrivateDnsZoneId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, RecordSetOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c RecordSetsClient) ListCompleteMatchingPredicate(ctx context.Context, id PrivateDnsZoneId, options ListOperationOptions, predicate RecordSetOperationPredicate) (result ListCompleteResult, err error) { + items := make([]RecordSet, 0) + + resp, err := c.List(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/privatedns/2024-06-01/recordsets/method_listbytype.go b/resource-manager/privatedns/2024-06-01/recordsets/method_listbytype.go new file mode 100644 index 00000000000..3705ca025ec --- /dev/null +++ b/resource-manager/privatedns/2024-06-01/recordsets/method_listbytype.go @@ -0,0 +1,137 @@ +package recordsets + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByTypeOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]RecordSet +} + +type ListByTypeCompleteResult struct { + LatestHttpResponse *http.Response + Items []RecordSet +} + +type ListByTypeOperationOptions struct { + Recordsetnamesuffix *string + Top *int64 +} + +func DefaultListByTypeOperationOptions() ListByTypeOperationOptions { + return ListByTypeOperationOptions{} +} + +func (o ListByTypeOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByTypeOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByTypeOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Recordsetnamesuffix != nil { + out.Append("$recordsetnamesuffix", fmt.Sprintf("%v", *o.Recordsetnamesuffix)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListByTypeCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByTypeCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByType ... +func (c RecordSetsClient) ListByType(ctx context.Context, id PrivateZoneId, options ListByTypeOperationOptions) (result ListByTypeOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByTypeCustomPager{}, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]RecordSet `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByTypeComplete retrieves all the results into a single object +func (c RecordSetsClient) ListByTypeComplete(ctx context.Context, id PrivateZoneId, options ListByTypeOperationOptions) (ListByTypeCompleteResult, error) { + return c.ListByTypeCompleteMatchingPredicate(ctx, id, options, RecordSetOperationPredicate{}) +} + +// ListByTypeCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c RecordSetsClient) ListByTypeCompleteMatchingPredicate(ctx context.Context, id PrivateZoneId, options ListByTypeOperationOptions, predicate RecordSetOperationPredicate) (result ListByTypeCompleteResult, err error) { + items := make([]RecordSet, 0) + + resp, err := c.ListByType(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByTypeCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/privatedns/2024-06-01/recordsets/method_update.go b/resource-manager/privatedns/2024-06-01/recordsets/method_update.go new file mode 100644 index 00000000000..def3737e664 --- /dev/null +++ b/resource-manager/privatedns/2024-06-01/recordsets/method_update.go @@ -0,0 +1,87 @@ +package recordsets + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *RecordSet +} + +type UpdateOperationOptions struct { + IfMatch *string +} + +func DefaultUpdateOperationOptions() UpdateOperationOptions { + return UpdateOperationOptions{} +} + +func (o UpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o UpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o UpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Update ... +func (c RecordSetsClient) Update(ctx context.Context, id RecordTypeId, input RecordSet, options UpdateOperationOptions) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model RecordSet + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/privatedns/2024-06-01/recordsets/model_aaaarecord.go b/resource-manager/privatedns/2024-06-01/recordsets/model_aaaarecord.go new file mode 100644 index 00000000000..ab849f34d41 --- /dev/null +++ b/resource-manager/privatedns/2024-06-01/recordsets/model_aaaarecord.go @@ -0,0 +1,8 @@ +package recordsets + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AaaaRecord struct { + IPv6Address *string `json:"ipv6Address,omitempty"` +} diff --git a/resource-manager/privatedns/2024-06-01/recordsets/model_arecord.go b/resource-manager/privatedns/2024-06-01/recordsets/model_arecord.go new file mode 100644 index 00000000000..878b5d761d5 --- /dev/null +++ b/resource-manager/privatedns/2024-06-01/recordsets/model_arecord.go @@ -0,0 +1,8 @@ +package recordsets + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ARecord struct { + IPv4Address *string `json:"ipv4Address,omitempty"` +} diff --git a/resource-manager/privatedns/2024-06-01/recordsets/model_cnamerecord.go b/resource-manager/privatedns/2024-06-01/recordsets/model_cnamerecord.go new file mode 100644 index 00000000000..911f2640c05 --- /dev/null +++ b/resource-manager/privatedns/2024-06-01/recordsets/model_cnamerecord.go @@ -0,0 +1,8 @@ +package recordsets + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CnameRecord struct { + Cname *string `json:"cname,omitempty"` +} diff --git a/resource-manager/privatedns/2024-06-01/recordsets/model_mxrecord.go b/resource-manager/privatedns/2024-06-01/recordsets/model_mxrecord.go new file mode 100644 index 00000000000..54903e902e4 --- /dev/null +++ b/resource-manager/privatedns/2024-06-01/recordsets/model_mxrecord.go @@ -0,0 +1,9 @@ +package recordsets + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MxRecord struct { + Exchange *string `json:"exchange,omitempty"` + Preference *int64 `json:"preference,omitempty"` +} diff --git a/resource-manager/privatedns/2024-06-01/recordsets/model_ptrrecord.go b/resource-manager/privatedns/2024-06-01/recordsets/model_ptrrecord.go new file mode 100644 index 00000000000..f05e7f6dd8c --- /dev/null +++ b/resource-manager/privatedns/2024-06-01/recordsets/model_ptrrecord.go @@ -0,0 +1,8 @@ +package recordsets + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PtrRecord struct { + Ptrdname *string `json:"ptrdname,omitempty"` +} diff --git a/resource-manager/privatedns/2024-06-01/recordsets/model_recordset.go b/resource-manager/privatedns/2024-06-01/recordsets/model_recordset.go new file mode 100644 index 00000000000..5b44bdb5364 --- /dev/null +++ b/resource-manager/privatedns/2024-06-01/recordsets/model_recordset.go @@ -0,0 +1,12 @@ +package recordsets + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecordSet struct { + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *RecordSetProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/privatedns/2024-06-01/recordsets/model_recordsetproperties.go b/resource-manager/privatedns/2024-06-01/recordsets/model_recordsetproperties.go new file mode 100644 index 00000000000..82851761b08 --- /dev/null +++ b/resource-manager/privatedns/2024-06-01/recordsets/model_recordsetproperties.go @@ -0,0 +1,19 @@ +package recordsets + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecordSetProperties struct { + ARecords *[]ARecord `json:"aRecords,omitempty"` + AaaaRecords *[]AaaaRecord `json:"aaaaRecords,omitempty"` + CnameRecord *CnameRecord `json:"cnameRecord,omitempty"` + Fqdn *string `json:"fqdn,omitempty"` + IsAutoRegistered *bool `json:"isAutoRegistered,omitempty"` + Metadata *map[string]string `json:"metadata,omitempty"` + MxRecords *[]MxRecord `json:"mxRecords,omitempty"` + PtrRecords *[]PtrRecord `json:"ptrRecords,omitempty"` + SoaRecord *SoaRecord `json:"soaRecord,omitempty"` + SrvRecords *[]SrvRecord `json:"srvRecords,omitempty"` + Ttl *int64 `json:"ttl,omitempty"` + TxtRecords *[]TxtRecord `json:"txtRecords,omitempty"` +} diff --git a/resource-manager/privatedns/2024-06-01/recordsets/model_soarecord.go b/resource-manager/privatedns/2024-06-01/recordsets/model_soarecord.go new file mode 100644 index 00000000000..d75d6f7535f --- /dev/null +++ b/resource-manager/privatedns/2024-06-01/recordsets/model_soarecord.go @@ -0,0 +1,14 @@ +package recordsets + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SoaRecord struct { + Email *string `json:"email,omitempty"` + ExpireTime *int64 `json:"expireTime,omitempty"` + Host *string `json:"host,omitempty"` + MinimumTtl *int64 `json:"minimumTtl,omitempty"` + RefreshTime *int64 `json:"refreshTime,omitempty"` + RetryTime *int64 `json:"retryTime,omitempty"` + SerialNumber *int64 `json:"serialNumber,omitempty"` +} diff --git a/resource-manager/privatedns/2024-06-01/recordsets/model_srvrecord.go b/resource-manager/privatedns/2024-06-01/recordsets/model_srvrecord.go new file mode 100644 index 00000000000..98d79cdea1d --- /dev/null +++ b/resource-manager/privatedns/2024-06-01/recordsets/model_srvrecord.go @@ -0,0 +1,11 @@ +package recordsets + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SrvRecord struct { + Port *int64 `json:"port,omitempty"` + Priority *int64 `json:"priority,omitempty"` + Target *string `json:"target,omitempty"` + Weight *int64 `json:"weight,omitempty"` +} diff --git a/resource-manager/privatedns/2024-06-01/recordsets/model_txtrecord.go b/resource-manager/privatedns/2024-06-01/recordsets/model_txtrecord.go new file mode 100644 index 00000000000..a55b70eade1 --- /dev/null +++ b/resource-manager/privatedns/2024-06-01/recordsets/model_txtrecord.go @@ -0,0 +1,8 @@ +package recordsets + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TxtRecord struct { + Value *[]string `json:"value,omitempty"` +} diff --git a/resource-manager/privatedns/2024-06-01/recordsets/predicates.go b/resource-manager/privatedns/2024-06-01/recordsets/predicates.go new file mode 100644 index 00000000000..d8c25e0e1ba --- /dev/null +++ b/resource-manager/privatedns/2024-06-01/recordsets/predicates.go @@ -0,0 +1,32 @@ +package recordsets + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecordSetOperationPredicate struct { + Etag *string + Id *string + Name *string + Type *string +} + +func (p RecordSetOperationPredicate) Matches(input RecordSet) bool { + + if p.Etag != nil && (input.Etag == nil || *p.Etag != *input.Etag) { + return false + } + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/privatedns/2024-06-01/recordsets/version.go b/resource-manager/privatedns/2024-06-01/recordsets/version.go new file mode 100644 index 00000000000..d2ce93f11bb --- /dev/null +++ b/resource-manager/privatedns/2024-06-01/recordsets/version.go @@ -0,0 +1,12 @@ +package recordsets + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-06-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/recordsets/%s", defaultApiVersion) +} diff --git a/resource-manager/privatedns/2024-06-01/virtualnetworklinks/README.md b/resource-manager/privatedns/2024-06-01/virtualnetworklinks/README.md new file mode 100644 index 00000000000..fc8d018e847 --- /dev/null +++ b/resource-manager/privatedns/2024-06-01/virtualnetworklinks/README.md @@ -0,0 +1,99 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/privatedns/2024-06-01/virtualnetworklinks` Documentation + +The `virtualnetworklinks` SDK allows for interaction with the Azure Resource Manager Service `privatedns` (API Version `2024-06-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/privatedns/2024-06-01/virtualnetworklinks" +``` + + +### Client Initialization + +```go +client := virtualnetworklinks.NewVirtualNetworkLinksClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `VirtualNetworkLinksClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := virtualnetworklinks.NewVirtualNetworkLinkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateDnsZoneValue", "virtualNetworkLinkValue") + +payload := virtualnetworklinks.VirtualNetworkLink{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload, virtualnetworklinks.DefaultCreateOrUpdateOperationOptions()); err != nil { + // handle the error +} +``` + + +### Example Usage: `VirtualNetworkLinksClient.Delete` + +```go +ctx := context.TODO() +id := virtualnetworklinks.NewVirtualNetworkLinkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateDnsZoneValue", "virtualNetworkLinkValue") + +if err := client.DeleteThenPoll(ctx, id, virtualnetworklinks.DefaultDeleteOperationOptions()); err != nil { + // handle the error +} +``` + + +### Example Usage: `VirtualNetworkLinksClient.Get` + +```go +ctx := context.TODO() +id := virtualnetworklinks.NewVirtualNetworkLinkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateDnsZoneValue", "virtualNetworkLinkValue") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `VirtualNetworkLinksClient.List` + +```go +ctx := context.TODO() +id := virtualnetworklinks.NewPrivateDnsZoneID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateDnsZoneValue") + +// alternatively `client.List(ctx, id, virtualnetworklinks.DefaultListOperationOptions())` can be used to do batched pagination +items, err := client.ListComplete(ctx, id, virtualnetworklinks.DefaultListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `VirtualNetworkLinksClient.Update` + +```go +ctx := context.TODO() +id := virtualnetworklinks.NewVirtualNetworkLinkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateDnsZoneValue", "virtualNetworkLinkValue") + +payload := virtualnetworklinks.VirtualNetworkLink{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload, virtualnetworklinks.DefaultUpdateOperationOptions()); err != nil { + // handle the error +} +``` diff --git a/resource-manager/privatedns/2024-06-01/virtualnetworklinks/client.go b/resource-manager/privatedns/2024-06-01/virtualnetworklinks/client.go new file mode 100644 index 00000000000..69e2bb7e2f1 --- /dev/null +++ b/resource-manager/privatedns/2024-06-01/virtualnetworklinks/client.go @@ -0,0 +1,26 @@ +package virtualnetworklinks + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VirtualNetworkLinksClient struct { + Client *resourcemanager.Client +} + +func NewVirtualNetworkLinksClientWithBaseURI(sdkApi sdkEnv.Api) (*VirtualNetworkLinksClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "virtualnetworklinks", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating VirtualNetworkLinksClient: %+v", err) + } + + return &VirtualNetworkLinksClient{ + Client: client, + }, nil +} diff --git a/resource-manager/privatedns/2024-06-01/virtualnetworklinks/constants.go b/resource-manager/privatedns/2024-06-01/virtualnetworklinks/constants.go new file mode 100644 index 00000000000..a5aff1657b6 --- /dev/null +++ b/resource-manager/privatedns/2024-06-01/virtualnetworklinks/constants.go @@ -0,0 +1,145 @@ +package virtualnetworklinks + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProvisioningState string + +const ( + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateCreating ProvisioningState = "Creating" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateCanceled), + string(ProvisioningStateCreating), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateSucceeded), + string(ProvisioningStateUpdating), + } +} + +func (s *ProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "canceled": ProvisioningStateCanceled, + "creating": ProvisioningStateCreating, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "succeeded": ProvisioningStateSucceeded, + "updating": ProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProvisioningState(input) + return &out, nil +} + +type ResolutionPolicy string + +const ( + ResolutionPolicyDefault ResolutionPolicy = "Default" + ResolutionPolicyNxDomainRedirect ResolutionPolicy = "NxDomainRedirect" +) + +func PossibleValuesForResolutionPolicy() []string { + return []string{ + string(ResolutionPolicyDefault), + string(ResolutionPolicyNxDomainRedirect), + } +} + +func (s *ResolutionPolicy) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseResolutionPolicy(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseResolutionPolicy(input string) (*ResolutionPolicy, error) { + vals := map[string]ResolutionPolicy{ + "default": ResolutionPolicyDefault, + "nxdomainredirect": ResolutionPolicyNxDomainRedirect, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ResolutionPolicy(input) + return &out, nil +} + +type VirtualNetworkLinkState string + +const ( + VirtualNetworkLinkStateCompleted VirtualNetworkLinkState = "Completed" + VirtualNetworkLinkStateInProgress VirtualNetworkLinkState = "InProgress" +) + +func PossibleValuesForVirtualNetworkLinkState() []string { + return []string{ + string(VirtualNetworkLinkStateCompleted), + string(VirtualNetworkLinkStateInProgress), + } +} + +func (s *VirtualNetworkLinkState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseVirtualNetworkLinkState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseVirtualNetworkLinkState(input string) (*VirtualNetworkLinkState, error) { + vals := map[string]VirtualNetworkLinkState{ + "completed": VirtualNetworkLinkStateCompleted, + "inprogress": VirtualNetworkLinkStateInProgress, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := VirtualNetworkLinkState(input) + return &out, nil +} diff --git a/resource-manager/privatedns/2024-06-01/virtualnetworklinks/id_privatednszone.go b/resource-manager/privatedns/2024-06-01/virtualnetworklinks/id_privatednszone.go new file mode 100644 index 00000000000..1d07795df74 --- /dev/null +++ b/resource-manager/privatedns/2024-06-01/virtualnetworklinks/id_privatednszone.go @@ -0,0 +1,130 @@ +package virtualnetworklinks + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&PrivateDnsZoneId{}) +} + +var _ resourceids.ResourceId = &PrivateDnsZoneId{} + +// PrivateDnsZoneId is a struct representing the Resource ID for a Private Dns Zone +type PrivateDnsZoneId struct { + SubscriptionId string + ResourceGroupName string + PrivateDnsZoneName string +} + +// NewPrivateDnsZoneID returns a new PrivateDnsZoneId struct +func NewPrivateDnsZoneID(subscriptionId string, resourceGroupName string, privateDnsZoneName string) PrivateDnsZoneId { + return PrivateDnsZoneId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + PrivateDnsZoneName: privateDnsZoneName, + } +} + +// ParsePrivateDnsZoneID parses 'input' into a PrivateDnsZoneId +func ParsePrivateDnsZoneID(input string) (*PrivateDnsZoneId, error) { + parser := resourceids.NewParserFromResourceIdType(&PrivateDnsZoneId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PrivateDnsZoneId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParsePrivateDnsZoneIDInsensitively parses 'input' case-insensitively into a PrivateDnsZoneId +// note: this method should only be used for API response data and not user input +func ParsePrivateDnsZoneIDInsensitively(input string) (*PrivateDnsZoneId, error) { + parser := resourceids.NewParserFromResourceIdType(&PrivateDnsZoneId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PrivateDnsZoneId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *PrivateDnsZoneId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.PrivateDnsZoneName, ok = input.Parsed["privateDnsZoneName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "privateDnsZoneName", input) + } + + return nil +} + +// ValidatePrivateDnsZoneID checks that 'input' can be parsed as a Private Dns Zone ID +func ValidatePrivateDnsZoneID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParsePrivateDnsZoneID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Private Dns Zone ID +func (id PrivateDnsZoneId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/privateDnsZones/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.PrivateDnsZoneName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Private Dns Zone ID +func (id PrivateDnsZoneId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftNetwork", "Microsoft.Network", "Microsoft.Network"), + resourceids.StaticSegment("staticPrivateDnsZones", "privateDnsZones", "privateDnsZones"), + resourceids.UserSpecifiedSegment("privateDnsZoneName", "privateDnsZoneValue"), + } +} + +// String returns a human-readable description of this Private Dns Zone ID +func (id PrivateDnsZoneId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Private Dns Zone Name: %q", id.PrivateDnsZoneName), + } + return fmt.Sprintf("Private Dns Zone (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/privatedns/2024-06-01/virtualnetworklinks/id_privatednszone_test.go b/resource-manager/privatedns/2024-06-01/virtualnetworklinks/id_privatednszone_test.go new file mode 100644 index 00000000000..a871cb3299b --- /dev/null +++ b/resource-manager/privatedns/2024-06-01/virtualnetworklinks/id_privatednszone_test.go @@ -0,0 +1,282 @@ +package virtualnetworklinks + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &PrivateDnsZoneId{} + +func TestNewPrivateDnsZoneID(t *testing.T) { + id := NewPrivateDnsZoneID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateDnsZoneValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.PrivateDnsZoneName != "privateDnsZoneValue" { + t.Fatalf("Expected %q but got %q for Segment 'PrivateDnsZoneName'", id.PrivateDnsZoneName, "privateDnsZoneValue") + } +} + +func TestFormatPrivateDnsZoneID(t *testing.T) { + actual := NewPrivateDnsZoneID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateDnsZoneValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network/privateDnsZones/privateDnsZoneValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParsePrivateDnsZoneID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateDnsZoneId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network/privateDnsZones", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network/privateDnsZones/privateDnsZoneValue", + Expected: &PrivateDnsZoneId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + PrivateDnsZoneName: "privateDnsZoneValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network/privateDnsZones/privateDnsZoneValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateDnsZoneID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.PrivateDnsZoneName != v.Expected.PrivateDnsZoneName { + t.Fatalf("Expected %q but got %q for PrivateDnsZoneName", v.Expected.PrivateDnsZoneName, actual.PrivateDnsZoneName) + } + + } +} + +func TestParsePrivateDnsZoneIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateDnsZoneId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.nEtWoRk", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network/privateDnsZones", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.nEtWoRk/pRiVaTeDnSzOnEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network/privateDnsZones/privateDnsZoneValue", + Expected: &PrivateDnsZoneId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + PrivateDnsZoneName: "privateDnsZoneValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network/privateDnsZones/privateDnsZoneValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.nEtWoRk/pRiVaTeDnSzOnEs/pRiVaTeDnSzOnEvAlUe", + Expected: &PrivateDnsZoneId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + PrivateDnsZoneName: "pRiVaTeDnSzOnEvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.nEtWoRk/pRiVaTeDnSzOnEs/pRiVaTeDnSzOnEvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateDnsZoneIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.PrivateDnsZoneName != v.Expected.PrivateDnsZoneName { + t.Fatalf("Expected %q but got %q for PrivateDnsZoneName", v.Expected.PrivateDnsZoneName, actual.PrivateDnsZoneName) + } + + } +} + +func TestSegmentsForPrivateDnsZoneId(t *testing.T) { + segments := PrivateDnsZoneId{}.Segments() + if len(segments) == 0 { + t.Fatalf("PrivateDnsZoneId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/privatedns/2024-06-01/virtualnetworklinks/id_virtualnetworklink.go b/resource-manager/privatedns/2024-06-01/virtualnetworklinks/id_virtualnetworklink.go new file mode 100644 index 00000000000..41ad08f463d --- /dev/null +++ b/resource-manager/privatedns/2024-06-01/virtualnetworklinks/id_virtualnetworklink.go @@ -0,0 +1,139 @@ +package virtualnetworklinks + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&VirtualNetworkLinkId{}) +} + +var _ resourceids.ResourceId = &VirtualNetworkLinkId{} + +// VirtualNetworkLinkId is a struct representing the Resource ID for a Virtual Network Link +type VirtualNetworkLinkId struct { + SubscriptionId string + ResourceGroupName string + PrivateDnsZoneName string + VirtualNetworkLinkName string +} + +// NewVirtualNetworkLinkID returns a new VirtualNetworkLinkId struct +func NewVirtualNetworkLinkID(subscriptionId string, resourceGroupName string, privateDnsZoneName string, virtualNetworkLinkName string) VirtualNetworkLinkId { + return VirtualNetworkLinkId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + PrivateDnsZoneName: privateDnsZoneName, + VirtualNetworkLinkName: virtualNetworkLinkName, + } +} + +// ParseVirtualNetworkLinkID parses 'input' into a VirtualNetworkLinkId +func ParseVirtualNetworkLinkID(input string) (*VirtualNetworkLinkId, error) { + parser := resourceids.NewParserFromResourceIdType(&VirtualNetworkLinkId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := VirtualNetworkLinkId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseVirtualNetworkLinkIDInsensitively parses 'input' case-insensitively into a VirtualNetworkLinkId +// note: this method should only be used for API response data and not user input +func ParseVirtualNetworkLinkIDInsensitively(input string) (*VirtualNetworkLinkId, error) { + parser := resourceids.NewParserFromResourceIdType(&VirtualNetworkLinkId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := VirtualNetworkLinkId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *VirtualNetworkLinkId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.PrivateDnsZoneName, ok = input.Parsed["privateDnsZoneName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "privateDnsZoneName", input) + } + + if id.VirtualNetworkLinkName, ok = input.Parsed["virtualNetworkLinkName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "virtualNetworkLinkName", input) + } + + return nil +} + +// ValidateVirtualNetworkLinkID checks that 'input' can be parsed as a Virtual Network Link ID +func ValidateVirtualNetworkLinkID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseVirtualNetworkLinkID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Virtual Network Link ID +func (id VirtualNetworkLinkId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/privateDnsZones/%s/virtualNetworkLinks/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.PrivateDnsZoneName, id.VirtualNetworkLinkName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Virtual Network Link ID +func (id VirtualNetworkLinkId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftNetwork", "Microsoft.Network", "Microsoft.Network"), + resourceids.StaticSegment("staticPrivateDnsZones", "privateDnsZones", "privateDnsZones"), + resourceids.UserSpecifiedSegment("privateDnsZoneName", "privateDnsZoneValue"), + resourceids.StaticSegment("staticVirtualNetworkLinks", "virtualNetworkLinks", "virtualNetworkLinks"), + resourceids.UserSpecifiedSegment("virtualNetworkLinkName", "virtualNetworkLinkValue"), + } +} + +// String returns a human-readable description of this Virtual Network Link ID +func (id VirtualNetworkLinkId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Private Dns Zone Name: %q", id.PrivateDnsZoneName), + fmt.Sprintf("Virtual Network Link Name: %q", id.VirtualNetworkLinkName), + } + return fmt.Sprintf("Virtual Network Link (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/privatedns/2024-06-01/virtualnetworklinks/id_virtualnetworklink_test.go b/resource-manager/privatedns/2024-06-01/virtualnetworklinks/id_virtualnetworklink_test.go new file mode 100644 index 00000000000..840fcb30bc3 --- /dev/null +++ b/resource-manager/privatedns/2024-06-01/virtualnetworklinks/id_virtualnetworklink_test.go @@ -0,0 +1,327 @@ +package virtualnetworklinks + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &VirtualNetworkLinkId{} + +func TestNewVirtualNetworkLinkID(t *testing.T) { + id := NewVirtualNetworkLinkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateDnsZoneValue", "virtualNetworkLinkValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.PrivateDnsZoneName != "privateDnsZoneValue" { + t.Fatalf("Expected %q but got %q for Segment 'PrivateDnsZoneName'", id.PrivateDnsZoneName, "privateDnsZoneValue") + } + + if id.VirtualNetworkLinkName != "virtualNetworkLinkValue" { + t.Fatalf("Expected %q but got %q for Segment 'VirtualNetworkLinkName'", id.VirtualNetworkLinkName, "virtualNetworkLinkValue") + } +} + +func TestFormatVirtualNetworkLinkID(t *testing.T) { + actual := NewVirtualNetworkLinkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateDnsZoneValue", "virtualNetworkLinkValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network/privateDnsZones/privateDnsZoneValue/virtualNetworkLinks/virtualNetworkLinkValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseVirtualNetworkLinkID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VirtualNetworkLinkId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network/privateDnsZones", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network/privateDnsZones/privateDnsZoneValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network/privateDnsZones/privateDnsZoneValue/virtualNetworkLinks", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network/privateDnsZones/privateDnsZoneValue/virtualNetworkLinks/virtualNetworkLinkValue", + Expected: &VirtualNetworkLinkId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + PrivateDnsZoneName: "privateDnsZoneValue", + VirtualNetworkLinkName: "virtualNetworkLinkValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network/privateDnsZones/privateDnsZoneValue/virtualNetworkLinks/virtualNetworkLinkValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVirtualNetworkLinkID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.PrivateDnsZoneName != v.Expected.PrivateDnsZoneName { + t.Fatalf("Expected %q but got %q for PrivateDnsZoneName", v.Expected.PrivateDnsZoneName, actual.PrivateDnsZoneName) + } + + if actual.VirtualNetworkLinkName != v.Expected.VirtualNetworkLinkName { + t.Fatalf("Expected %q but got %q for VirtualNetworkLinkName", v.Expected.VirtualNetworkLinkName, actual.VirtualNetworkLinkName) + } + + } +} + +func TestParseVirtualNetworkLinkIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VirtualNetworkLinkId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.nEtWoRk", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network/privateDnsZones", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.nEtWoRk/pRiVaTeDnSzOnEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network/privateDnsZones/privateDnsZoneValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.nEtWoRk/pRiVaTeDnSzOnEs/pRiVaTeDnSzOnEvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network/privateDnsZones/privateDnsZoneValue/virtualNetworkLinks", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.nEtWoRk/pRiVaTeDnSzOnEs/pRiVaTeDnSzOnEvAlUe/vIrTuAlNeTwOrKlInKs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network/privateDnsZones/privateDnsZoneValue/virtualNetworkLinks/virtualNetworkLinkValue", + Expected: &VirtualNetworkLinkId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + PrivateDnsZoneName: "privateDnsZoneValue", + VirtualNetworkLinkName: "virtualNetworkLinkValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network/privateDnsZones/privateDnsZoneValue/virtualNetworkLinks/virtualNetworkLinkValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.nEtWoRk/pRiVaTeDnSzOnEs/pRiVaTeDnSzOnEvAlUe/vIrTuAlNeTwOrKlInKs/vIrTuAlNeTwOrKlInKvAlUe", + Expected: &VirtualNetworkLinkId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + PrivateDnsZoneName: "pRiVaTeDnSzOnEvAlUe", + VirtualNetworkLinkName: "vIrTuAlNeTwOrKlInKvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.nEtWoRk/pRiVaTeDnSzOnEs/pRiVaTeDnSzOnEvAlUe/vIrTuAlNeTwOrKlInKs/vIrTuAlNeTwOrKlInKvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVirtualNetworkLinkIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.PrivateDnsZoneName != v.Expected.PrivateDnsZoneName { + t.Fatalf("Expected %q but got %q for PrivateDnsZoneName", v.Expected.PrivateDnsZoneName, actual.PrivateDnsZoneName) + } + + if actual.VirtualNetworkLinkName != v.Expected.VirtualNetworkLinkName { + t.Fatalf("Expected %q but got %q for VirtualNetworkLinkName", v.Expected.VirtualNetworkLinkName, actual.VirtualNetworkLinkName) + } + + } +} + +func TestSegmentsForVirtualNetworkLinkId(t *testing.T) { + segments := VirtualNetworkLinkId{}.Segments() + if len(segments) == 0 { + t.Fatalf("VirtualNetworkLinkId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/privatedns/2024-06-01/virtualnetworklinks/method_createorupdate.go b/resource-manager/privatedns/2024-06-01/virtualnetworklinks/method_createorupdate.go new file mode 100644 index 00000000000..c6bc6fe5517 --- /dev/null +++ b/resource-manager/privatedns/2024-06-01/virtualnetworklinks/method_createorupdate.go @@ -0,0 +1,108 @@ +package virtualnetworklinks + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *VirtualNetworkLink +} + +type CreateOrUpdateOperationOptions struct { + IfMatch *string + IfNoneMatch *string +} + +func DefaultCreateOrUpdateOperationOptions() CreateOrUpdateOperationOptions { + return CreateOrUpdateOperationOptions{} +} + +func (o CreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + if o.IfNoneMatch != nil { + out.Append("If-None-Match", fmt.Sprintf("%v", *o.IfNoneMatch)) + } + return &out +} + +func (o CreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o CreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// CreateOrUpdate ... +func (c VirtualNetworkLinksClient) CreateOrUpdate(ctx context.Context, id VirtualNetworkLinkId, input VirtualNetworkLink, options CreateOrUpdateOperationOptions) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c VirtualNetworkLinksClient) CreateOrUpdateThenPoll(ctx context.Context, id VirtualNetworkLinkId, input VirtualNetworkLink, options CreateOrUpdateOperationOptions) error { + result, err := c.CreateOrUpdate(ctx, id, input, options) + if err != nil { + return fmt.Errorf("performing CreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after CreateOrUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/privatedns/2024-06-01/virtualnetworklinks/method_delete.go b/resource-manager/privatedns/2024-06-01/virtualnetworklinks/method_delete.go new file mode 100644 index 00000000000..d170aa216a1 --- /dev/null +++ b/resource-manager/privatedns/2024-06-01/virtualnetworklinks/method_delete.go @@ -0,0 +1,99 @@ +package virtualnetworklinks + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +type DeleteOperationOptions struct { + IfMatch *string +} + +func DefaultDeleteOperationOptions() DeleteOperationOptions { + return DeleteOperationOptions{} +} + +func (o DeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o DeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o DeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Delete ... +func (c VirtualNetworkLinksClient) Delete(ctx context.Context, id VirtualNetworkLinkId, options DeleteOperationOptions) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c VirtualNetworkLinksClient) DeleteThenPoll(ctx context.Context, id VirtualNetworkLinkId, options DeleteOperationOptions) error { + result, err := c.Delete(ctx, id, options) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} diff --git a/resource-manager/privatedns/2024-06-01/virtualnetworklinks/method_get.go b/resource-manager/privatedns/2024-06-01/virtualnetworklinks/method_get.go new file mode 100644 index 00000000000..27873563faf --- /dev/null +++ b/resource-manager/privatedns/2024-06-01/virtualnetworklinks/method_get.go @@ -0,0 +1,54 @@ +package virtualnetworklinks + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *VirtualNetworkLink +} + +// Get ... +func (c VirtualNetworkLinksClient) Get(ctx context.Context, id VirtualNetworkLinkId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model VirtualNetworkLink + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/privatedns/2024-06-01/virtualnetworklinks/method_list.go b/resource-manager/privatedns/2024-06-01/virtualnetworklinks/method_list.go new file mode 100644 index 00000000000..096ad73c974 --- /dev/null +++ b/resource-manager/privatedns/2024-06-01/virtualnetworklinks/method_list.go @@ -0,0 +1,133 @@ +package virtualnetworklinks + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]VirtualNetworkLink +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []VirtualNetworkLink +} + +type ListOperationOptions struct { + Top *int64 +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c VirtualNetworkLinksClient) List(ctx context.Context, id PrivateDnsZoneId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/virtualNetworkLinks", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]VirtualNetworkLink `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c VirtualNetworkLinksClient) ListComplete(ctx context.Context, id PrivateDnsZoneId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, VirtualNetworkLinkOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c VirtualNetworkLinksClient) ListCompleteMatchingPredicate(ctx context.Context, id PrivateDnsZoneId, options ListOperationOptions, predicate VirtualNetworkLinkOperationPredicate) (result ListCompleteResult, err error) { + items := make([]VirtualNetworkLink, 0) + + resp, err := c.List(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/privatedns/2024-06-01/virtualnetworklinks/method_update.go b/resource-manager/privatedns/2024-06-01/virtualnetworklinks/method_update.go new file mode 100644 index 00000000000..752ec2d4324 --- /dev/null +++ b/resource-manager/privatedns/2024-06-01/virtualnetworklinks/method_update.go @@ -0,0 +1,103 @@ +package virtualnetworklinks + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *VirtualNetworkLink +} + +type UpdateOperationOptions struct { + IfMatch *string +} + +func DefaultUpdateOperationOptions() UpdateOperationOptions { + return UpdateOperationOptions{} +} + +func (o UpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o UpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o UpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Update ... +func (c VirtualNetworkLinksClient) Update(ctx context.Context, id VirtualNetworkLinkId, input VirtualNetworkLink, options UpdateOperationOptions) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// UpdateThenPoll performs Update then polls until it's completed +func (c VirtualNetworkLinksClient) UpdateThenPoll(ctx context.Context, id VirtualNetworkLinkId, input VirtualNetworkLink, options UpdateOperationOptions) error { + result, err := c.Update(ctx, id, input, options) + if err != nil { + return fmt.Errorf("performing Update: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Update: %+v", err) + } + + return nil +} diff --git a/resource-manager/privatedns/2024-06-01/virtualnetworklinks/model_subresource.go b/resource-manager/privatedns/2024-06-01/virtualnetworklinks/model_subresource.go new file mode 100644 index 00000000000..070c0a5fa82 --- /dev/null +++ b/resource-manager/privatedns/2024-06-01/virtualnetworklinks/model_subresource.go @@ -0,0 +1,8 @@ +package virtualnetworklinks + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SubResource struct { + Id *string `json:"id,omitempty"` +} diff --git a/resource-manager/privatedns/2024-06-01/virtualnetworklinks/model_virtualnetworklink.go b/resource-manager/privatedns/2024-06-01/virtualnetworklinks/model_virtualnetworklink.go new file mode 100644 index 00000000000..31810004ed1 --- /dev/null +++ b/resource-manager/privatedns/2024-06-01/virtualnetworklinks/model_virtualnetworklink.go @@ -0,0 +1,14 @@ +package virtualnetworklinks + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VirtualNetworkLink struct { + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *VirtualNetworkLinkProperties `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/privatedns/2024-06-01/virtualnetworklinks/model_virtualnetworklinkproperties.go b/resource-manager/privatedns/2024-06-01/virtualnetworklinks/model_virtualnetworklinkproperties.go new file mode 100644 index 00000000000..806c581524c --- /dev/null +++ b/resource-manager/privatedns/2024-06-01/virtualnetworklinks/model_virtualnetworklinkproperties.go @@ -0,0 +1,12 @@ +package virtualnetworklinks + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VirtualNetworkLinkProperties struct { + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + RegistrationEnabled *bool `json:"registrationEnabled,omitempty"` + ResolutionPolicy *ResolutionPolicy `json:"resolutionPolicy,omitempty"` + VirtualNetwork *SubResource `json:"virtualNetwork,omitempty"` + VirtualNetworkLinkState *VirtualNetworkLinkState `json:"virtualNetworkLinkState,omitempty"` +} diff --git a/resource-manager/privatedns/2024-06-01/virtualnetworklinks/predicates.go b/resource-manager/privatedns/2024-06-01/virtualnetworklinks/predicates.go new file mode 100644 index 00000000000..2c16f4badc5 --- /dev/null +++ b/resource-manager/privatedns/2024-06-01/virtualnetworklinks/predicates.go @@ -0,0 +1,37 @@ +package virtualnetworklinks + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VirtualNetworkLinkOperationPredicate struct { + Etag *string + Id *string + Location *string + Name *string + Type *string +} + +func (p VirtualNetworkLinkOperationPredicate) Matches(input VirtualNetworkLink) bool { + + if p.Etag != nil && (input.Etag == nil || *p.Etag != *input.Etag) { + return false + } + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Location != nil && (input.Location == nil || *p.Location != *input.Location) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/privatedns/2024-06-01/virtualnetworklinks/version.go b/resource-manager/privatedns/2024-06-01/virtualnetworklinks/version.go new file mode 100644 index 00000000000..c23491db140 --- /dev/null +++ b/resource-manager/privatedns/2024-06-01/virtualnetworklinks/version.go @@ -0,0 +1,12 @@ +package virtualnetworklinks + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-06-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/virtualnetworklinks/%s", defaultApiVersion) +}