diff --git a/resource-manager/servicenetworking/2023-11-01/associationsinterface/README.md b/resource-manager/servicenetworking/2023-11-01/associationsinterface/README.md new file mode 100644 index 00000000000..f3a0d073708 --- /dev/null +++ b/resource-manager/servicenetworking/2023-11-01/associationsinterface/README.md @@ -0,0 +1,103 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/servicenetworking/2023-11-01/associationsinterface` Documentation + +The `associationsinterface` SDK allows for interaction with the Azure Resource Manager Service `servicenetworking` (API Version `2023-11-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/servicenetworking/2023-11-01/associationsinterface" +``` + + +### Client Initialization + +```go +client := associationsinterface.NewAssociationsInterfaceClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `AssociationsInterfaceClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := associationsinterface.NewAssociationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "trafficControllerValue", "associationValue") + +payload := associationsinterface.Association{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `AssociationsInterfaceClient.Delete` + +```go +ctx := context.TODO() +id := associationsinterface.NewAssociationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "trafficControllerValue", "associationValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `AssociationsInterfaceClient.Get` + +```go +ctx := context.TODO() +id := associationsinterface.NewAssociationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "trafficControllerValue", "associationValue") + +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: `AssociationsInterfaceClient.ListByTrafficController` + +```go +ctx := context.TODO() +id := associationsinterface.NewTrafficControllerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "trafficControllerValue") + +// alternatively `client.ListByTrafficController(ctx, id)` can be used to do batched pagination +items, err := client.ListByTrafficControllerComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `AssociationsInterfaceClient.Update` + +```go +ctx := context.TODO() +id := associationsinterface.NewAssociationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "trafficControllerValue", "associationValue") + +payload := associationsinterface.AssociationUpdate{ + // ... +} + + +read, err := client.Update(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/servicenetworking/2023-11-01/associationsinterface/client.go b/resource-manager/servicenetworking/2023-11-01/associationsinterface/client.go new file mode 100644 index 00000000000..3a72a214473 --- /dev/null +++ b/resource-manager/servicenetworking/2023-11-01/associationsinterface/client.go @@ -0,0 +1,26 @@ +package associationsinterface + +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 AssociationsInterfaceClient struct { + Client *resourcemanager.Client +} + +func NewAssociationsInterfaceClientWithBaseURI(sdkApi sdkEnv.Api) (*AssociationsInterfaceClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "associationsinterface", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating AssociationsInterfaceClient: %+v", err) + } + + return &AssociationsInterfaceClient{ + Client: client, + }, nil +} diff --git a/resource-manager/servicenetworking/2023-11-01/associationsinterface/constants.go b/resource-manager/servicenetworking/2023-11-01/associationsinterface/constants.go new file mode 100644 index 00000000000..b11441f4b9a --- /dev/null +++ b/resource-manager/servicenetworking/2023-11-01/associationsinterface/constants.go @@ -0,0 +1,104 @@ +package associationsinterface + +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 AssociationType string + +const ( + AssociationTypeSubnets AssociationType = "subnets" +) + +func PossibleValuesForAssociationType() []string { + return []string{ + string(AssociationTypeSubnets), + } +} + +func (s *AssociationType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAssociationType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAssociationType(input string) (*AssociationType, error) { + vals := map[string]AssociationType{ + "subnets": AssociationTypeSubnets, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AssociationType(input) + return &out, nil +} + +type ProvisioningState string + +const ( + ProvisioningStateAccepted ProvisioningState = "Accepted" + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateProvisioning ProvisioningState = "Provisioning" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateAccepted), + string(ProvisioningStateCanceled), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateProvisioning), + 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{ + "accepted": ProvisioningStateAccepted, + "canceled": ProvisioningStateCanceled, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "provisioning": ProvisioningStateProvisioning, + "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/servicenetworking/2023-11-01/associationsinterface/id_association.go b/resource-manager/servicenetworking/2023-11-01/associationsinterface/id_association.go new file mode 100644 index 00000000000..4d1f84f46dd --- /dev/null +++ b/resource-manager/servicenetworking/2023-11-01/associationsinterface/id_association.go @@ -0,0 +1,140 @@ +package associationsinterface + +import ( + "fmt" + "strings" + + "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 = AssociationId{} + +// AssociationId is a struct representing the Resource ID for a Association +type AssociationId struct { + SubscriptionId string + ResourceGroupName string + TrafficControllerName string + AssociationName string +} + +// NewAssociationID returns a new AssociationId struct +func NewAssociationID(subscriptionId string, resourceGroupName string, trafficControllerName string, associationName string) AssociationId { + return AssociationId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + TrafficControllerName: trafficControllerName, + AssociationName: associationName, + } +} + +// ParseAssociationID parses 'input' into a AssociationId +func ParseAssociationID(input string) (*AssociationId, error) { + parser := resourceids.NewParserFromResourceIdType(AssociationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := AssociationId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) + } + + if id.TrafficControllerName, ok = parsed.Parsed["trafficControllerName"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "trafficControllerName", *parsed) + } + + if id.AssociationName, ok = parsed.Parsed["associationName"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "associationName", *parsed) + } + + return &id, nil +} + +// ParseAssociationIDInsensitively parses 'input' case-insensitively into a AssociationId +// note: this method should only be used for API response data and not user input +func ParseAssociationIDInsensitively(input string) (*AssociationId, error) { + parser := resourceids.NewParserFromResourceIdType(AssociationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := AssociationId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) + } + + if id.TrafficControllerName, ok = parsed.Parsed["trafficControllerName"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "trafficControllerName", *parsed) + } + + if id.AssociationName, ok = parsed.Parsed["associationName"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "associationName", *parsed) + } + + return &id, nil +} + +// ValidateAssociationID checks that 'input' can be parsed as a Association ID +func ValidateAssociationID(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 := ParseAssociationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Association ID +func (id AssociationId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ServiceNetworking/trafficControllers/%s/associations/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.TrafficControllerName, id.AssociationName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Association ID +func (id AssociationId) 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("staticMicrosoftServiceNetworking", "Microsoft.ServiceNetworking", "Microsoft.ServiceNetworking"), + resourceids.StaticSegment("staticTrafficControllers", "trafficControllers", "trafficControllers"), + resourceids.UserSpecifiedSegment("trafficControllerName", "trafficControllerValue"), + resourceids.StaticSegment("staticAssociations", "associations", "associations"), + resourceids.UserSpecifiedSegment("associationName", "associationValue"), + } +} + +// String returns a human-readable description of this Association ID +func (id AssociationId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Traffic Controller Name: %q", id.TrafficControllerName), + fmt.Sprintf("Association Name: %q", id.AssociationName), + } + return fmt.Sprintf("Association (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/servicenetworking/2023-11-01/associationsinterface/id_association_test.go b/resource-manager/servicenetworking/2023-11-01/associationsinterface/id_association_test.go new file mode 100644 index 00000000000..7c0ee450528 --- /dev/null +++ b/resource-manager/servicenetworking/2023-11-01/associationsinterface/id_association_test.go @@ -0,0 +1,327 @@ +package associationsinterface + +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 = AssociationId{} + +func TestNewAssociationID(t *testing.T) { + id := NewAssociationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "trafficControllerValue", "associationValue") + + 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.TrafficControllerName != "trafficControllerValue" { + t.Fatalf("Expected %q but got %q for Segment 'TrafficControllerName'", id.TrafficControllerName, "trafficControllerValue") + } + + if id.AssociationName != "associationValue" { + t.Fatalf("Expected %q but got %q for Segment 'AssociationName'", id.AssociationName, "associationValue") + } +} + +func TestFormatAssociationID(t *testing.T) { + actual := NewAssociationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "trafficControllerValue", "associationValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerValue/associations/associationValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseAssociationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AssociationId + }{ + { + // 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.ServiceNetworking", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerValue/associations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerValue/associations/associationValue", + Expected: &AssociationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + TrafficControllerName: "trafficControllerValue", + AssociationName: "associationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerValue/associations/associationValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAssociationID(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.TrafficControllerName != v.Expected.TrafficControllerName { + t.Fatalf("Expected %q but got %q for TrafficControllerName", v.Expected.TrafficControllerName, actual.TrafficControllerName) + } + + if actual.AssociationName != v.Expected.AssociationName { + t.Fatalf("Expected %q but got %q for AssociationName", v.Expected.AssociationName, actual.AssociationName) + } + + } +} + +func TestParseAssociationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AssociationId + }{ + { + // 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.ServiceNetworking", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sErViCeNeTwOrKiNg", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sErViCeNeTwOrKiNg/tRaFfIcCoNtRoLlErS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sErViCeNeTwOrKiNg/tRaFfIcCoNtRoLlErS/tRaFfIcCoNtRoLlErVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerValue/associations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sErViCeNeTwOrKiNg/tRaFfIcCoNtRoLlErS/tRaFfIcCoNtRoLlErVaLuE/aSsOcIaTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerValue/associations/associationValue", + Expected: &AssociationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + TrafficControllerName: "trafficControllerValue", + AssociationName: "associationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerValue/associations/associationValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sErViCeNeTwOrKiNg/tRaFfIcCoNtRoLlErS/tRaFfIcCoNtRoLlErVaLuE/aSsOcIaTiOnS/aSsOcIaTiOnVaLuE", + Expected: &AssociationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + TrafficControllerName: "tRaFfIcCoNtRoLlErVaLuE", + AssociationName: "aSsOcIaTiOnVaLuE", + }, + }, + { + // 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.sErViCeNeTwOrKiNg/tRaFfIcCoNtRoLlErS/tRaFfIcCoNtRoLlErVaLuE/aSsOcIaTiOnS/aSsOcIaTiOnVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAssociationIDInsensitively(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.TrafficControllerName != v.Expected.TrafficControllerName { + t.Fatalf("Expected %q but got %q for TrafficControllerName", v.Expected.TrafficControllerName, actual.TrafficControllerName) + } + + if actual.AssociationName != v.Expected.AssociationName { + t.Fatalf("Expected %q but got %q for AssociationName", v.Expected.AssociationName, actual.AssociationName) + } + + } +} + +func TestSegmentsForAssociationId(t *testing.T) { + segments := AssociationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("AssociationId 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/servicenetworking/2023-11-01/associationsinterface/id_trafficcontroller.go b/resource-manager/servicenetworking/2023-11-01/associationsinterface/id_trafficcontroller.go new file mode 100644 index 00000000000..11c2580cb1a --- /dev/null +++ b/resource-manager/servicenetworking/2023-11-01/associationsinterface/id_trafficcontroller.go @@ -0,0 +1,127 @@ +package associationsinterface + +import ( + "fmt" + "strings" + + "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 = TrafficControllerId{} + +// TrafficControllerId is a struct representing the Resource ID for a Traffic Controller +type TrafficControllerId struct { + SubscriptionId string + ResourceGroupName string + TrafficControllerName string +} + +// NewTrafficControllerID returns a new TrafficControllerId struct +func NewTrafficControllerID(subscriptionId string, resourceGroupName string, trafficControllerName string) TrafficControllerId { + return TrafficControllerId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + TrafficControllerName: trafficControllerName, + } +} + +// ParseTrafficControllerID parses 'input' into a TrafficControllerId +func ParseTrafficControllerID(input string) (*TrafficControllerId, error) { + parser := resourceids.NewParserFromResourceIdType(TrafficControllerId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := TrafficControllerId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) + } + + if id.TrafficControllerName, ok = parsed.Parsed["trafficControllerName"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "trafficControllerName", *parsed) + } + + return &id, nil +} + +// ParseTrafficControllerIDInsensitively parses 'input' case-insensitively into a TrafficControllerId +// note: this method should only be used for API response data and not user input +func ParseTrafficControllerIDInsensitively(input string) (*TrafficControllerId, error) { + parser := resourceids.NewParserFromResourceIdType(TrafficControllerId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := TrafficControllerId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) + } + + if id.TrafficControllerName, ok = parsed.Parsed["trafficControllerName"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "trafficControllerName", *parsed) + } + + return &id, nil +} + +// ValidateTrafficControllerID checks that 'input' can be parsed as a Traffic Controller ID +func ValidateTrafficControllerID(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 := ParseTrafficControllerID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Traffic Controller ID +func (id TrafficControllerId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ServiceNetworking/trafficControllers/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.TrafficControllerName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Traffic Controller ID +func (id TrafficControllerId) 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("staticMicrosoftServiceNetworking", "Microsoft.ServiceNetworking", "Microsoft.ServiceNetworking"), + resourceids.StaticSegment("staticTrafficControllers", "trafficControllers", "trafficControllers"), + resourceids.UserSpecifiedSegment("trafficControllerName", "trafficControllerValue"), + } +} + +// String returns a human-readable description of this Traffic Controller ID +func (id TrafficControllerId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Traffic Controller Name: %q", id.TrafficControllerName), + } + return fmt.Sprintf("Traffic Controller (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/servicenetworking/2023-11-01/associationsinterface/id_trafficcontroller_test.go b/resource-manager/servicenetworking/2023-11-01/associationsinterface/id_trafficcontroller_test.go new file mode 100644 index 00000000000..851f018b7c2 --- /dev/null +++ b/resource-manager/servicenetworking/2023-11-01/associationsinterface/id_trafficcontroller_test.go @@ -0,0 +1,282 @@ +package associationsinterface + +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 = TrafficControllerId{} + +func TestNewTrafficControllerID(t *testing.T) { + id := NewTrafficControllerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "trafficControllerValue") + + 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.TrafficControllerName != "trafficControllerValue" { + t.Fatalf("Expected %q but got %q for Segment 'TrafficControllerName'", id.TrafficControllerName, "trafficControllerValue") + } +} + +func TestFormatTrafficControllerID(t *testing.T) { + actual := NewTrafficControllerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "trafficControllerValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseTrafficControllerID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TrafficControllerId + }{ + { + // 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.ServiceNetworking", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerValue", + Expected: &TrafficControllerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + TrafficControllerName: "trafficControllerValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTrafficControllerID(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.TrafficControllerName != v.Expected.TrafficControllerName { + t.Fatalf("Expected %q but got %q for TrafficControllerName", v.Expected.TrafficControllerName, actual.TrafficControllerName) + } + + } +} + +func TestParseTrafficControllerIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TrafficControllerId + }{ + { + // 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.ServiceNetworking", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sErViCeNeTwOrKiNg", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sErViCeNeTwOrKiNg/tRaFfIcCoNtRoLlErS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerValue", + Expected: &TrafficControllerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + TrafficControllerName: "trafficControllerValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sErViCeNeTwOrKiNg/tRaFfIcCoNtRoLlErS/tRaFfIcCoNtRoLlErVaLuE", + Expected: &TrafficControllerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + TrafficControllerName: "tRaFfIcCoNtRoLlErVaLuE", + }, + }, + { + // 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.sErViCeNeTwOrKiNg/tRaFfIcCoNtRoLlErS/tRaFfIcCoNtRoLlErVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTrafficControllerIDInsensitively(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.TrafficControllerName != v.Expected.TrafficControllerName { + t.Fatalf("Expected %q but got %q for TrafficControllerName", v.Expected.TrafficControllerName, actual.TrafficControllerName) + } + + } +} + +func TestSegmentsForTrafficControllerId(t *testing.T) { + segments := TrafficControllerId{}.Segments() + if len(segments) == 0 { + t.Fatalf("TrafficControllerId 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/servicenetworking/2023-11-01/associationsinterface/method_createorupdate.go b/resource-manager/servicenetworking/2023-11-01/associationsinterface/method_createorupdate.go new file mode 100644 index 00000000000..4cbf029c5da --- /dev/null +++ b/resource-manager/servicenetworking/2023-11-01/associationsinterface/method_createorupdate.go @@ -0,0 +1,74 @@ +package associationsinterface + +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 +} + +// CreateOrUpdate ... +func (c AssociationsInterfaceClient) CreateOrUpdate(ctx context.Context, id AssociationId, input Association) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + 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 AssociationsInterfaceClient) CreateOrUpdateThenPoll(ctx context.Context, id AssociationId, input Association) error { + result, err := c.CreateOrUpdate(ctx, id, input) + 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/servicenetworking/2023-11-01/associationsinterface/method_delete.go b/resource-manager/servicenetworking/2023-11-01/associationsinterface/method_delete.go new file mode 100644 index 00000000000..bb567ad5f67 --- /dev/null +++ b/resource-manager/servicenetworking/2023-11-01/associationsinterface/method_delete.go @@ -0,0 +1,71 @@ +package associationsinterface + +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 +} + +// Delete ... +func (c AssociationsInterfaceClient) Delete(ctx context.Context, id AssociationId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + 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 AssociationsInterfaceClient) DeleteThenPoll(ctx context.Context, id AssociationId) error { + result, err := c.Delete(ctx, id) + 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/servicenetworking/2023-11-01/associationsinterface/method_get.go b/resource-manager/servicenetworking/2023-11-01/associationsinterface/method_get.go new file mode 100644 index 00000000000..00fba0e60a8 --- /dev/null +++ b/resource-manager/servicenetworking/2023-11-01/associationsinterface/method_get.go @@ -0,0 +1,51 @@ +package associationsinterface + +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 *Association +} + +// Get ... +func (c AssociationsInterfaceClient) Get(ctx context.Context, id AssociationId) (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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/servicenetworking/2023-11-01/associationsinterface/method_listbytrafficcontroller.go b/resource-manager/servicenetworking/2023-11-01/associationsinterface/method_listbytrafficcontroller.go new file mode 100644 index 00000000000..9e40f926a0c --- /dev/null +++ b/resource-manager/servicenetworking/2023-11-01/associationsinterface/method_listbytrafficcontroller.go @@ -0,0 +1,89 @@ +package associationsinterface + +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 ListByTrafficControllerOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Association +} + +type ListByTrafficControllerCompleteResult struct { + Items []Association +} + +// ListByTrafficController ... +func (c AssociationsInterfaceClient) ListByTrafficController(ctx context.Context, id TrafficControllerId) (result ListByTrafficControllerOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/associations", 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 *[]Association `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByTrafficControllerComplete retrieves all the results into a single object +func (c AssociationsInterfaceClient) ListByTrafficControllerComplete(ctx context.Context, id TrafficControllerId) (ListByTrafficControllerCompleteResult, error) { + return c.ListByTrafficControllerCompleteMatchingPredicate(ctx, id, AssociationOperationPredicate{}) +} + +// ListByTrafficControllerCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c AssociationsInterfaceClient) ListByTrafficControllerCompleteMatchingPredicate(ctx context.Context, id TrafficControllerId, predicate AssociationOperationPredicate) (result ListByTrafficControllerCompleteResult, err error) { + items := make([]Association, 0) + + resp, err := c.ListByTrafficController(ctx, id) + if err != nil { + 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 = ListByTrafficControllerCompleteResult{ + Items: items, + } + return +} diff --git a/resource-manager/servicenetworking/2023-11-01/associationsinterface/method_update.go b/resource-manager/servicenetworking/2023-11-01/associationsinterface/method_update.go new file mode 100644 index 00000000000..aafec03f005 --- /dev/null +++ b/resource-manager/servicenetworking/2023-11-01/associationsinterface/method_update.go @@ -0,0 +1,55 @@ +package associationsinterface + +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 UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Association +} + +// Update ... +func (c AssociationsInterfaceClient) Update(ctx context.Context, id AssociationId, input AssociationUpdate) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + 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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/servicenetworking/2023-11-01/associationsinterface/model_association.go b/resource-manager/servicenetworking/2023-11-01/associationsinterface/model_association.go new file mode 100644 index 00000000000..51e5fc503be --- /dev/null +++ b/resource-manager/servicenetworking/2023-11-01/associationsinterface/model_association.go @@ -0,0 +1,18 @@ +package associationsinterface + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Association struct { + Id *string `json:"id,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *AssociationProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/servicenetworking/2023-11-01/associationsinterface/model_associationproperties.go b/resource-manager/servicenetworking/2023-11-01/associationsinterface/model_associationproperties.go new file mode 100644 index 00000000000..cb4915b6591 --- /dev/null +++ b/resource-manager/servicenetworking/2023-11-01/associationsinterface/model_associationproperties.go @@ -0,0 +1,10 @@ +package associationsinterface + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AssociationProperties struct { + AssociationType AssociationType `json:"associationType"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + Subnet *AssociationSubnet `json:"subnet,omitempty"` +} diff --git a/resource-manager/servicenetworking/2023-11-01/associationsinterface/model_associationsubnet.go b/resource-manager/servicenetworking/2023-11-01/associationsinterface/model_associationsubnet.go new file mode 100644 index 00000000000..0ca18bb5ea3 --- /dev/null +++ b/resource-manager/servicenetworking/2023-11-01/associationsinterface/model_associationsubnet.go @@ -0,0 +1,8 @@ +package associationsinterface + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AssociationSubnet struct { + Id string `json:"id"` +} diff --git a/resource-manager/servicenetworking/2023-11-01/associationsinterface/model_associationsubnetupdate.go b/resource-manager/servicenetworking/2023-11-01/associationsinterface/model_associationsubnetupdate.go new file mode 100644 index 00000000000..c24d87e1a7b --- /dev/null +++ b/resource-manager/servicenetworking/2023-11-01/associationsinterface/model_associationsubnetupdate.go @@ -0,0 +1,8 @@ +package associationsinterface + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AssociationSubnetUpdate struct { + Id *string `json:"id,omitempty"` +} diff --git a/resource-manager/servicenetworking/2023-11-01/associationsinterface/model_associationupdate.go b/resource-manager/servicenetworking/2023-11-01/associationsinterface/model_associationupdate.go new file mode 100644 index 00000000000..86f5d0c0bb2 --- /dev/null +++ b/resource-manager/servicenetworking/2023-11-01/associationsinterface/model_associationupdate.go @@ -0,0 +1,9 @@ +package associationsinterface + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AssociationUpdate struct { + Properties *AssociationUpdateProperties `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/servicenetworking/2023-11-01/associationsinterface/model_associationupdateproperties.go b/resource-manager/servicenetworking/2023-11-01/associationsinterface/model_associationupdateproperties.go new file mode 100644 index 00000000000..84beffe2c44 --- /dev/null +++ b/resource-manager/servicenetworking/2023-11-01/associationsinterface/model_associationupdateproperties.go @@ -0,0 +1,9 @@ +package associationsinterface + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AssociationUpdateProperties struct { + AssociationType *AssociationType `json:"associationType,omitempty"` + Subnet *AssociationSubnetUpdate `json:"subnet,omitempty"` +} diff --git a/resource-manager/servicenetworking/2023-11-01/associationsinterface/predicates.go b/resource-manager/servicenetworking/2023-11-01/associationsinterface/predicates.go new file mode 100644 index 00000000000..52d86740212 --- /dev/null +++ b/resource-manager/servicenetworking/2023-11-01/associationsinterface/predicates.go @@ -0,0 +1,32 @@ +package associationsinterface + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AssociationOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p AssociationOperationPredicate) Matches(input Association) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.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/servicenetworking/2023-11-01/associationsinterface/version.go b/resource-manager/servicenetworking/2023-11-01/associationsinterface/version.go new file mode 100644 index 00000000000..e61866e435f --- /dev/null +++ b/resource-manager/servicenetworking/2023-11-01/associationsinterface/version.go @@ -0,0 +1,12 @@ +package associationsinterface + +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 = "2023-11-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/associationsinterface/%s", defaultApiVersion) +} diff --git a/resource-manager/servicenetworking/2023-11-01/client.go b/resource-manager/servicenetworking/2023-11-01/client.go new file mode 100644 index 00000000000..11f90c6c536 --- /dev/null +++ b/resource-manager/servicenetworking/2023-11-01/client.go @@ -0,0 +1,46 @@ +package v2023_11_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/servicenetworking/2023-11-01/associationsinterface" + "github.com/hashicorp/go-azure-sdk/resource-manager/servicenetworking/2023-11-01/frontendsinterface" + "github.com/hashicorp/go-azure-sdk/resource-manager/servicenetworking/2023-11-01/trafficcontrollerinterface" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +type Client struct { + AssociationsInterface *associationsinterface.AssociationsInterfaceClient + FrontendsInterface *frontendsinterface.FrontendsInterfaceClient + TrafficControllerInterface *trafficcontrollerinterface.TrafficControllerInterfaceClient +} + +func NewClientWithBaseURI(sdkApi sdkEnv.Api, configureFunc func(c *resourcemanager.Client)) (*Client, error) { + associationsInterfaceClient, err := associationsinterface.NewAssociationsInterfaceClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building AssociationsInterface client: %+v", err) + } + configureFunc(associationsInterfaceClient.Client) + + frontendsInterfaceClient, err := frontendsinterface.NewFrontendsInterfaceClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building FrontendsInterface client: %+v", err) + } + configureFunc(frontendsInterfaceClient.Client) + + trafficControllerInterfaceClient, err := trafficcontrollerinterface.NewTrafficControllerInterfaceClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building TrafficControllerInterface client: %+v", err) + } + configureFunc(trafficControllerInterfaceClient.Client) + + return &Client{ + AssociationsInterface: associationsInterfaceClient, + FrontendsInterface: frontendsInterfaceClient, + TrafficControllerInterface: trafficControllerInterfaceClient, + }, nil +} diff --git a/resource-manager/servicenetworking/2023-11-01/frontendsinterface/README.md b/resource-manager/servicenetworking/2023-11-01/frontendsinterface/README.md new file mode 100644 index 00000000000..ab186331d63 --- /dev/null +++ b/resource-manager/servicenetworking/2023-11-01/frontendsinterface/README.md @@ -0,0 +1,103 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/servicenetworking/2023-11-01/frontendsinterface` Documentation + +The `frontendsinterface` SDK allows for interaction with the Azure Resource Manager Service `servicenetworking` (API Version `2023-11-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/servicenetworking/2023-11-01/frontendsinterface" +``` + + +### Client Initialization + +```go +client := frontendsinterface.NewFrontendsInterfaceClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `FrontendsInterfaceClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := frontendsinterface.NewFrontendID("12345678-1234-9876-4563-123456789012", "example-resource-group", "trafficControllerValue", "frontendValue") + +payload := frontendsinterface.Frontend{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `FrontendsInterfaceClient.Delete` + +```go +ctx := context.TODO() +id := frontendsinterface.NewFrontendID("12345678-1234-9876-4563-123456789012", "example-resource-group", "trafficControllerValue", "frontendValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `FrontendsInterfaceClient.Get` + +```go +ctx := context.TODO() +id := frontendsinterface.NewFrontendID("12345678-1234-9876-4563-123456789012", "example-resource-group", "trafficControllerValue", "frontendValue") + +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: `FrontendsInterfaceClient.ListByTrafficController` + +```go +ctx := context.TODO() +id := frontendsinterface.NewTrafficControllerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "trafficControllerValue") + +// alternatively `client.ListByTrafficController(ctx, id)` can be used to do batched pagination +items, err := client.ListByTrafficControllerComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `FrontendsInterfaceClient.Update` + +```go +ctx := context.TODO() +id := frontendsinterface.NewFrontendID("12345678-1234-9876-4563-123456789012", "example-resource-group", "trafficControllerValue", "frontendValue") + +payload := frontendsinterface.FrontendUpdate{ + // ... +} + + +read, err := client.Update(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/servicenetworking/2023-11-01/frontendsinterface/client.go b/resource-manager/servicenetworking/2023-11-01/frontendsinterface/client.go new file mode 100644 index 00000000000..ced20e82fea --- /dev/null +++ b/resource-manager/servicenetworking/2023-11-01/frontendsinterface/client.go @@ -0,0 +1,26 @@ +package frontendsinterface + +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 FrontendsInterfaceClient struct { + Client *resourcemanager.Client +} + +func NewFrontendsInterfaceClientWithBaseURI(sdkApi sdkEnv.Api) (*FrontendsInterfaceClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "frontendsinterface", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating FrontendsInterfaceClient: %+v", err) + } + + return &FrontendsInterfaceClient{ + Client: client, + }, nil +} diff --git a/resource-manager/servicenetworking/2023-11-01/frontendsinterface/constants.go b/resource-manager/servicenetworking/2023-11-01/frontendsinterface/constants.go new file mode 100644 index 00000000000..ce65291eaa3 --- /dev/null +++ b/resource-manager/servicenetworking/2023-11-01/frontendsinterface/constants.go @@ -0,0 +1,66 @@ +package frontendsinterface + +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 ( + ProvisioningStateAccepted ProvisioningState = "Accepted" + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateProvisioning ProvisioningState = "Provisioning" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateAccepted), + string(ProvisioningStateCanceled), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateProvisioning), + 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{ + "accepted": ProvisioningStateAccepted, + "canceled": ProvisioningStateCanceled, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "provisioning": ProvisioningStateProvisioning, + "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/servicenetworking/2023-11-01/frontendsinterface/id_frontend.go b/resource-manager/servicenetworking/2023-11-01/frontendsinterface/id_frontend.go new file mode 100644 index 00000000000..b7e579d0a72 --- /dev/null +++ b/resource-manager/servicenetworking/2023-11-01/frontendsinterface/id_frontend.go @@ -0,0 +1,140 @@ +package frontendsinterface + +import ( + "fmt" + "strings" + + "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 = FrontendId{} + +// FrontendId is a struct representing the Resource ID for a Frontend +type FrontendId struct { + SubscriptionId string + ResourceGroupName string + TrafficControllerName string + FrontendName string +} + +// NewFrontendID returns a new FrontendId struct +func NewFrontendID(subscriptionId string, resourceGroupName string, trafficControllerName string, frontendName string) FrontendId { + return FrontendId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + TrafficControllerName: trafficControllerName, + FrontendName: frontendName, + } +} + +// ParseFrontendID parses 'input' into a FrontendId +func ParseFrontendID(input string) (*FrontendId, error) { + parser := resourceids.NewParserFromResourceIdType(FrontendId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := FrontendId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) + } + + if id.TrafficControllerName, ok = parsed.Parsed["trafficControllerName"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "trafficControllerName", *parsed) + } + + if id.FrontendName, ok = parsed.Parsed["frontendName"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "frontendName", *parsed) + } + + return &id, nil +} + +// ParseFrontendIDInsensitively parses 'input' case-insensitively into a FrontendId +// note: this method should only be used for API response data and not user input +func ParseFrontendIDInsensitively(input string) (*FrontendId, error) { + parser := resourceids.NewParserFromResourceIdType(FrontendId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := FrontendId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) + } + + if id.TrafficControllerName, ok = parsed.Parsed["trafficControllerName"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "trafficControllerName", *parsed) + } + + if id.FrontendName, ok = parsed.Parsed["frontendName"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "frontendName", *parsed) + } + + return &id, nil +} + +// ValidateFrontendID checks that 'input' can be parsed as a Frontend ID +func ValidateFrontendID(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 := ParseFrontendID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Frontend ID +func (id FrontendId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ServiceNetworking/trafficControllers/%s/frontends/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.TrafficControllerName, id.FrontendName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Frontend ID +func (id FrontendId) 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("staticMicrosoftServiceNetworking", "Microsoft.ServiceNetworking", "Microsoft.ServiceNetworking"), + resourceids.StaticSegment("staticTrafficControllers", "trafficControllers", "trafficControllers"), + resourceids.UserSpecifiedSegment("trafficControllerName", "trafficControllerValue"), + resourceids.StaticSegment("staticFrontends", "frontends", "frontends"), + resourceids.UserSpecifiedSegment("frontendName", "frontendValue"), + } +} + +// String returns a human-readable description of this Frontend ID +func (id FrontendId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Traffic Controller Name: %q", id.TrafficControllerName), + fmt.Sprintf("Frontend Name: %q", id.FrontendName), + } + return fmt.Sprintf("Frontend (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/servicenetworking/2023-11-01/frontendsinterface/id_frontend_test.go b/resource-manager/servicenetworking/2023-11-01/frontendsinterface/id_frontend_test.go new file mode 100644 index 00000000000..2ef0f079edc --- /dev/null +++ b/resource-manager/servicenetworking/2023-11-01/frontendsinterface/id_frontend_test.go @@ -0,0 +1,327 @@ +package frontendsinterface + +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 = FrontendId{} + +func TestNewFrontendID(t *testing.T) { + id := NewFrontendID("12345678-1234-9876-4563-123456789012", "example-resource-group", "trafficControllerValue", "frontendValue") + + 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.TrafficControllerName != "trafficControllerValue" { + t.Fatalf("Expected %q but got %q for Segment 'TrafficControllerName'", id.TrafficControllerName, "trafficControllerValue") + } + + if id.FrontendName != "frontendValue" { + t.Fatalf("Expected %q but got %q for Segment 'FrontendName'", id.FrontendName, "frontendValue") + } +} + +func TestFormatFrontendID(t *testing.T) { + actual := NewFrontendID("12345678-1234-9876-4563-123456789012", "example-resource-group", "trafficControllerValue", "frontendValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerValue/frontends/frontendValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseFrontendID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *FrontendId + }{ + { + // 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.ServiceNetworking", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerValue/frontends", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerValue/frontends/frontendValue", + Expected: &FrontendId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + TrafficControllerName: "trafficControllerValue", + FrontendName: "frontendValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerValue/frontends/frontendValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseFrontendID(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.TrafficControllerName != v.Expected.TrafficControllerName { + t.Fatalf("Expected %q but got %q for TrafficControllerName", v.Expected.TrafficControllerName, actual.TrafficControllerName) + } + + if actual.FrontendName != v.Expected.FrontendName { + t.Fatalf("Expected %q but got %q for FrontendName", v.Expected.FrontendName, actual.FrontendName) + } + + } +} + +func TestParseFrontendIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *FrontendId + }{ + { + // 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.ServiceNetworking", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sErViCeNeTwOrKiNg", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sErViCeNeTwOrKiNg/tRaFfIcCoNtRoLlErS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sErViCeNeTwOrKiNg/tRaFfIcCoNtRoLlErS/tRaFfIcCoNtRoLlErVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerValue/frontends", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sErViCeNeTwOrKiNg/tRaFfIcCoNtRoLlErS/tRaFfIcCoNtRoLlErVaLuE/fRoNtEnDs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerValue/frontends/frontendValue", + Expected: &FrontendId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + TrafficControllerName: "trafficControllerValue", + FrontendName: "frontendValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerValue/frontends/frontendValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sErViCeNeTwOrKiNg/tRaFfIcCoNtRoLlErS/tRaFfIcCoNtRoLlErVaLuE/fRoNtEnDs/fRoNtEnDvAlUe", + Expected: &FrontendId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + TrafficControllerName: "tRaFfIcCoNtRoLlErVaLuE", + FrontendName: "fRoNtEnDvAlUe", + }, + }, + { + // 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.sErViCeNeTwOrKiNg/tRaFfIcCoNtRoLlErS/tRaFfIcCoNtRoLlErVaLuE/fRoNtEnDs/fRoNtEnDvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseFrontendIDInsensitively(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.TrafficControllerName != v.Expected.TrafficControllerName { + t.Fatalf("Expected %q but got %q for TrafficControllerName", v.Expected.TrafficControllerName, actual.TrafficControllerName) + } + + if actual.FrontendName != v.Expected.FrontendName { + t.Fatalf("Expected %q but got %q for FrontendName", v.Expected.FrontendName, actual.FrontendName) + } + + } +} + +func TestSegmentsForFrontendId(t *testing.T) { + segments := FrontendId{}.Segments() + if len(segments) == 0 { + t.Fatalf("FrontendId 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/servicenetworking/2023-11-01/frontendsinterface/id_trafficcontroller.go b/resource-manager/servicenetworking/2023-11-01/frontendsinterface/id_trafficcontroller.go new file mode 100644 index 00000000000..8b8821e6174 --- /dev/null +++ b/resource-manager/servicenetworking/2023-11-01/frontendsinterface/id_trafficcontroller.go @@ -0,0 +1,127 @@ +package frontendsinterface + +import ( + "fmt" + "strings" + + "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 = TrafficControllerId{} + +// TrafficControllerId is a struct representing the Resource ID for a Traffic Controller +type TrafficControllerId struct { + SubscriptionId string + ResourceGroupName string + TrafficControllerName string +} + +// NewTrafficControllerID returns a new TrafficControllerId struct +func NewTrafficControllerID(subscriptionId string, resourceGroupName string, trafficControllerName string) TrafficControllerId { + return TrafficControllerId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + TrafficControllerName: trafficControllerName, + } +} + +// ParseTrafficControllerID parses 'input' into a TrafficControllerId +func ParseTrafficControllerID(input string) (*TrafficControllerId, error) { + parser := resourceids.NewParserFromResourceIdType(TrafficControllerId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := TrafficControllerId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) + } + + if id.TrafficControllerName, ok = parsed.Parsed["trafficControllerName"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "trafficControllerName", *parsed) + } + + return &id, nil +} + +// ParseTrafficControllerIDInsensitively parses 'input' case-insensitively into a TrafficControllerId +// note: this method should only be used for API response data and not user input +func ParseTrafficControllerIDInsensitively(input string) (*TrafficControllerId, error) { + parser := resourceids.NewParserFromResourceIdType(TrafficControllerId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := TrafficControllerId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) + } + + if id.TrafficControllerName, ok = parsed.Parsed["trafficControllerName"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "trafficControllerName", *parsed) + } + + return &id, nil +} + +// ValidateTrafficControllerID checks that 'input' can be parsed as a Traffic Controller ID +func ValidateTrafficControllerID(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 := ParseTrafficControllerID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Traffic Controller ID +func (id TrafficControllerId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ServiceNetworking/trafficControllers/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.TrafficControllerName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Traffic Controller ID +func (id TrafficControllerId) 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("staticMicrosoftServiceNetworking", "Microsoft.ServiceNetworking", "Microsoft.ServiceNetworking"), + resourceids.StaticSegment("staticTrafficControllers", "trafficControllers", "trafficControllers"), + resourceids.UserSpecifiedSegment("trafficControllerName", "trafficControllerValue"), + } +} + +// String returns a human-readable description of this Traffic Controller ID +func (id TrafficControllerId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Traffic Controller Name: %q", id.TrafficControllerName), + } + return fmt.Sprintf("Traffic Controller (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/servicenetworking/2023-11-01/frontendsinterface/id_trafficcontroller_test.go b/resource-manager/servicenetworking/2023-11-01/frontendsinterface/id_trafficcontroller_test.go new file mode 100644 index 00000000000..c3168d00094 --- /dev/null +++ b/resource-manager/servicenetworking/2023-11-01/frontendsinterface/id_trafficcontroller_test.go @@ -0,0 +1,282 @@ +package frontendsinterface + +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 = TrafficControllerId{} + +func TestNewTrafficControllerID(t *testing.T) { + id := NewTrafficControllerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "trafficControllerValue") + + 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.TrafficControllerName != "trafficControllerValue" { + t.Fatalf("Expected %q but got %q for Segment 'TrafficControllerName'", id.TrafficControllerName, "trafficControllerValue") + } +} + +func TestFormatTrafficControllerID(t *testing.T) { + actual := NewTrafficControllerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "trafficControllerValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseTrafficControllerID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TrafficControllerId + }{ + { + // 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.ServiceNetworking", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerValue", + Expected: &TrafficControllerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + TrafficControllerName: "trafficControllerValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTrafficControllerID(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.TrafficControllerName != v.Expected.TrafficControllerName { + t.Fatalf("Expected %q but got %q for TrafficControllerName", v.Expected.TrafficControllerName, actual.TrafficControllerName) + } + + } +} + +func TestParseTrafficControllerIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TrafficControllerId + }{ + { + // 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.ServiceNetworking", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sErViCeNeTwOrKiNg", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sErViCeNeTwOrKiNg/tRaFfIcCoNtRoLlErS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerValue", + Expected: &TrafficControllerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + TrafficControllerName: "trafficControllerValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sErViCeNeTwOrKiNg/tRaFfIcCoNtRoLlErS/tRaFfIcCoNtRoLlErVaLuE", + Expected: &TrafficControllerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + TrafficControllerName: "tRaFfIcCoNtRoLlErVaLuE", + }, + }, + { + // 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.sErViCeNeTwOrKiNg/tRaFfIcCoNtRoLlErS/tRaFfIcCoNtRoLlErVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTrafficControllerIDInsensitively(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.TrafficControllerName != v.Expected.TrafficControllerName { + t.Fatalf("Expected %q but got %q for TrafficControllerName", v.Expected.TrafficControllerName, actual.TrafficControllerName) + } + + } +} + +func TestSegmentsForTrafficControllerId(t *testing.T) { + segments := TrafficControllerId{}.Segments() + if len(segments) == 0 { + t.Fatalf("TrafficControllerId 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/servicenetworking/2023-11-01/frontendsinterface/method_createorupdate.go b/resource-manager/servicenetworking/2023-11-01/frontendsinterface/method_createorupdate.go new file mode 100644 index 00000000000..63a12d4e357 --- /dev/null +++ b/resource-manager/servicenetworking/2023-11-01/frontendsinterface/method_createorupdate.go @@ -0,0 +1,74 @@ +package frontendsinterface + +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 +} + +// CreateOrUpdate ... +func (c FrontendsInterfaceClient) CreateOrUpdate(ctx context.Context, id FrontendId, input Frontend) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + 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 FrontendsInterfaceClient) CreateOrUpdateThenPoll(ctx context.Context, id FrontendId, input Frontend) error { + result, err := c.CreateOrUpdate(ctx, id, input) + 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/servicenetworking/2023-11-01/frontendsinterface/method_delete.go b/resource-manager/servicenetworking/2023-11-01/frontendsinterface/method_delete.go new file mode 100644 index 00000000000..5ffbaf1356c --- /dev/null +++ b/resource-manager/servicenetworking/2023-11-01/frontendsinterface/method_delete.go @@ -0,0 +1,71 @@ +package frontendsinterface + +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 +} + +// Delete ... +func (c FrontendsInterfaceClient) Delete(ctx context.Context, id FrontendId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + 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 FrontendsInterfaceClient) DeleteThenPoll(ctx context.Context, id FrontendId) error { + result, err := c.Delete(ctx, id) + 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/servicenetworking/2023-11-01/frontendsinterface/method_get.go b/resource-manager/servicenetworking/2023-11-01/frontendsinterface/method_get.go new file mode 100644 index 00000000000..7a2ebbfd4f7 --- /dev/null +++ b/resource-manager/servicenetworking/2023-11-01/frontendsinterface/method_get.go @@ -0,0 +1,51 @@ +package frontendsinterface + +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 *Frontend +} + +// Get ... +func (c FrontendsInterfaceClient) Get(ctx context.Context, id FrontendId) (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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/servicenetworking/2023-11-01/frontendsinterface/method_listbytrafficcontroller.go b/resource-manager/servicenetworking/2023-11-01/frontendsinterface/method_listbytrafficcontroller.go new file mode 100644 index 00000000000..66825da3798 --- /dev/null +++ b/resource-manager/servicenetworking/2023-11-01/frontendsinterface/method_listbytrafficcontroller.go @@ -0,0 +1,89 @@ +package frontendsinterface + +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 ListByTrafficControllerOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Frontend +} + +type ListByTrafficControllerCompleteResult struct { + Items []Frontend +} + +// ListByTrafficController ... +func (c FrontendsInterfaceClient) ListByTrafficController(ctx context.Context, id TrafficControllerId) (result ListByTrafficControllerOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/frontends", 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 *[]Frontend `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByTrafficControllerComplete retrieves all the results into a single object +func (c FrontendsInterfaceClient) ListByTrafficControllerComplete(ctx context.Context, id TrafficControllerId) (ListByTrafficControllerCompleteResult, error) { + return c.ListByTrafficControllerCompleteMatchingPredicate(ctx, id, FrontendOperationPredicate{}) +} + +// ListByTrafficControllerCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c FrontendsInterfaceClient) ListByTrafficControllerCompleteMatchingPredicate(ctx context.Context, id TrafficControllerId, predicate FrontendOperationPredicate) (result ListByTrafficControllerCompleteResult, err error) { + items := make([]Frontend, 0) + + resp, err := c.ListByTrafficController(ctx, id) + if err != nil { + 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 = ListByTrafficControllerCompleteResult{ + Items: items, + } + return +} diff --git a/resource-manager/servicenetworking/2023-11-01/frontendsinterface/method_update.go b/resource-manager/servicenetworking/2023-11-01/frontendsinterface/method_update.go new file mode 100644 index 00000000000..6caa3398cc0 --- /dev/null +++ b/resource-manager/servicenetworking/2023-11-01/frontendsinterface/method_update.go @@ -0,0 +1,55 @@ +package frontendsinterface + +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 UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Frontend +} + +// Update ... +func (c FrontendsInterfaceClient) Update(ctx context.Context, id FrontendId, input FrontendUpdate) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + 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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/servicenetworking/2023-11-01/frontendsinterface/model_frontend.go b/resource-manager/servicenetworking/2023-11-01/frontendsinterface/model_frontend.go new file mode 100644 index 00000000000..d60b842d9ca --- /dev/null +++ b/resource-manager/servicenetworking/2023-11-01/frontendsinterface/model_frontend.go @@ -0,0 +1,18 @@ +package frontendsinterface + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Frontend struct { + Id *string `json:"id,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *FrontendProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/servicenetworking/2023-11-01/frontendsinterface/model_frontendproperties.go b/resource-manager/servicenetworking/2023-11-01/frontendsinterface/model_frontendproperties.go new file mode 100644 index 00000000000..666719495f9 --- /dev/null +++ b/resource-manager/servicenetworking/2023-11-01/frontendsinterface/model_frontendproperties.go @@ -0,0 +1,9 @@ +package frontendsinterface + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FrontendProperties struct { + Fqdn *string `json:"fqdn,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/servicenetworking/2023-11-01/frontendsinterface/model_frontendupdate.go b/resource-manager/servicenetworking/2023-11-01/frontendsinterface/model_frontendupdate.go new file mode 100644 index 00000000000..ac589ede9df --- /dev/null +++ b/resource-manager/servicenetworking/2023-11-01/frontendsinterface/model_frontendupdate.go @@ -0,0 +1,8 @@ +package frontendsinterface + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FrontendUpdate struct { + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/servicenetworking/2023-11-01/frontendsinterface/predicates.go b/resource-manager/servicenetworking/2023-11-01/frontendsinterface/predicates.go new file mode 100644 index 00000000000..15b28850961 --- /dev/null +++ b/resource-manager/servicenetworking/2023-11-01/frontendsinterface/predicates.go @@ -0,0 +1,32 @@ +package frontendsinterface + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FrontendOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p FrontendOperationPredicate) Matches(input Frontend) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.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/servicenetworking/2023-11-01/frontendsinterface/version.go b/resource-manager/servicenetworking/2023-11-01/frontendsinterface/version.go new file mode 100644 index 00000000000..db233385e8e --- /dev/null +++ b/resource-manager/servicenetworking/2023-11-01/frontendsinterface/version.go @@ -0,0 +1,12 @@ +package frontendsinterface + +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 = "2023-11-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/frontendsinterface/%s", defaultApiVersion) +} diff --git a/resource-manager/servicenetworking/2023-11-01/trafficcontrollerinterface/README.md b/resource-manager/servicenetworking/2023-11-01/trafficcontrollerinterface/README.md new file mode 100644 index 00000000000..07c0a2194b0 --- /dev/null +++ b/resource-manager/servicenetworking/2023-11-01/trafficcontrollerinterface/README.md @@ -0,0 +1,120 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/servicenetworking/2023-11-01/trafficcontrollerinterface` Documentation + +The `trafficcontrollerinterface` SDK allows for interaction with the Azure Resource Manager Service `servicenetworking` (API Version `2023-11-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/servicenetworking/2023-11-01/trafficcontrollerinterface" +``` + + +### Client Initialization + +```go +client := trafficcontrollerinterface.NewTrafficControllerInterfaceClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `TrafficControllerInterfaceClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := trafficcontrollerinterface.NewTrafficControllerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "trafficControllerValue") + +payload := trafficcontrollerinterface.TrafficController{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `TrafficControllerInterfaceClient.Delete` + +```go +ctx := context.TODO() +id := trafficcontrollerinterface.NewTrafficControllerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "trafficControllerValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `TrafficControllerInterfaceClient.Get` + +```go +ctx := context.TODO() +id := trafficcontrollerinterface.NewTrafficControllerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "trafficControllerValue") + +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: `TrafficControllerInterfaceClient.ListByResourceGroup` + +```go +ctx := context.TODO() +id := trafficcontrollerinterface.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +// alternatively `client.ListByResourceGroup(ctx, id)` can be used to do batched pagination +items, err := client.ListByResourceGroupComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `TrafficControllerInterfaceClient.ListBySubscription` + +```go +ctx := context.TODO() +id := trafficcontrollerinterface.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.ListBySubscription(ctx, id)` can be used to do batched pagination +items, err := client.ListBySubscriptionComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `TrafficControllerInterfaceClient.Update` + +```go +ctx := context.TODO() +id := trafficcontrollerinterface.NewTrafficControllerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "trafficControllerValue") + +payload := trafficcontrollerinterface.TrafficControllerUpdate{ + // ... +} + + +read, err := client.Update(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/servicenetworking/2023-11-01/trafficcontrollerinterface/client.go b/resource-manager/servicenetworking/2023-11-01/trafficcontrollerinterface/client.go new file mode 100644 index 00000000000..4396983ea36 --- /dev/null +++ b/resource-manager/servicenetworking/2023-11-01/trafficcontrollerinterface/client.go @@ -0,0 +1,26 @@ +package trafficcontrollerinterface + +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 TrafficControllerInterfaceClient struct { + Client *resourcemanager.Client +} + +func NewTrafficControllerInterfaceClientWithBaseURI(sdkApi sdkEnv.Api) (*TrafficControllerInterfaceClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "trafficcontrollerinterface", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating TrafficControllerInterfaceClient: %+v", err) + } + + return &TrafficControllerInterfaceClient{ + Client: client, + }, nil +} diff --git a/resource-manager/servicenetworking/2023-11-01/trafficcontrollerinterface/constants.go b/resource-manager/servicenetworking/2023-11-01/trafficcontrollerinterface/constants.go new file mode 100644 index 00000000000..3eaf31f91f0 --- /dev/null +++ b/resource-manager/servicenetworking/2023-11-01/trafficcontrollerinterface/constants.go @@ -0,0 +1,66 @@ +package trafficcontrollerinterface + +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 ( + ProvisioningStateAccepted ProvisioningState = "Accepted" + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateProvisioning ProvisioningState = "Provisioning" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateAccepted), + string(ProvisioningStateCanceled), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateProvisioning), + 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{ + "accepted": ProvisioningStateAccepted, + "canceled": ProvisioningStateCanceled, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "provisioning": ProvisioningStateProvisioning, + "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/servicenetworking/2023-11-01/trafficcontrollerinterface/id_trafficcontroller.go b/resource-manager/servicenetworking/2023-11-01/trafficcontrollerinterface/id_trafficcontroller.go new file mode 100644 index 00000000000..785e137e845 --- /dev/null +++ b/resource-manager/servicenetworking/2023-11-01/trafficcontrollerinterface/id_trafficcontroller.go @@ -0,0 +1,127 @@ +package trafficcontrollerinterface + +import ( + "fmt" + "strings" + + "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 = TrafficControllerId{} + +// TrafficControllerId is a struct representing the Resource ID for a Traffic Controller +type TrafficControllerId struct { + SubscriptionId string + ResourceGroupName string + TrafficControllerName string +} + +// NewTrafficControllerID returns a new TrafficControllerId struct +func NewTrafficControllerID(subscriptionId string, resourceGroupName string, trafficControllerName string) TrafficControllerId { + return TrafficControllerId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + TrafficControllerName: trafficControllerName, + } +} + +// ParseTrafficControllerID parses 'input' into a TrafficControllerId +func ParseTrafficControllerID(input string) (*TrafficControllerId, error) { + parser := resourceids.NewParserFromResourceIdType(TrafficControllerId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := TrafficControllerId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) + } + + if id.TrafficControllerName, ok = parsed.Parsed["trafficControllerName"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "trafficControllerName", *parsed) + } + + return &id, nil +} + +// ParseTrafficControllerIDInsensitively parses 'input' case-insensitively into a TrafficControllerId +// note: this method should only be used for API response data and not user input +func ParseTrafficControllerIDInsensitively(input string) (*TrafficControllerId, error) { + parser := resourceids.NewParserFromResourceIdType(TrafficControllerId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := TrafficControllerId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) + } + + if id.TrafficControllerName, ok = parsed.Parsed["trafficControllerName"]; !ok { + return nil, resourceids.NewSegmentNotSpecifiedError(id, "trafficControllerName", *parsed) + } + + return &id, nil +} + +// ValidateTrafficControllerID checks that 'input' can be parsed as a Traffic Controller ID +func ValidateTrafficControllerID(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 := ParseTrafficControllerID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Traffic Controller ID +func (id TrafficControllerId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ServiceNetworking/trafficControllers/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.TrafficControllerName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Traffic Controller ID +func (id TrafficControllerId) 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("staticMicrosoftServiceNetworking", "Microsoft.ServiceNetworking", "Microsoft.ServiceNetworking"), + resourceids.StaticSegment("staticTrafficControllers", "trafficControllers", "trafficControllers"), + resourceids.UserSpecifiedSegment("trafficControllerName", "trafficControllerValue"), + } +} + +// String returns a human-readable description of this Traffic Controller ID +func (id TrafficControllerId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Traffic Controller Name: %q", id.TrafficControllerName), + } + return fmt.Sprintf("Traffic Controller (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/servicenetworking/2023-11-01/trafficcontrollerinterface/id_trafficcontroller_test.go b/resource-manager/servicenetworking/2023-11-01/trafficcontrollerinterface/id_trafficcontroller_test.go new file mode 100644 index 00000000000..0f21a5a7275 --- /dev/null +++ b/resource-manager/servicenetworking/2023-11-01/trafficcontrollerinterface/id_trafficcontroller_test.go @@ -0,0 +1,282 @@ +package trafficcontrollerinterface + +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 = TrafficControllerId{} + +func TestNewTrafficControllerID(t *testing.T) { + id := NewTrafficControllerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "trafficControllerValue") + + 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.TrafficControllerName != "trafficControllerValue" { + t.Fatalf("Expected %q but got %q for Segment 'TrafficControllerName'", id.TrafficControllerName, "trafficControllerValue") + } +} + +func TestFormatTrafficControllerID(t *testing.T) { + actual := NewTrafficControllerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "trafficControllerValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseTrafficControllerID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TrafficControllerId + }{ + { + // 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.ServiceNetworking", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerValue", + Expected: &TrafficControllerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + TrafficControllerName: "trafficControllerValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTrafficControllerID(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.TrafficControllerName != v.Expected.TrafficControllerName { + t.Fatalf("Expected %q but got %q for TrafficControllerName", v.Expected.TrafficControllerName, actual.TrafficControllerName) + } + + } +} + +func TestParseTrafficControllerIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TrafficControllerId + }{ + { + // 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.ServiceNetworking", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sErViCeNeTwOrKiNg", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sErViCeNeTwOrKiNg/tRaFfIcCoNtRoLlErS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerValue", + Expected: &TrafficControllerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + TrafficControllerName: "trafficControllerValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sErViCeNeTwOrKiNg/tRaFfIcCoNtRoLlErS/tRaFfIcCoNtRoLlErVaLuE", + Expected: &TrafficControllerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + TrafficControllerName: "tRaFfIcCoNtRoLlErVaLuE", + }, + }, + { + // 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.sErViCeNeTwOrKiNg/tRaFfIcCoNtRoLlErS/tRaFfIcCoNtRoLlErVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTrafficControllerIDInsensitively(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.TrafficControllerName != v.Expected.TrafficControllerName { + t.Fatalf("Expected %q but got %q for TrafficControllerName", v.Expected.TrafficControllerName, actual.TrafficControllerName) + } + + } +} + +func TestSegmentsForTrafficControllerId(t *testing.T) { + segments := TrafficControllerId{}.Segments() + if len(segments) == 0 { + t.Fatalf("TrafficControllerId 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/servicenetworking/2023-11-01/trafficcontrollerinterface/method_createorupdate.go b/resource-manager/servicenetworking/2023-11-01/trafficcontrollerinterface/method_createorupdate.go new file mode 100644 index 00000000000..eac3b25ea15 --- /dev/null +++ b/resource-manager/servicenetworking/2023-11-01/trafficcontrollerinterface/method_createorupdate.go @@ -0,0 +1,74 @@ +package trafficcontrollerinterface + +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 +} + +// CreateOrUpdate ... +func (c TrafficControllerInterfaceClient) CreateOrUpdate(ctx context.Context, id TrafficControllerId, input TrafficController) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + 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 TrafficControllerInterfaceClient) CreateOrUpdateThenPoll(ctx context.Context, id TrafficControllerId, input TrafficController) error { + result, err := c.CreateOrUpdate(ctx, id, input) + 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/servicenetworking/2023-11-01/trafficcontrollerinterface/method_delete.go b/resource-manager/servicenetworking/2023-11-01/trafficcontrollerinterface/method_delete.go new file mode 100644 index 00000000000..fdc18f1a9f5 --- /dev/null +++ b/resource-manager/servicenetworking/2023-11-01/trafficcontrollerinterface/method_delete.go @@ -0,0 +1,71 @@ +package trafficcontrollerinterface + +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 +} + +// Delete ... +func (c TrafficControllerInterfaceClient) Delete(ctx context.Context, id TrafficControllerId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + 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 TrafficControllerInterfaceClient) DeleteThenPoll(ctx context.Context, id TrafficControllerId) error { + result, err := c.Delete(ctx, id) + 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/servicenetworking/2023-11-01/trafficcontrollerinterface/method_get.go b/resource-manager/servicenetworking/2023-11-01/trafficcontrollerinterface/method_get.go new file mode 100644 index 00000000000..7ef890671c3 --- /dev/null +++ b/resource-manager/servicenetworking/2023-11-01/trafficcontrollerinterface/method_get.go @@ -0,0 +1,51 @@ +package trafficcontrollerinterface + +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 *TrafficController +} + +// Get ... +func (c TrafficControllerInterfaceClient) Get(ctx context.Context, id TrafficControllerId) (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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/servicenetworking/2023-11-01/trafficcontrollerinterface/method_listbyresourcegroup.go b/resource-manager/servicenetworking/2023-11-01/trafficcontrollerinterface/method_listbyresourcegroup.go new file mode 100644 index 00000000000..1359081f2db --- /dev/null +++ b/resource-manager/servicenetworking/2023-11-01/trafficcontrollerinterface/method_listbyresourcegroup.go @@ -0,0 +1,90 @@ +package trafficcontrollerinterface + +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 *[]TrafficController +} + +type ListByResourceGroupCompleteResult struct { + Items []TrafficController +} + +// ListByResourceGroup ... +func (c TrafficControllerInterfaceClient) ListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (result ListByResourceGroupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.ServiceNetworking/trafficControllers", 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 *[]TrafficController `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 TrafficControllerInterfaceClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (ListByResourceGroupCompleteResult, error) { + return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, TrafficControllerOperationPredicate{}) +} + +// ListByResourceGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c TrafficControllerInterfaceClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate TrafficControllerOperationPredicate) (result ListByResourceGroupCompleteResult, err error) { + items := make([]TrafficController, 0) + + resp, err := c.ListByResourceGroup(ctx, id) + if err != nil { + 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{ + Items: items, + } + return +} diff --git a/resource-manager/servicenetworking/2023-11-01/trafficcontrollerinterface/method_listbysubscription.go b/resource-manager/servicenetworking/2023-11-01/trafficcontrollerinterface/method_listbysubscription.go new file mode 100644 index 00000000000..88c9a83acb3 --- /dev/null +++ b/resource-manager/servicenetworking/2023-11-01/trafficcontrollerinterface/method_listbysubscription.go @@ -0,0 +1,90 @@ +package trafficcontrollerinterface + +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 ListBySubscriptionOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]TrafficController +} + +type ListBySubscriptionCompleteResult struct { + Items []TrafficController +} + +// ListBySubscription ... +func (c TrafficControllerInterfaceClient) ListBySubscription(ctx context.Context, id commonids.SubscriptionId) (result ListBySubscriptionOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.ServiceNetworking/trafficControllers", 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 *[]TrafficController `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListBySubscriptionComplete retrieves all the results into a single object +func (c TrafficControllerInterfaceClient) ListBySubscriptionComplete(ctx context.Context, id commonids.SubscriptionId) (ListBySubscriptionCompleteResult, error) { + return c.ListBySubscriptionCompleteMatchingPredicate(ctx, id, TrafficControllerOperationPredicate{}) +} + +// ListBySubscriptionCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c TrafficControllerInterfaceClient) ListBySubscriptionCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate TrafficControllerOperationPredicate) (result ListBySubscriptionCompleteResult, err error) { + items := make([]TrafficController, 0) + + resp, err := c.ListBySubscription(ctx, id) + if err != nil { + 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 = ListBySubscriptionCompleteResult{ + Items: items, + } + return +} diff --git a/resource-manager/servicenetworking/2023-11-01/trafficcontrollerinterface/method_update.go b/resource-manager/servicenetworking/2023-11-01/trafficcontrollerinterface/method_update.go new file mode 100644 index 00000000000..c69f068992a --- /dev/null +++ b/resource-manager/servicenetworking/2023-11-01/trafficcontrollerinterface/method_update.go @@ -0,0 +1,55 @@ +package trafficcontrollerinterface + +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 UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *TrafficController +} + +// Update ... +func (c TrafficControllerInterfaceClient) Update(ctx context.Context, id TrafficControllerId, input TrafficControllerUpdate) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + 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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/servicenetworking/2023-11-01/trafficcontrollerinterface/model_resourceid.go b/resource-manager/servicenetworking/2023-11-01/trafficcontrollerinterface/model_resourceid.go new file mode 100644 index 00000000000..bb565db648e --- /dev/null +++ b/resource-manager/servicenetworking/2023-11-01/trafficcontrollerinterface/model_resourceid.go @@ -0,0 +1,8 @@ +package trafficcontrollerinterface + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceId struct { + Id string `json:"id"` +} diff --git a/resource-manager/servicenetworking/2023-11-01/trafficcontrollerinterface/model_trafficcontroller.go b/resource-manager/servicenetworking/2023-11-01/trafficcontrollerinterface/model_trafficcontroller.go new file mode 100644 index 00000000000..2c3e90dd16b --- /dev/null +++ b/resource-manager/servicenetworking/2023-11-01/trafficcontrollerinterface/model_trafficcontroller.go @@ -0,0 +1,18 @@ +package trafficcontrollerinterface + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TrafficController struct { + Id *string `json:"id,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *TrafficControllerProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/servicenetworking/2023-11-01/trafficcontrollerinterface/model_trafficcontrollerproperties.go b/resource-manager/servicenetworking/2023-11-01/trafficcontrollerinterface/model_trafficcontrollerproperties.go new file mode 100644 index 00000000000..49c8e3f49e2 --- /dev/null +++ b/resource-manager/servicenetworking/2023-11-01/trafficcontrollerinterface/model_trafficcontrollerproperties.go @@ -0,0 +1,11 @@ +package trafficcontrollerinterface + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TrafficControllerProperties struct { + Associations *[]ResourceId `json:"associations,omitempty"` + ConfigurationEndpoints *[]string `json:"configurationEndpoints,omitempty"` + Frontends *[]ResourceId `json:"frontends,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/servicenetworking/2023-11-01/trafficcontrollerinterface/model_trafficcontrollerupdate.go b/resource-manager/servicenetworking/2023-11-01/trafficcontrollerinterface/model_trafficcontrollerupdate.go new file mode 100644 index 00000000000..2f2d0897d29 --- /dev/null +++ b/resource-manager/servicenetworking/2023-11-01/trafficcontrollerinterface/model_trafficcontrollerupdate.go @@ -0,0 +1,8 @@ +package trafficcontrollerinterface + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TrafficControllerUpdate struct { + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/servicenetworking/2023-11-01/trafficcontrollerinterface/predicates.go b/resource-manager/servicenetworking/2023-11-01/trafficcontrollerinterface/predicates.go new file mode 100644 index 00000000000..3f8bcc32db3 --- /dev/null +++ b/resource-manager/servicenetworking/2023-11-01/trafficcontrollerinterface/predicates.go @@ -0,0 +1,32 @@ +package trafficcontrollerinterface + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TrafficControllerOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p TrafficControllerOperationPredicate) Matches(input TrafficController) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.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/servicenetworking/2023-11-01/trafficcontrollerinterface/version.go b/resource-manager/servicenetworking/2023-11-01/trafficcontrollerinterface/version.go new file mode 100644 index 00000000000..ca9d4837ab4 --- /dev/null +++ b/resource-manager/servicenetworking/2023-11-01/trafficcontrollerinterface/version.go @@ -0,0 +1,12 @@ +package trafficcontrollerinterface + +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 = "2023-11-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/trafficcontrollerinterface/%s", defaultApiVersion) +}