From 76122296f70fb924a1582e133f986744585c36c1 Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Tue, 9 Nov 2021 17:09:09 -0800 Subject: [PATCH] regen embedded sdk --- .../sdk/2020-05-01/signalr/constants.go | 214 ++++++++++++++ .../sdk/2020-05-01/signalr/id_location.go | 120 ++++---- .../2020-05-01/signalr/id_location_test.go | 173 ++++++----- .../signalr/id_privateendpointconnection.go | 165 ++++++----- .../id_privateendpointconnection_test.go | 277 ++++++++++-------- .../2020-05-01/signalr/id_resourcegroup.go | 118 ++++---- .../signalr/id_resourcegroup_test.go | 149 +++++----- .../sdk/2020-05-01/signalr/id_signalr.go | 142 +++++---- .../sdk/2020-05-01/signalr/id_signalr_test.go | 225 ++++++++------ .../sdk/2020-05-01/signalr/id_subscription.go | 93 +++--- .../signalr/id_subscription_test.go | 97 +++--- .../method_listbyresourcegroup_autorest.go | 2 +- .../method_listbysubscription_autorest.go | 2 +- .../sdk/2020-05-01/signalr/predicates.go | 3 + .../signalr/signalr_service_data_source.go | 4 +- .../signalr_service_network_acl_resource.go | 8 +- .../signalr/signalr_service_resource.go | 4 +- 17 files changed, 1096 insertions(+), 700 deletions(-) diff --git a/internal/services/signalr/sdk/2020-05-01/signalr/constants.go b/internal/services/signalr/sdk/2020-05-01/signalr/constants.go index 1f982d19ce45..4c42834377bc 100644 --- a/internal/services/signalr/sdk/2020-05-01/signalr/constants.go +++ b/internal/services/signalr/sdk/2020-05-01/signalr/constants.go @@ -1,5 +1,7 @@ package signalr +import "strings" + type ACLAction string const ( @@ -7,6 +9,29 @@ const ( ACLActionDeny ACLAction = "Deny" ) +func PossibleValuesForACLAction() []string { + return []string{ + "Allow", + "Deny", + } +} + +func parseACLAction(input string) (*ACLAction, error) { + vals := map[string]ACLAction{ + "allow": "Allow", + "deny": "Deny", + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // it could be a new value - best effort convert this + v := input + + out := ACLAction(v) + return &out, nil +} + type FeatureFlags string const ( @@ -15,6 +40,31 @@ const ( FeatureFlagsServiceMode FeatureFlags = "ServiceMode" ) +func PossibleValuesForFeatureFlags() []string { + return []string{ + "EnableConnectivityLogs", + "EnableMessagingLogs", + "ServiceMode", + } +} + +func parseFeatureFlags(input string) (*FeatureFlags, error) { + vals := map[string]FeatureFlags{ + "enableconnectivitylogs": "EnableConnectivityLogs", + "enablemessaginglogs": "EnableMessagingLogs", + "servicemode": "ServiceMode", + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // it could be a new value - best effort convert this + v := input + + out := FeatureFlags(v) + return &out, nil +} + type KeyType string const ( @@ -22,6 +72,29 @@ const ( KeyTypeSecondary KeyType = "Secondary" ) +func PossibleValuesForKeyType() []string { + return []string{ + "Primary", + "Secondary", + } +} + +func parseKeyType(input string) (*KeyType, error) { + vals := map[string]KeyType{ + "primary": "Primary", + "secondary": "Secondary", + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // it could be a new value - best effort convert this + v := input + + out := KeyType(v) + return &out, nil +} + type PrivateLinkServiceConnectionStatus string const ( @@ -31,6 +104,33 @@ const ( PrivateLinkServiceConnectionStatusRejected PrivateLinkServiceConnectionStatus = "Rejected" ) +func PossibleValuesForPrivateLinkServiceConnectionStatus() []string { + return []string{ + "Approved", + "Disconnected", + "Pending", + "Rejected", + } +} + +func parsePrivateLinkServiceConnectionStatus(input string) (*PrivateLinkServiceConnectionStatus, error) { + vals := map[string]PrivateLinkServiceConnectionStatus{ + "approved": "Approved", + "disconnected": "Disconnected", + "pending": "Pending", + "rejected": "Rejected", + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // it could be a new value - best effort convert this + v := input + + out := PrivateLinkServiceConnectionStatus(v) + return &out, nil +} + type ProvisioningState string const ( @@ -45,6 +145,43 @@ const ( ProvisioningStateUpdating ProvisioningState = "Updating" ) +func PossibleValuesForProvisioningState() []string { + return []string{ + "Canceled", + "Creating", + "Deleting", + "Failed", + "Moving", + "Running", + "Succeeded", + "Unknown", + "Updating", + } +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "canceled": "Canceled", + "creating": "Creating", + "deleting": "Deleting", + "failed": "Failed", + "moving": "Moving", + "running": "Running", + "succeeded": "Succeeded", + "unknown": "Unknown", + "updating": "Updating", + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // it could be a new value - best effort convert this + v := input + + out := ProvisioningState(v) + return &out, nil +} + type ServiceKind string const ( @@ -52,6 +189,29 @@ const ( ServiceKindSignalR ServiceKind = "SignalR" ) +func PossibleValuesForServiceKind() []string { + return []string{ + "RawWebSockets", + "SignalR", + } +} + +func parseServiceKind(input string) (*ServiceKind, error) { + vals := map[string]ServiceKind{ + "rawwebsockets": "RawWebSockets", + "signalr": "SignalR", + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // it could be a new value - best effort convert this + v := input + + out := ServiceKind(v) + return &out, nil +} + type SignalRRequestType string const ( @@ -61,6 +221,33 @@ const ( SignalRRequestTypeTrace SignalRRequestType = "Trace" ) +func PossibleValuesForSignalRRequestType() []string { + return []string{ + "ClientConnection", + "RESTAPI", + "ServerConnection", + "Trace", + } +} + +func parseSignalRRequestType(input string) (*SignalRRequestType, error) { + vals := map[string]SignalRRequestType{ + "clientconnection": "ClientConnection", + "restapi": "RESTAPI", + "serverconnection": "ServerConnection", + "trace": "Trace", + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // it could be a new value - best effort convert this + v := input + + out := SignalRRequestType(v) + return &out, nil +} + type SignalRSkuTier string const ( @@ -69,3 +256,30 @@ const ( SignalRSkuTierPremium SignalRSkuTier = "Premium" SignalRSkuTierStandard SignalRSkuTier = "Standard" ) + +func PossibleValuesForSignalRSkuTier() []string { + return []string{ + "Basic", + "Free", + "Premium", + "Standard", + } +} + +func parseSignalRSkuTier(input string) (*SignalRSkuTier, error) { + vals := map[string]SignalRSkuTier{ + "basic": "Basic", + "free": "Free", + "premium": "Premium", + "standard": "Standard", + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // it could be a new value - best effort convert this + v := input + + out := SignalRSkuTier(v) + return &out, nil +} diff --git a/internal/services/signalr/sdk/2020-05-01/signalr/id_location.go b/internal/services/signalr/sdk/2020-05-01/signalr/id_location.go index 05db42532df1..d26267c38243 100644 --- a/internal/services/signalr/sdk/2020-05-01/signalr/id_location.go +++ b/internal/services/signalr/sdk/2020-05-01/signalr/id_location.go @@ -7,89 +7,105 @@ import ( "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" ) +var _ resourceids.ResourceId = LocationId{} + +// LocationId is a struct representing the Resource ID for a Location type LocationId struct { SubscriptionId string - Name string + Location string } -func NewLocationID(subscriptionId, name string) LocationId { +// NewLocationID returns a new LocationId struct +func NewLocationID(subscriptionId string, location string) LocationId { return LocationId{ SubscriptionId: subscriptionId, - Name: name, + Location: location, } } -func (id LocationId) String() string { - segments := []string{ - fmt.Sprintf("Name %q", id.Name), - } - segmentsStr := strings.Join(segments, " / ") - return fmt.Sprintf("%s: (%s)", "Location", segmentsStr) -} - -func (id LocationId) ID() string { - fmtString := "/subscriptions/%s/providers/Microsoft.SignalRService/locations/%s" - return fmt.Sprintf(fmtString, id.SubscriptionId, id.Name) -} - -// ParseLocationID parses a Location ID into an LocationId struct +// ParseLocationID parses 'input' into a LocationId func ParseLocationID(input string) (*LocationId, error) { - id, err := resourceids.ParseAzureResourceID(input) + parser := resourceids.NewParserFromResourceIdType(LocationId{}) + parsed, err := parser.Parse(input, false) if err != nil { - return nil, err - } - - resourceId := LocationId{ - SubscriptionId: id.SubscriptionID, + return nil, fmt.Errorf("parsing %q: %+v", input, err) } - if resourceId.SubscriptionId == "" { - return nil, fmt.Errorf("ID was missing the 'subscriptions' element") - } + var ok bool + id := LocationId{} - if resourceId.Name, err = id.PopSegment("locations"); err != nil { - return nil, err + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) } - if err := id.ValidateNoEmptySegments(input); err != nil { - return nil, err + if id.Location, ok = parsed.Parsed["location"]; !ok { + return nil, fmt.Errorf("the segment 'location' was not found in the resource id %q", input) } - return &resourceId, nil + return &id, nil } -// ParseLocationIDInsensitively parses an Location ID into an LocationId struct, insensitively -// This should only be used to parse an ID for rewriting to a consistent casing, -// the ParseLocationID method should be used instead for validation etc. +// ParseLocationIDInsensitively parses 'input' case-insensitively into a LocationId +// note: this method should only be used for API response data and not user input func ParseLocationIDInsensitively(input string) (*LocationId, error) { - id, err := resourceids.ParseAzureResourceID(input) + parser := resourceids.NewParserFromResourceIdType(LocationId{}) + parsed, err := parser.Parse(input, true) if err != nil { - return nil, err + return nil, fmt.Errorf("parsing %q: %+v", input, err) } - resourceId := LocationId{ - SubscriptionId: id.SubscriptionID, + var ok bool + id := LocationId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) } - if resourceId.SubscriptionId == "" { - return nil, fmt.Errorf("ID was missing the 'subscriptions' element") + if id.Location, ok = parsed.Parsed["location"]; !ok { + return nil, fmt.Errorf("the segment 'location' was not found in the resource id %q", input) } - // find the correct casing for the 'locations' segment - locationsKey := "locations" - for key := range id.Path { - if strings.EqualFold(key, locationsKey) { - locationsKey = key - break - } + return &id, nil +} + +// ValidateLocationID checks that 'input' can be parsed as a Location ID +func ValidateLocationID(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 resourceId.Name, err = id.PopSegment(locationsKey); err != nil { - return nil, err + + if _, err := ParseLocationID(v); err != nil { + errors = append(errors, err) } - if err := id.ValidateNoEmptySegments(input); err != nil { - return nil, err + return +} + +// ID returns the formatted Location ID +func (id LocationId) ID() string { + fmtString := "/subscriptions/%s/providers/Microsoft.SignalRService/locations/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.Location) +} + +// Segments returns a slice of Resource ID Segments which comprise this Location ID +func (id LocationId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("subscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("providers", "providers", "providers"), + resourceids.ResourceProviderSegment("microsoftSignalRService", "Microsoft.SignalRService", "Microsoft.SignalRService"), + resourceids.StaticSegment("locations", "locations", "locations"), + resourceids.UserSpecifiedSegment("location", "locationValue"), } +} - return &resourceId, nil +// String returns a human-readable description of this Location ID +func (id LocationId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Location: %q", id.Location), + } + return fmt.Sprintf("Location (%s)", strings.Join(components, "\n")) } diff --git a/internal/services/signalr/sdk/2020-05-01/signalr/id_location_test.go b/internal/services/signalr/sdk/2020-05-01/signalr/id_location_test.go index 288a1876d917..83d653586f0a 100644 --- a/internal/services/signalr/sdk/2020-05-01/signalr/id_location_test.go +++ b/internal/services/signalr/sdk/2020-05-01/signalr/id_location_test.go @@ -6,13 +6,25 @@ import ( "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" ) -var _ resourceids.Id = LocationId{} +var _ resourceids.ResourceId = LocationId{} -func TestLocationIDFormatter(t *testing.T) { - actual := NewLocationID("{subscriptionId}", "{location}").ID() - expected := "/subscriptions/{subscriptionId}/providers/Microsoft.SignalRService/locations/{location}" +func TestNewLocationID(t *testing.T) { + id := NewLocationID("12345678-1234-9876-4563-123456789012", "locationValue") + + 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.Location != "locationValue" { + t.Fatalf("Expected %q but got %q for Segment 'Location'", id.Location, "locationValue") + } +} + +func TestFormatLocationID(t *testing.T) { + actual := NewLocationID("12345678-1234-9876-4563-123456789012", "locationValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.SignalRService/locations/locationValue" if actual != expected { - t.Fatalf("Expected %q but got %q", expected, actual) + t.Fatalf("Expected the Formatted ID to be %q but got %q", actual, expected) } } @@ -22,53 +34,50 @@ func TestParseLocationID(t *testing.T) { Error bool Expected *LocationId }{ - { - // empty + // Incomplete URI Input: "", Error: true, }, - { - // missing SubscriptionId - Input: "/", + // Incomplete URI + Input: "/subscriptions", Error: true, }, - { - // missing value for SubscriptionId - Input: "/subscriptions/", + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", Error: true, }, - { - // missing Name - Input: "/subscriptions/{subscriptionId}/providers/Microsoft.SignalRService/", + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers", Error: true, }, - { - // missing value for Name - Input: "/subscriptions/{subscriptionId}/providers/Microsoft.SignalRService/locations/", + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.SignalRService", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.SignalRService/locations", Error: true, }, - { - // valid - Input: "/subscriptions/{subscriptionId}/providers/Microsoft.SignalRService/locations/{location}", + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.SignalRService/locations/locationValue", Expected: &LocationId{ - SubscriptionId: "{subscriptionId}", - Name: "{location}", + SubscriptionId: "12345678-1234-9876-4563-123456789012", + Location: "locationValue", }, }, - { - // upper-cased - Input: "/SUBSCRIPTIONS/{SUBSCRIPTIONID}/PROVIDERS/MICROSOFT.SIGNALRSERVICE/LOCATIONS/{LOCATION}", + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.SignalRService/locations/locationValue/extra", Error: true, }, } - for _, v := range testData { t.Logf("[DEBUG] Testing %q", v.Input) @@ -78,7 +87,7 @@ func TestParseLocationID(t *testing.T) { continue } - t.Fatalf("Expect a value but got an error: %s", err) + t.Fatalf("Expect a value but got an error: %+v", err) } if v.Error { t.Fatal("Expect an error but didn't get one") @@ -87,9 +96,11 @@ func TestParseLocationID(t *testing.T) { if actual.SubscriptionId != v.Expected.SubscriptionId { t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) } - if actual.Name != v.Expected.Name { - t.Fatalf("Expected %q but got %q for Name", v.Expected.Name, actual.Name) + + if actual.Location != v.Expected.Location { + t.Fatalf("Expected %q but got %q for Location", v.Expected.Location, actual.Location) } + } } @@ -99,74 +110,88 @@ func TestParseLocationIDInsensitively(t *testing.T) { Error bool Expected *LocationId }{ - { - // empty + // Incomplete URI Input: "", Error: true, }, - { - // missing SubscriptionId - Input: "/", + // Incomplete URI + Input: "/subscriptions", Error: true, }, - { - // missing value for SubscriptionId - Input: "/subscriptions/", + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", Error: true, }, - { - // missing Name - Input: "/subscriptions/{subscriptionId}/providers/Microsoft.SignalRService/", + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", Error: true, }, - { - // missing value for Name - Input: "/subscriptions/{subscriptionId}/providers/Microsoft.SignalRService/locations/", + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", Error: true, }, - { - // valid - Input: "/subscriptions/{subscriptionId}/providers/Microsoft.SignalRService/locations/{location}", - Expected: &LocationId{ - SubscriptionId: "{subscriptionId}", - Name: "{location}", - }, + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, }, - { - // lower-cased segment names - Input: "/subscriptions/{subscriptionId}/providers/Microsoft.SignalRService/locations/{location}", - Expected: &LocationId{ - SubscriptionId: "{subscriptionId}", - Name: "{location}", - }, + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.SignalRService", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.SignalRService/locations", + Error: true, }, - { - // upper-cased segment names - Input: "/subscriptions/{subscriptionId}/providers/Microsoft.SignalRService/LOCATIONS/{location}", + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE/lOcAtIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.SignalRService/locations/locationValue", Expected: &LocationId{ - SubscriptionId: "{subscriptionId}", - Name: "{location}", + SubscriptionId: "12345678-1234-9876-4563-123456789012", + Location: "locationValue", }, }, - { - // mixed-cased segment names - Input: "/subscriptions/{subscriptionId}/providers/Microsoft.SignalRService/LoCaTiOnS/{location}", + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.SignalRService/locations/locationValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE/lOcAtIoNs/lOcAtIoNvAlUe", Expected: &LocationId{ - SubscriptionId: "{subscriptionId}", - Name: "{location}", + SubscriptionId: "12345678-1234-9876-4563-123456789012", + Location: "lOcAtIoNvAlUe", }, }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE/lOcAtIoNs/lOcAtIoNvAlUe/extra", + Error: true, + }, } - for _, v := range testData { t.Logf("[DEBUG] Testing %q", v.Input) @@ -176,7 +201,7 @@ func TestParseLocationIDInsensitively(t *testing.T) { continue } - t.Fatalf("Expect a value but got an error: %s", err) + t.Fatalf("Expect a value but got an error: %+v", err) } if v.Error { t.Fatal("Expect an error but didn't get one") @@ -185,8 +210,10 @@ func TestParseLocationIDInsensitively(t *testing.T) { if actual.SubscriptionId != v.Expected.SubscriptionId { t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) } - if actual.Name != v.Expected.Name { - t.Fatalf("Expected %q but got %q for Name", v.Expected.Name, actual.Name) + + if actual.Location != v.Expected.Location { + t.Fatalf("Expected %q but got %q for Location", v.Expected.Location, actual.Location) } + } } diff --git a/internal/services/signalr/sdk/2020-05-01/signalr/id_privateendpointconnection.go b/internal/services/signalr/sdk/2020-05-01/signalr/id_privateendpointconnection.go index b15c87804edc..1deb956dce58 100644 --- a/internal/services/signalr/sdk/2020-05-01/signalr/id_privateendpointconnection.go +++ b/internal/services/signalr/sdk/2020-05-01/signalr/id_privateendpointconnection.go @@ -7,120 +7,131 @@ import ( "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" ) +var _ resourceids.ResourceId = PrivateEndpointConnectionId{} + +// PrivateEndpointConnectionId is a struct representing the Resource ID for a Private Endpoint Connection type PrivateEndpointConnectionId struct { - SubscriptionId string - ResourceGroup string - SignalRName string - Name string + SubscriptionId string + ResourceGroupName string + ResourceName string + PrivateEndpointConnectionName string } -func NewPrivateEndpointConnectionID(subscriptionId, resourceGroup, signalRName, name string) PrivateEndpointConnectionId { +// NewPrivateEndpointConnectionID returns a new PrivateEndpointConnectionId struct +func NewPrivateEndpointConnectionID(subscriptionId string, resourceGroupName string, resourceName string, privateEndpointConnectionName string) PrivateEndpointConnectionId { return PrivateEndpointConnectionId{ - SubscriptionId: subscriptionId, - ResourceGroup: resourceGroup, - SignalRName: signalRName, - Name: name, - } -} - -func (id PrivateEndpointConnectionId) String() string { - segments := []string{ - fmt.Sprintf("Name %q", id.Name), - fmt.Sprintf("Signal R Name %q", id.SignalRName), - fmt.Sprintf("Resource Group %q", id.ResourceGroup), + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ResourceName: resourceName, + PrivateEndpointConnectionName: privateEndpointConnectionName, } - segmentsStr := strings.Join(segments, " / ") - return fmt.Sprintf("%s: (%s)", "Private Endpoint Connection", segmentsStr) -} - -func (id PrivateEndpointConnectionId) ID() string { - fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.SignalRService/SignalR/%s/privateEndpointConnections/%s" - return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.SignalRName, id.Name) } -// ParsePrivateEndpointConnectionID parses a PrivateEndpointConnection ID into an PrivateEndpointConnectionId struct +// ParsePrivateEndpointConnectionID parses 'input' into a PrivateEndpointConnectionId func ParsePrivateEndpointConnectionID(input string) (*PrivateEndpointConnectionId, error) { - id, err := resourceids.ParseAzureResourceID(input) + parser := resourceids.NewParserFromResourceIdType(PrivateEndpointConnectionId{}) + parsed, err := parser.Parse(input, false) if err != nil { - return nil, err + return nil, fmt.Errorf("parsing %q: %+v", input, err) } - resourceId := PrivateEndpointConnectionId{ - SubscriptionId: id.SubscriptionID, - ResourceGroup: id.ResourceGroup, - } + var ok bool + id := PrivateEndpointConnectionId{} - if resourceId.SubscriptionId == "" { - return nil, fmt.Errorf("ID was missing the 'subscriptions' element") + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) } - if resourceId.ResourceGroup == "" { - return nil, fmt.Errorf("ID was missing the 'resourceGroups' element") + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) } - if resourceId.SignalRName, err = id.PopSegment("SignalR"); err != nil { - return nil, err - } - if resourceId.Name, err = id.PopSegment("privateEndpointConnections"); err != nil { - return nil, err + if id.ResourceName, ok = parsed.Parsed["resourceName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceName' was not found in the resource id %q", input) } - if err := id.ValidateNoEmptySegments(input); err != nil { - return nil, err + if id.PrivateEndpointConnectionName, ok = parsed.Parsed["privateEndpointConnectionName"]; !ok { + return nil, fmt.Errorf("the segment 'privateEndpointConnectionName' was not found in the resource id %q", input) } - return &resourceId, nil + return &id, nil } -// ParsePrivateEndpointConnectionIDInsensitively parses an PrivateEndpointConnection ID into an PrivateEndpointConnectionId struct, insensitively -// This should only be used to parse an ID for rewriting to a consistent casing, -// the ParsePrivateEndpointConnectionID method should be used instead for validation etc. +// ParsePrivateEndpointConnectionIDInsensitively parses 'input' case-insensitively into a PrivateEndpointConnectionId +// note: this method should only be used for API response data and not user input func ParsePrivateEndpointConnectionIDInsensitively(input string) (*PrivateEndpointConnectionId, error) { - id, err := resourceids.ParseAzureResourceID(input) + parser := resourceids.NewParserFromResourceIdType(PrivateEndpointConnectionId{}) + parsed, err := parser.Parse(input, true) if err != nil { - return nil, err + return nil, fmt.Errorf("parsing %q: %+v", input, err) } - resourceId := PrivateEndpointConnectionId{ - SubscriptionId: id.SubscriptionID, - ResourceGroup: id.ResourceGroup, - } + var ok bool + id := PrivateEndpointConnectionId{} - if resourceId.SubscriptionId == "" { - return nil, fmt.Errorf("ID was missing the 'subscriptions' element") + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) } - if resourceId.ResourceGroup == "" { - return nil, fmt.Errorf("ID was missing the 'resourceGroups' element") + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) } - // find the correct casing for the 'SignalR' segment - SignalRKey := "SignalR" - for key := range id.Path { - if strings.EqualFold(key, SignalRKey) { - SignalRKey = key - break - } + if id.ResourceName, ok = parsed.Parsed["resourceName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceName' was not found in the resource id %q", input) } - if resourceId.SignalRName, err = id.PopSegment(SignalRKey); err != nil { - return nil, err + + if id.PrivateEndpointConnectionName, ok = parsed.Parsed["privateEndpointConnectionName"]; !ok { + return nil, fmt.Errorf("the segment 'privateEndpointConnectionName' was not found in the resource id %q", input) } - // find the correct casing for the 'privateEndpointConnections' segment - privateEndpointConnectionsKey := "privateEndpointConnections" - for key := range id.Path { - if strings.EqualFold(key, privateEndpointConnectionsKey) { - privateEndpointConnectionsKey = key - break - } + return &id, nil +} + +// ValidatePrivateEndpointConnectionID checks that 'input' can be parsed as a Private Endpoint Connection ID +func ValidatePrivateEndpointConnectionID(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 resourceId.Name, err = id.PopSegment(privateEndpointConnectionsKey); err != nil { - return nil, err + + if _, err := ParsePrivateEndpointConnectionID(v); err != nil { + errors = append(errors, err) } - if err := id.ValidateNoEmptySegments(input); err != nil { - return nil, err + return +} + +// ID returns the formatted Private Endpoint Connection ID +func (id PrivateEndpointConnectionId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.SignalRService/signalR/%s/privateEndpointConnections/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ResourceName, id.PrivateEndpointConnectionName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Private Endpoint Connection ID +func (id PrivateEndpointConnectionId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("subscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("resourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("providers", "providers", "providers"), + resourceids.ResourceProviderSegment("microsoftSignalRService", "Microsoft.SignalRService", "Microsoft.SignalRService"), + resourceids.StaticSegment("signalR", "signalR", "signalR"), + resourceids.UserSpecifiedSegment("resourceName", "resourceValue"), + resourceids.StaticSegment("privateEndpointConnections", "privateEndpointConnections", "privateEndpointConnections"), + resourceids.UserSpecifiedSegment("privateEndpointConnectionName", "privateEndpointConnectionValue"), } +} - return &resourceId, nil +// String returns a human-readable description of this Private Endpoint Connection ID +func (id PrivateEndpointConnectionId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Resource Name: %q", id.ResourceName), + fmt.Sprintf("Private Endpoint Connection Name: %q", id.PrivateEndpointConnectionName), + } + return fmt.Sprintf("Private Endpoint Connection (%s)", strings.Join(components, "\n")) } diff --git a/internal/services/signalr/sdk/2020-05-01/signalr/id_privateendpointconnection_test.go b/internal/services/signalr/sdk/2020-05-01/signalr/id_privateendpointconnection_test.go index b175dbe1ce58..6827f2428d9f 100644 --- a/internal/services/signalr/sdk/2020-05-01/signalr/id_privateendpointconnection_test.go +++ b/internal/services/signalr/sdk/2020-05-01/signalr/id_privateendpointconnection_test.go @@ -6,13 +6,33 @@ import ( "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" ) -var _ resourceids.Id = PrivateEndpointConnectionId{} +var _ resourceids.ResourceId = PrivateEndpointConnectionId{} -func TestPrivateEndpointConnectionIDFormatter(t *testing.T) { - actual := NewPrivateEndpointConnectionID("{subscriptionId}", "{resourceGroupName}", "{resourceName}", "{privateEndpointConnectionName}").ID() - expected := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.SignalRService/SignalR/{resourceName}/privateEndpointConnections/{privateEndpointConnectionName}" +func TestNewPrivateEndpointConnectionID(t *testing.T) { + id := NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceValue", "privateEndpointConnectionValue") + + 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.ResourceName != "resourceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceName'", id.ResourceName, "resourceValue") + } + + if id.PrivateEndpointConnectionName != "privateEndpointConnectionValue" { + t.Fatalf("Expected %q but got %q for Segment 'PrivateEndpointConnectionName'", id.PrivateEndpointConnectionName, "privateEndpointConnectionValue") + } +} + +func TestFormatPrivateEndpointConnectionID(t *testing.T) { + actual := NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceValue", "privateEndpointConnectionValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/signalR/resourceValue/privateEndpointConnections/privateEndpointConnectionValue" if actual != expected { - t.Fatalf("Expected %q but got %q", expected, actual) + t.Fatalf("Expected the Formatted ID to be %q but got %q", actual, expected) } } @@ -22,79 +42,72 @@ func TestParsePrivateEndpointConnectionID(t *testing.T) { Error bool Expected *PrivateEndpointConnectionId }{ - { - // empty + // Incomplete URI Input: "", Error: true, }, - { - // missing SubscriptionId - Input: "/", + // Incomplete URI + Input: "/subscriptions", Error: true, }, - { - // missing value for SubscriptionId - Input: "/subscriptions/", + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", Error: true, }, - { - // missing ResourceGroup - Input: "/subscriptions/{subscriptionId}/", + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", Error: true, }, - { - // missing value for ResourceGroup - Input: "/subscriptions/{subscriptionId}/resourceGroups/", + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", Error: true, }, - { - // missing SignalRName - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.", + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", Error: true, }, - { - // missing value for SignalRName - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.SignalRService/SignalR/", + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService", Error: true, }, - { - // missing Name - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.SignalRService/SignalR/{resourceName}/", + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/signalR", Error: true, }, - { - // missing value for Name - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.SignalRService/SignalR/{resourceName}/privateEndpointConnections/", + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/signalR/resourceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/signalR/resourceValue/privateEndpointConnections", Error: true, }, - { - // valid - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.SignalRService/SignalR/{resourceName}/privateEndpointConnections/{privateEndpointConnectionName}", + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/signalR/resourceValue/privateEndpointConnections/privateEndpointConnectionValue", Expected: &PrivateEndpointConnectionId{ - SubscriptionId: "{subscriptionId}", - ResourceGroup: "{resourceGroupName}", - SignalRName: "{resourceName}", - Name: "{privateEndpointConnectionName}", + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ResourceName: "resourceValue", + PrivateEndpointConnectionName: "privateEndpointConnectionValue", }, }, - { - // upper-cased - Input: "/SUBSCRIPTIONS/{SUBSCRIPTIONID}/RESOURCEGROUPS/{RESOURCEGROUPNAME}/PROVIDERS/MICROSOFT.SIGNALRSERVICE/SIGNALR/{RESOURCENAME}/PRIVATEENDPOINTCONNECTIONS/{PRIVATEENDPOINTCONNECTIONNAME}", + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/signalR/resourceValue/privateEndpointConnections/privateEndpointConnectionValue/extra", Error: true, }, } - for _, v := range testData { t.Logf("[DEBUG] Testing %q", v.Input) @@ -104,7 +117,7 @@ func TestParsePrivateEndpointConnectionID(t *testing.T) { continue } - t.Fatalf("Expect a value but got an error: %s", err) + t.Fatalf("Expect a value but got an error: %+v", err) } if v.Error { t.Fatal("Expect an error but didn't get one") @@ -113,15 +126,19 @@ func TestParsePrivateEndpointConnectionID(t *testing.T) { if actual.SubscriptionId != v.Expected.SubscriptionId { t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) } - if actual.ResourceGroup != v.Expected.ResourceGroup { - t.Fatalf("Expected %q but got %q for ResourceGroup", v.Expected.ResourceGroup, actual.ResourceGroup) + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) } - if actual.SignalRName != v.Expected.SignalRName { - t.Fatalf("Expected %q but got %q for SignalRName", v.Expected.SignalRName, actual.SignalRName) + + if actual.ResourceName != v.Expected.ResourceName { + t.Fatalf("Expected %q but got %q for ResourceName", v.Expected.ResourceName, actual.ResourceName) } - if actual.Name != v.Expected.Name { - t.Fatalf("Expected %q but got %q for Name", v.Expected.Name, actual.Name) + + if actual.PrivateEndpointConnectionName != v.Expected.PrivateEndpointConnectionName { + t.Fatalf("Expected %q but got %q for PrivateEndpointConnectionName", v.Expected.PrivateEndpointConnectionName, actual.PrivateEndpointConnectionName) } + } } @@ -131,106 +148,132 @@ func TestParsePrivateEndpointConnectionIDInsensitively(t *testing.T) { Error bool Expected *PrivateEndpointConnectionId }{ - { - // empty + // Incomplete URI Input: "", Error: true, }, - { - // missing SubscriptionId - Input: "/", + // Incomplete URI + Input: "/subscriptions", Error: true, }, - { - // missing value for SubscriptionId - Input: "/subscriptions/", + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", Error: true, }, - { - // missing ResourceGroup - Input: "/subscriptions/{subscriptionId}/", + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", Error: true, }, - { - // missing value for ResourceGroup - Input: "/subscriptions/{subscriptionId}/resourceGroups/", + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", Error: true, }, - { - // missing SignalRName - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.", + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", Error: true, }, - { - // missing value for SignalRName - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.SignalRService/SignalR/", + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", Error: true, }, - { - // missing Name - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.SignalRService/SignalR/{resourceName}/", + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", Error: true, }, - { - // missing value for Name - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.SignalRService/SignalR/{resourceName}/privateEndpointConnections/", + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", Error: true, }, - { - // valid - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.SignalRService/SignalR/{resourceName}/privateEndpointConnections/{privateEndpointConnectionName}", - Expected: &PrivateEndpointConnectionId{ - SubscriptionId: "{subscriptionId}", - ResourceGroup: "{resourceGroupName}", - SignalRName: "{resourceName}", - Name: "{privateEndpointConnectionName}", - }, + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, }, - { - // lower-cased segment names - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.signalrService/SignalR/{resourceName}/privateendpointconnections/{privateEndpointConnectionName}", - Expected: &PrivateEndpointConnectionId{ - SubscriptionId: "{subscriptionId}", - ResourceGroup: "{resourceGroupName}", - SignalRName: "{resourceName}", - Name: "{privateEndpointConnectionName}", - }, + // 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.SignalRService", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE", + Error: true, }, - { - // upper-cased segment names - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.SIGNALRService/SignalR/{resourceName}/PRIVATEENDPOINTCONNECTIONS/{privateEndpointConnectionName}", + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/signalR", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE/sIgNaLr", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/signalR/resourceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE/sIgNaLr/rEsOuRcEvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/signalR/resourceValue/privateEndpointConnections", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE/sIgNaLr/rEsOuRcEvAlUe/pRiVaTeEnDpOiNtCoNnEcTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/signalR/resourceValue/privateEndpointConnections/privateEndpointConnectionValue", Expected: &PrivateEndpointConnectionId{ - SubscriptionId: "{subscriptionId}", - ResourceGroup: "{resourceGroupName}", - SignalRName: "{resourceName}", - Name: "{privateEndpointConnectionName}", + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ResourceName: "resourceValue", + PrivateEndpointConnectionName: "privateEndpointConnectionValue", }, }, - { - // mixed-cased segment names - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.SiGnAlRService/SignalR/{resourceName}/PrIvAtEeNdPoInTcOnNeCtIoNs/{privateEndpointConnectionName}", + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/signalR/resourceValue/privateEndpointConnections/privateEndpointConnectionValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE/sIgNaLr/rEsOuRcEvAlUe/pRiVaTeEnDpOiNtCoNnEcTiOnS/pRiVaTeEnDpOiNtCoNnEcTiOnVaLuE", Expected: &PrivateEndpointConnectionId{ - SubscriptionId: "{subscriptionId}", - ResourceGroup: "{resourceGroupName}", - SignalRName: "{resourceName}", - Name: "{privateEndpointConnectionName}", + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ResourceName: "rEsOuRcEvAlUe", + PrivateEndpointConnectionName: "pRiVaTeEnDpOiNtCoNnEcTiOnVaLuE", }, }, + { + // 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.sIgNaLrSeRvIcE/sIgNaLr/rEsOuRcEvAlUe/pRiVaTeEnDpOiNtCoNnEcTiOnS/pRiVaTeEnDpOiNtCoNnEcTiOnVaLuE/extra", + Error: true, + }, } - for _, v := range testData { t.Logf("[DEBUG] Testing %q", v.Input) @@ -240,7 +283,7 @@ func TestParsePrivateEndpointConnectionIDInsensitively(t *testing.T) { continue } - t.Fatalf("Expect a value but got an error: %s", err) + t.Fatalf("Expect a value but got an error: %+v", err) } if v.Error { t.Fatal("Expect an error but didn't get one") @@ -249,14 +292,18 @@ func TestParsePrivateEndpointConnectionIDInsensitively(t *testing.T) { if actual.SubscriptionId != v.Expected.SubscriptionId { t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) } - if actual.ResourceGroup != v.Expected.ResourceGroup { - t.Fatalf("Expected %q but got %q for ResourceGroup", v.Expected.ResourceGroup, actual.ResourceGroup) + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) } - if actual.SignalRName != v.Expected.SignalRName { - t.Fatalf("Expected %q but got %q for SignalRName", v.Expected.SignalRName, actual.SignalRName) + + if actual.ResourceName != v.Expected.ResourceName { + t.Fatalf("Expected %q but got %q for ResourceName", v.Expected.ResourceName, actual.ResourceName) } - if actual.Name != v.Expected.Name { - t.Fatalf("Expected %q but got %q for Name", v.Expected.Name, actual.Name) + + if actual.PrivateEndpointConnectionName != v.Expected.PrivateEndpointConnectionName { + t.Fatalf("Expected %q but got %q for PrivateEndpointConnectionName", v.Expected.PrivateEndpointConnectionName, actual.PrivateEndpointConnectionName) } + } } diff --git a/internal/services/signalr/sdk/2020-05-01/signalr/id_resourcegroup.go b/internal/services/signalr/sdk/2020-05-01/signalr/id_resourcegroup.go index 7bcbabb104de..389d49132321 100644 --- a/internal/services/signalr/sdk/2020-05-01/signalr/id_resourcegroup.go +++ b/internal/services/signalr/sdk/2020-05-01/signalr/id_resourcegroup.go @@ -7,83 +7,103 @@ import ( "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" ) +var _ resourceids.ResourceId = ResourceGroupId{} + +// ResourceGroupId is a struct representing the Resource ID for a Resource Group type ResourceGroupId struct { - SubscriptionId string - ResourceGroup string + SubscriptionId string + ResourceGroupName string } -func NewResourceGroupID(subscriptionId, resourceGroup string) ResourceGroupId { +// NewResourceGroupID returns a new ResourceGroupId struct +func NewResourceGroupID(subscriptionId string, resourceGroupName string) ResourceGroupId { return ResourceGroupId{ - SubscriptionId: subscriptionId, - ResourceGroup: resourceGroup, + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, } } -func (id ResourceGroupId) String() string { - segments := []string{ - fmt.Sprintf("Resource Group %q", id.ResourceGroup), - } - segmentsStr := strings.Join(segments, " / ") - return fmt.Sprintf("%s: (%s)", "Resource Group", segmentsStr) -} - -func (id ResourceGroupId) ID() string { - fmtString := "/subscriptions/%s/resourceGroups/%s" - return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup) -} - -// ParseResourceGroupID parses a ResourceGroup ID into an ResourceGroupId struct +// ParseResourceGroupID parses 'input' into a ResourceGroupId func ParseResourceGroupID(input string) (*ResourceGroupId, error) { - id, err := resourceids.ParseAzureResourceID(input) + parser := resourceids.NewParserFromResourceIdType(ResourceGroupId{}) + parsed, err := parser.Parse(input, false) if err != nil { - return nil, err - } - - resourceId := ResourceGroupId{ - SubscriptionId: id.SubscriptionID, - ResourceGroup: id.ResourceGroup, + return nil, fmt.Errorf("parsing %q: %+v", input, err) } - if resourceId.SubscriptionId == "" { - return nil, fmt.Errorf("ID was missing the 'subscriptions' element") - } + var ok bool + id := ResourceGroupId{} - if resourceId.ResourceGroup == "" { - return nil, fmt.Errorf("ID was missing the 'resourceGroups' element") + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) } - if err := id.ValidateNoEmptySegments(input); err != nil { - return nil, err + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) } - return &resourceId, nil + return &id, nil } -// ParseResourceGroupIDInsensitively parses an ResourceGroup ID into an ResourceGroupId struct, insensitively -// This should only be used to parse an ID for rewriting to a consistent casing, -// the ParseResourceGroupID method should be used instead for validation etc. +// ParseResourceGroupIDInsensitively parses 'input' case-insensitively into a ResourceGroupId +// note: this method should only be used for API response data and not user input func ParseResourceGroupIDInsensitively(input string) (*ResourceGroupId, error) { - id, err := resourceids.ParseAzureResourceID(input) + parser := resourceids.NewParserFromResourceIdType(ResourceGroupId{}) + parsed, err := parser.Parse(input, true) if err != nil { - return nil, err + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ResourceGroupId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) } - resourceId := ResourceGroupId{ - SubscriptionId: id.SubscriptionID, - ResourceGroup: id.ResourceGroup, + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) } - if resourceId.SubscriptionId == "" { - return nil, fmt.Errorf("ID was missing the 'subscriptions' element") + return &id, nil +} + +// ValidateResourceGroupID checks that 'input' can be parsed as a Resource Group ID +func ValidateResourceGroupID(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 resourceId.ResourceGroup == "" { - return nil, fmt.Errorf("ID was missing the 'resourceGroups' element") + if _, err := ParseResourceGroupID(v); err != nil { + errors = append(errors, err) } - if err := id.ValidateNoEmptySegments(input); err != nil { - return nil, err + return +} + +// ID returns the formatted Resource Group ID +func (id ResourceGroupId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Resource Group ID +func (id ResourceGroupId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("subscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("resourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), } +} - return &resourceId, nil +// String returns a human-readable description of this Resource Group ID +func (id ResourceGroupId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + } + return fmt.Sprintf("Resource Group (%s)", strings.Join(components, "\n")) } diff --git a/internal/services/signalr/sdk/2020-05-01/signalr/id_resourcegroup_test.go b/internal/services/signalr/sdk/2020-05-01/signalr/id_resourcegroup_test.go index 3de2f560ab58..4d7347a3e4ac 100644 --- a/internal/services/signalr/sdk/2020-05-01/signalr/id_resourcegroup_test.go +++ b/internal/services/signalr/sdk/2020-05-01/signalr/id_resourcegroup_test.go @@ -6,13 +6,25 @@ import ( "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" ) -var _ resourceids.Id = ResourceGroupId{} +var _ resourceids.ResourceId = ResourceGroupId{} -func TestResourceGroupIDFormatter(t *testing.T) { - actual := NewResourceGroupID("{subscriptionId}", "{resourceGroupName}").ID() - expected := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}" +func TestNewResourceGroupID(t *testing.T) { + id := NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + + 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") + } +} + +func TestFormatResourceGroupID(t *testing.T) { + actual := NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group" if actual != expected { - t.Fatalf("Expected %q but got %q", expected, actual) + t.Fatalf("Expected the Formatted ID to be %q but got %q", actual, expected) } } @@ -22,53 +34,40 @@ func TestParseResourceGroupID(t *testing.T) { Error bool Expected *ResourceGroupId }{ - { - // empty + // Incomplete URI Input: "", Error: true, }, - - { - // missing SubscriptionId - Input: "/", - Error: true, - }, - { - // missing value for SubscriptionId - Input: "/subscriptions/", + // Incomplete URI + Input: "/subscriptions", Error: true, }, - { - // missing ResourceGroup - Input: "/subscriptions/{subscriptionId}/", + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", Error: true, }, - { - // missing value for ResourceGroup - Input: "/subscriptions/{subscriptionId}/resourceGroups/", + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", Error: true, }, - { - // valid - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}", + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", Expected: &ResourceGroupId{ - SubscriptionId: "{subscriptionId}", - ResourceGroup: "{resourceGroupName}", + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", }, }, - { - // upper-cased - Input: "/SUBSCRIPTIONS/{SUBSCRIPTIONID}/RESOURCEGROUPS/{RESOURCEGROUPNAME}", + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/extra", Error: true, }, } - for _, v := range testData { t.Logf("[DEBUG] Testing %q", v.Input) @@ -78,7 +77,7 @@ func TestParseResourceGroupID(t *testing.T) { continue } - t.Fatalf("Expect a value but got an error: %s", err) + t.Fatalf("Expect a value but got an error: %+v", err) } if v.Error { t.Fatal("Expect an error but didn't get one") @@ -87,9 +86,11 @@ func TestParseResourceGroupID(t *testing.T) { if actual.SubscriptionId != v.Expected.SubscriptionId { t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) } - if actual.ResourceGroup != v.Expected.ResourceGroup { - t.Fatalf("Expected %q but got %q for ResourceGroup", v.Expected.ResourceGroup, actual.ResourceGroup) + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) } + } } @@ -99,74 +100,68 @@ func TestParseResourceGroupIDInsensitively(t *testing.T) { Error bool Expected *ResourceGroupId }{ - { - // empty + // Incomplete URI Input: "", Error: true, }, - { - // missing SubscriptionId - Input: "/", + // Incomplete URI + Input: "/subscriptions", Error: true, }, - { - // missing value for SubscriptionId - Input: "/subscriptions/", + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", Error: true, }, - { - // missing ResourceGroup - Input: "/subscriptions/{subscriptionId}/", + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", Error: true, }, - { - // missing value for ResourceGroup - Input: "/subscriptions/{subscriptionId}/resourceGroups/", + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", Error: true, }, - { - // valid - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}", - Expected: &ResourceGroupId{ - SubscriptionId: "{subscriptionId}", - ResourceGroup: "{resourceGroupName}", - }, + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, }, - { - // lower-cased segment names - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}", - Expected: &ResourceGroupId{ - SubscriptionId: "{subscriptionId}", - ResourceGroup: "{resourceGroupName}", - }, + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, }, - { - // upper-cased segment names - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}", + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", Expected: &ResourceGroupId{ - SubscriptionId: "{subscriptionId}", - ResourceGroup: "{resourceGroupName}", + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", }, }, - { - // mixed-cased segment names - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}", + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", Expected: &ResourceGroupId{ - SubscriptionId: "{subscriptionId}", - ResourceGroup: "{resourceGroupName}", + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", }, }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/extra", + Error: true, + }, } - for _, v := range testData { t.Logf("[DEBUG] Testing %q", v.Input) @@ -176,7 +171,7 @@ func TestParseResourceGroupIDInsensitively(t *testing.T) { continue } - t.Fatalf("Expect a value but got an error: %s", err) + t.Fatalf("Expect a value but got an error: %+v", err) } if v.Error { t.Fatal("Expect an error but didn't get one") @@ -185,8 +180,10 @@ func TestParseResourceGroupIDInsensitively(t *testing.T) { if actual.SubscriptionId != v.Expected.SubscriptionId { t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) } - if actual.ResourceGroup != v.Expected.ResourceGroup { - t.Fatalf("Expected %q but got %q for ResourceGroup", v.Expected.ResourceGroup, actual.ResourceGroup) + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) } + } } diff --git a/internal/services/signalr/sdk/2020-05-01/signalr/id_signalr.go b/internal/services/signalr/sdk/2020-05-01/signalr/id_signalr.go index 9f0a3e4a8453..007ec6a5a3be 100644 --- a/internal/services/signalr/sdk/2020-05-01/signalr/id_signalr.go +++ b/internal/services/signalr/sdk/2020-05-01/signalr/id_signalr.go @@ -7,102 +7,118 @@ import ( "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" ) +var _ resourceids.ResourceId = SignalRId{} + +// SignalRId is a struct representing the Resource ID for a Signal R type SignalRId struct { - SubscriptionId string - ResourceGroup string - SignalRName string + SubscriptionId string + ResourceGroupName string + ResourceName string } -func NewSignalRID(subscriptionId, resourceGroup, signalRName string) SignalRId { +// NewSignalRID returns a new SignalRId struct +func NewSignalRID(subscriptionId string, resourceGroupName string, resourceName string) SignalRId { return SignalRId{ - SubscriptionId: subscriptionId, - ResourceGroup: resourceGroup, - SignalRName: signalRName, - } -} - -func (id SignalRId) String() string { - segments := []string{ - fmt.Sprintf("Signal R Name %q", id.SignalRName), - fmt.Sprintf("Resource Group %q", id.ResourceGroup), + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ResourceName: resourceName, } - segmentsStr := strings.Join(segments, " / ") - return fmt.Sprintf("%s: (%s)", "Signal R", segmentsStr) -} - -func (id SignalRId) ID() string { - fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.SignalRService/SignalR/%s" - return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.SignalRName) } -// ParseSignalRID parses a SignalR ID into an SignalRId struct +// ParseSignalRID parses 'input' into a SignalRId func ParseSignalRID(input string) (*SignalRId, error) { - id, err := resourceids.ParseAzureResourceID(input) + parser := resourceids.NewParserFromResourceIdType(SignalRId{}) + parsed, err := parser.Parse(input, false) if err != nil { - return nil, err - } - - resourceId := SignalRId{ - SubscriptionId: id.SubscriptionID, - ResourceGroup: id.ResourceGroup, + return nil, fmt.Errorf("parsing %q: %+v", input, err) } - if resourceId.SubscriptionId == "" { - return nil, fmt.Errorf("ID was missing the 'subscriptions' element") - } + var ok bool + id := SignalRId{} - if resourceId.ResourceGroup == "" { - return nil, fmt.Errorf("ID was missing the 'resourceGroups' element") + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) } - if resourceId.SignalRName, err = id.PopSegment("SignalR"); err != nil { - return nil, err + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) } - if err := id.ValidateNoEmptySegments(input); err != nil { - return nil, err + if id.ResourceName, ok = parsed.Parsed["resourceName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceName' was not found in the resource id %q", input) } - return &resourceId, nil + return &id, nil } -// ParseSignalRIDInsensitively parses an SignalR ID into an SignalRId struct, insensitively -// This should only be used to parse an ID for rewriting to a consistent casing, -// the ParseSignalRID method should be used instead for validation etc. +// ParseSignalRIDInsensitively parses 'input' case-insensitively into a SignalRId +// note: this method should only be used for API response data and not user input func ParseSignalRIDInsensitively(input string) (*SignalRId, error) { - id, err := resourceids.ParseAzureResourceID(input) + parser := resourceids.NewParserFromResourceIdType(SignalRId{}) + parsed, err := parser.Parse(input, true) if err != nil { - return nil, err + return nil, fmt.Errorf("parsing %q: %+v", input, err) } - resourceId := SignalRId{ - SubscriptionId: id.SubscriptionID, - ResourceGroup: id.ResourceGroup, + var ok bool + id := SignalRId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) } - if resourceId.SubscriptionId == "" { - return nil, fmt.Errorf("ID was missing the 'subscriptions' element") + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) } - if resourceId.ResourceGroup == "" { - return nil, fmt.Errorf("ID was missing the 'resourceGroups' element") + if id.ResourceName, ok = parsed.Parsed["resourceName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceName' was not found in the resource id %q", input) } - // find the correct casing for the 'SignalR' segment - SignalRKey := "SignalR" - for key := range id.Path { - if strings.EqualFold(key, SignalRKey) { - SignalRKey = key - break - } + return &id, nil +} + +// ValidateSignalRID checks that 'input' can be parsed as a Signal R ID +func ValidateSignalRID(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 resourceId.SignalRName, err = id.PopSegment(SignalRKey); err != nil { - return nil, err + + if _, err := ParseSignalRID(v); err != nil { + errors = append(errors, err) } - if err := id.ValidateNoEmptySegments(input); err != nil { - return nil, err + return +} + +// ID returns the formatted Signal R ID +func (id SignalRId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.SignalRService/signalR/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ResourceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Signal R ID +func (id SignalRId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("subscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("resourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("providers", "providers", "providers"), + resourceids.ResourceProviderSegment("microsoftSignalRService", "Microsoft.SignalRService", "Microsoft.SignalRService"), + resourceids.StaticSegment("signalR", "signalR", "signalR"), + resourceids.UserSpecifiedSegment("resourceName", "resourceValue"), } +} - return &resourceId, nil +// String returns a human-readable description of this Signal R ID +func (id SignalRId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Resource Name: %q", id.ResourceName), + } + return fmt.Sprintf("Signal R (%s)", strings.Join(components, "\n")) } diff --git a/internal/services/signalr/sdk/2020-05-01/signalr/id_signalr_test.go b/internal/services/signalr/sdk/2020-05-01/signalr/id_signalr_test.go index cb195b1b3bd8..30d8f7da8e11 100644 --- a/internal/services/signalr/sdk/2020-05-01/signalr/id_signalr_test.go +++ b/internal/services/signalr/sdk/2020-05-01/signalr/id_signalr_test.go @@ -6,13 +6,29 @@ import ( "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" ) -var _ resourceids.Id = SignalRId{} +var _ resourceids.ResourceId = SignalRId{} -func TestSignalRIDFormatter(t *testing.T) { - actual := NewSignalRID("{subscriptionId}", "{resourceGroupName}", "{resourceName}").ID() - expected := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.SignalRService/SignalR/{resourceName}" +func TestNewSignalRID(t *testing.T) { + id := NewSignalRID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceValue") + + 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.ResourceName != "resourceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceName'", id.ResourceName, "resourceValue") + } +} + +func TestFormatSignalRID(t *testing.T) { + actual := NewSignalRID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/signalR/resourceValue" if actual != expected { - t.Fatalf("Expected %q but got %q", expected, actual) + t.Fatalf("Expected the Formatted ID to be %q but got %q", actual, expected) } } @@ -22,66 +38,61 @@ func TestParseSignalRID(t *testing.T) { Error bool Expected *SignalRId }{ - { - // empty + // Incomplete URI Input: "", Error: true, }, - { - // missing SubscriptionId - Input: "/", + // Incomplete URI + Input: "/subscriptions", Error: true, }, - { - // missing value for SubscriptionId - Input: "/subscriptions/", + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", Error: true, }, - { - // missing ResourceGroup - Input: "/subscriptions/{subscriptionId}/", + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", Error: true, }, - { - // missing value for ResourceGroup - Input: "/subscriptions/{subscriptionId}/resourceGroups/", + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", Error: true, }, - { - // missing SignalRName - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.", + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", Error: true, }, - { - // missing value for SignalRName - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.SignalRService/SignalR/", + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService", Error: true, }, - { - // valid - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.SignalRService/SignalR/{resourceName}", + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/signalR", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/signalR/resourceValue", Expected: &SignalRId{ - SubscriptionId: "{subscriptionId}", - ResourceGroup: "{resourceGroupName}", - SignalRName: "{resourceName}", + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ResourceName: "resourceValue", }, }, - { - // upper-cased - Input: "/SUBSCRIPTIONS/{SUBSCRIPTIONID}/RESOURCEGROUPS/{RESOURCEGROUPNAME}/PROVIDERS/MICROSOFT.SIGNALRSERVICE/SIGNALR/{RESOURCENAME}", + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/signalR/resourceValue/extra", Error: true, }, } - for _, v := range testData { t.Logf("[DEBUG] Testing %q", v.Input) @@ -91,7 +102,7 @@ func TestParseSignalRID(t *testing.T) { continue } - t.Fatalf("Expect a value but got an error: %s", err) + t.Fatalf("Expect a value but got an error: %+v", err) } if v.Error { t.Fatal("Expect an error but didn't get one") @@ -100,12 +111,15 @@ func TestParseSignalRID(t *testing.T) { if actual.SubscriptionId != v.Expected.SubscriptionId { t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) } - if actual.ResourceGroup != v.Expected.ResourceGroup { - t.Fatalf("Expected %q but got %q for ResourceGroup", v.Expected.ResourceGroup, actual.ResourceGroup) + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) } - if actual.SignalRName != v.Expected.SignalRName { - t.Fatalf("Expected %q but got %q for SignalRName", v.Expected.SignalRName, actual.SignalRName) + + if actual.ResourceName != v.Expected.ResourceName { + t.Fatalf("Expected %q but got %q for ResourceName", v.Expected.ResourceName, actual.ResourceName) } + } } @@ -115,90 +129,110 @@ func TestParseSignalRIDInsensitively(t *testing.T) { Error bool Expected *SignalRId }{ - { - // empty + // Incomplete URI Input: "", Error: true, }, - { - // missing SubscriptionId - Input: "/", + // Incomplete URI + Input: "/subscriptions", Error: true, }, - { - // missing value for SubscriptionId - Input: "/subscriptions/", + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", Error: true, }, - { - // missing ResourceGroup - Input: "/subscriptions/{subscriptionId}/", + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", Error: true, }, - { - // missing value for ResourceGroup - Input: "/subscriptions/{subscriptionId}/resourceGroups/", + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", Error: true, }, - { - // missing SignalRName - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.", + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", Error: true, }, - { - // missing value for SignalRName - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.SignalRService/SignalR/", + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", Error: true, }, - { - // valid - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.SignalRService/SignalR/{resourceName}", - Expected: &SignalRId{ - SubscriptionId: "{subscriptionId}", - ResourceGroup: "{resourceGroupName}", - SignalRName: "{resourceName}", - }, + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, }, - { - // lower-cased segment names - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.signalrService/SignalR/{resourceName}", - Expected: &SignalRId{ - SubscriptionId: "{subscriptionId}", - ResourceGroup: "{resourceGroupName}", - SignalRName: "{resourceName}", - }, + // 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.SignalRService", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE", + Error: true, }, - { - // upper-cased segment names - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.SIGNALRService/SignalR/{resourceName}", + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/signalR", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE/sIgNaLr", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/signalR/resourceValue", Expected: &SignalRId{ - SubscriptionId: "{subscriptionId}", - ResourceGroup: "{resourceGroupName}", - SignalRName: "{resourceName}", + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ResourceName: "resourceValue", }, }, - { - // mixed-cased segment names - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.SiGnAlRService/SignalR/{resourceName}", + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/signalR/resourceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE/sIgNaLr/rEsOuRcEvAlUe", Expected: &SignalRId{ - SubscriptionId: "{subscriptionId}", - ResourceGroup: "{resourceGroupName}", - SignalRName: "{resourceName}", + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ResourceName: "rEsOuRcEvAlUe", }, }, + { + // 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.sIgNaLrSeRvIcE/sIgNaLr/rEsOuRcEvAlUe/extra", + Error: true, + }, } - for _, v := range testData { t.Logf("[DEBUG] Testing %q", v.Input) @@ -208,7 +242,7 @@ func TestParseSignalRIDInsensitively(t *testing.T) { continue } - t.Fatalf("Expect a value but got an error: %s", err) + t.Fatalf("Expect a value but got an error: %+v", err) } if v.Error { t.Fatal("Expect an error but didn't get one") @@ -217,11 +251,14 @@ func TestParseSignalRIDInsensitively(t *testing.T) { if actual.SubscriptionId != v.Expected.SubscriptionId { t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) } - if actual.ResourceGroup != v.Expected.ResourceGroup { - t.Fatalf("Expected %q but got %q for ResourceGroup", v.Expected.ResourceGroup, actual.ResourceGroup) + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) } - if actual.SignalRName != v.Expected.SignalRName { - t.Fatalf("Expected %q but got %q for SignalRName", v.Expected.SignalRName, actual.SignalRName) + + if actual.ResourceName != v.Expected.ResourceName { + t.Fatalf("Expected %q but got %q for ResourceName", v.Expected.ResourceName, actual.ResourceName) } + } } diff --git a/internal/services/signalr/sdk/2020-05-01/signalr/id_subscription.go b/internal/services/signalr/sdk/2020-05-01/signalr/id_subscription.go index 68c562283521..6b09c60b3698 100644 --- a/internal/services/signalr/sdk/2020-05-01/signalr/id_subscription.go +++ b/internal/services/signalr/sdk/2020-05-01/signalr/id_subscription.go @@ -7,69 +7,90 @@ import ( "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" ) +var _ resourceids.ResourceId = SubscriptionId{} + +// SubscriptionId is a struct representing the Resource ID for a Subscription type SubscriptionId struct { SubscriptionId string } +// NewSubscriptionID returns a new SubscriptionId struct func NewSubscriptionID(subscriptionId string) SubscriptionId { return SubscriptionId{ SubscriptionId: subscriptionId, } } -func (id SubscriptionId) String() string { - segments := []string{} - segmentsStr := strings.Join(segments, " / ") - return fmt.Sprintf("%s: (%s)", "Subscription", segmentsStr) -} - -func (id SubscriptionId) ID() string { - fmtString := "/subscriptions/%s" - return fmt.Sprintf(fmtString, id.SubscriptionId) -} - -// ParseSubscriptionID parses a Subscription ID into an SubscriptionId struct +// ParseSubscriptionID parses 'input' into a SubscriptionId func ParseSubscriptionID(input string) (*SubscriptionId, error) { - id, err := resourceids.ParseAzureResourceID(input) + parser := resourceids.NewParserFromResourceIdType(SubscriptionId{}) + parsed, err := parser.Parse(input, false) if err != nil { - return nil, err + return nil, fmt.Errorf("parsing %q: %+v", input, err) } - resourceId := SubscriptionId{ - SubscriptionId: id.SubscriptionID, - } + var ok bool + id := SubscriptionId{} - if resourceId.SubscriptionId == "" { - return nil, fmt.Errorf("ID was missing the 'subscriptions' element") + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) } - if err := id.ValidateNoEmptySegments(input); err != nil { - return nil, err - } - - return &resourceId, nil + return &id, nil } -// ParseSubscriptionIDInsensitively parses an Subscription ID into an SubscriptionId struct, insensitively -// This should only be used to parse an ID for rewriting to a consistent casing, -// the ParseSubscriptionID method should be used instead for validation etc. +// ParseSubscriptionIDInsensitively parses 'input' case-insensitively into a SubscriptionId +// note: this method should only be used for API response data and not user input func ParseSubscriptionIDInsensitively(input string) (*SubscriptionId, error) { - id, err := resourceids.ParseAzureResourceID(input) + parser := resourceids.NewParserFromResourceIdType(SubscriptionId{}) + parsed, err := parser.Parse(input, true) if err != nil { - return nil, err + return nil, fmt.Errorf("parsing %q: %+v", input, err) } - resourceId := SubscriptionId{ - SubscriptionId: id.SubscriptionID, + var ok bool + id := SubscriptionId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) } - if resourceId.SubscriptionId == "" { - return nil, fmt.Errorf("ID was missing the 'subscriptions' element") + return &id, nil +} + +// ValidateSubscriptionID checks that 'input' can be parsed as a Subscription ID +func ValidateSubscriptionID(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 := id.ValidateNoEmptySegments(input); err != nil { - return nil, err + if _, err := ParseSubscriptionID(v); err != nil { + errors = append(errors, err) } - return &resourceId, nil + return +} + +// ID returns the formatted Subscription ID +func (id SubscriptionId) ID() string { + fmtString := "/subscriptions/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Subscription ID +func (id SubscriptionId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("subscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + } +} + +// String returns a human-readable description of this Subscription ID +func (id SubscriptionId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + } + return fmt.Sprintf("Subscription (%s)", strings.Join(components, "\n")) } diff --git a/internal/services/signalr/sdk/2020-05-01/signalr/id_subscription_test.go b/internal/services/signalr/sdk/2020-05-01/signalr/id_subscription_test.go index cc0160d19ffc..134fd1ddb41c 100644 --- a/internal/services/signalr/sdk/2020-05-01/signalr/id_subscription_test.go +++ b/internal/services/signalr/sdk/2020-05-01/signalr/id_subscription_test.go @@ -6,13 +6,21 @@ import ( "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" ) -var _ resourceids.Id = SubscriptionId{} +var _ resourceids.ResourceId = SubscriptionId{} -func TestSubscriptionIDFormatter(t *testing.T) { - actual := NewSubscriptionID("{subscriptionId}").ID() - expected := "/subscriptions/{subscriptionId}" +func TestNewSubscriptionID(t *testing.T) { + id := NewSubscriptionID("12345678-1234-9876-4563-123456789012") + + 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") + } +} + +func TestFormatSubscriptionID(t *testing.T) { + actual := NewSubscriptionID("12345678-1234-9876-4563-123456789012").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012" if actual != expected { - t.Fatalf("Expected %q but got %q", expected, actual) + t.Fatalf("Expected the Formatted ID to be %q but got %q", actual, expected) } } @@ -22,40 +30,29 @@ func TestParseSubscriptionID(t *testing.T) { Error bool Expected *SubscriptionId }{ - { - // empty + // Incomplete URI Input: "", Error: true, }, - { - // missing SubscriptionId - Input: "/", + // Incomplete URI + Input: "/subscriptions", Error: true, }, - { - // missing value for SubscriptionId - Input: "/subscriptions/", - Error: true, - }, - - { - // valid - Input: "/subscriptions/{subscriptionId}", + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", Expected: &SubscriptionId{ - SubscriptionId: "{subscriptionId}", + SubscriptionId: "12345678-1234-9876-4563-123456789012", }, }, - { - // upper-cased - Input: "/SUBSCRIPTIONS/{SUBSCRIPTIONID}", + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/extra", Error: true, }, } - for _, v := range testData { t.Logf("[DEBUG] Testing %q", v.Input) @@ -65,7 +62,7 @@ func TestParseSubscriptionID(t *testing.T) { continue } - t.Fatalf("Expect a value but got an error: %s", err) + t.Fatalf("Expect a value but got an error: %+v", err) } if v.Error { t.Fatal("Expect an error but didn't get one") @@ -74,6 +71,7 @@ func TestParseSubscriptionID(t *testing.T) { if actual.SubscriptionId != v.Expected.SubscriptionId { t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) } + } } @@ -83,58 +81,46 @@ func TestParseSubscriptionIDInsensitively(t *testing.T) { Error bool Expected *SubscriptionId }{ - { - // empty + // Incomplete URI Input: "", Error: true, }, - { - // missing SubscriptionId - Input: "/", + // Incomplete URI + Input: "/subscriptions", Error: true, }, - { - // missing value for SubscriptionId - Input: "/subscriptions/", + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", Error: true, }, - { - // valid - Input: "/subscriptions/{subscriptionId}", + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", Expected: &SubscriptionId{ - SubscriptionId: "{subscriptionId}", + SubscriptionId: "12345678-1234-9876-4563-123456789012", }, }, - { - // lower-cased segment names - Input: "/subscriptions/{subscriptionId}", - Expected: &SubscriptionId{ - SubscriptionId: "{subscriptionId}", - }, + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/extra", + Error: true, }, - { - // upper-cased segment names - Input: "/subscriptions/{subscriptionId}", + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", Expected: &SubscriptionId{ - SubscriptionId: "{subscriptionId}", + SubscriptionId: "12345678-1234-9876-4563-123456789012", }, }, - { - // mixed-cased segment names - Input: "/subscriptions/{subscriptionId}", - Expected: &SubscriptionId{ - SubscriptionId: "{subscriptionId}", - }, + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/extra", + Error: true, }, } - for _, v := range testData { t.Logf("[DEBUG] Testing %q", v.Input) @@ -144,7 +130,7 @@ func TestParseSubscriptionIDInsensitively(t *testing.T) { continue } - t.Fatalf("Expect a value but got an error: %s", err) + t.Fatalf("Expect a value but got an error: %+v", err) } if v.Error { t.Fatal("Expect an error but didn't get one") @@ -153,5 +139,6 @@ func TestParseSubscriptionIDInsensitively(t *testing.T) { if actual.SubscriptionId != v.Expected.SubscriptionId { t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) } + } } diff --git a/internal/services/signalr/sdk/2020-05-01/signalr/method_listbyresourcegroup_autorest.go b/internal/services/signalr/sdk/2020-05-01/signalr/method_listbyresourcegroup_autorest.go index 21a0f311b0ae..f7428dc3c560 100644 --- a/internal/services/signalr/sdk/2020-05-01/signalr/method_listbyresourcegroup_autorest.go +++ b/internal/services/signalr/sdk/2020-05-01/signalr/method_listbyresourcegroup_autorest.go @@ -110,7 +110,7 @@ func (c SignalRClient) preparerForListByResourceGroup(ctx context.Context, id Re autorest.AsContentType("application/json; charset=utf-8"), autorest.AsGet(), autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SignalRService/SignalR", id.ID())), + autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SignalRService/signalR", id.ID())), autorest.WithQueryParameters(queryParameters)) return preparer.Prepare((&http.Request{}).WithContext(ctx)) } diff --git a/internal/services/signalr/sdk/2020-05-01/signalr/method_listbysubscription_autorest.go b/internal/services/signalr/sdk/2020-05-01/signalr/method_listbysubscription_autorest.go index 0a0291562c2b..405bb779048b 100644 --- a/internal/services/signalr/sdk/2020-05-01/signalr/method_listbysubscription_autorest.go +++ b/internal/services/signalr/sdk/2020-05-01/signalr/method_listbysubscription_autorest.go @@ -110,7 +110,7 @@ func (c SignalRClient) preparerForListBySubscription(ctx context.Context, id Sub autorest.AsContentType("application/json; charset=utf-8"), autorest.AsGet(), autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SignalRService/SignalR", id.ID())), + autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SignalRService/signalR", id.ID())), autorest.WithQueryParameters(queryParameters)) return preparer.Prepare((&http.Request{}).WithContext(ctx)) } diff --git a/internal/services/signalr/sdk/2020-05-01/signalr/predicates.go b/internal/services/signalr/sdk/2020-05-01/signalr/predicates.go index e4c105c5a9cd..b5ff818357a7 100644 --- a/internal/services/signalr/sdk/2020-05-01/signalr/predicates.go +++ b/internal/services/signalr/sdk/2020-05-01/signalr/predicates.go @@ -7,6 +7,7 @@ type PrivateLinkResourcePredicate struct { } func (p PrivateLinkResourcePredicate) Matches(input PrivateLinkResource) bool { + if p.Id != nil && (input.Id == nil && *p.Id != *input.Id) { return false } @@ -30,6 +31,7 @@ type SignalRResourcePredicate struct { } func (p SignalRResourcePredicate) Matches(input SignalRResource) bool { + if p.Id != nil && (input.Id == nil && *p.Id != *input.Id) { return false } @@ -57,6 +59,7 @@ type SignalRUsagePredicate struct { } func (p SignalRUsagePredicate) Matches(input SignalRUsage) bool { + if p.CurrentValue != nil && (input.CurrentValue == nil && *p.CurrentValue != *input.CurrentValue) { return false } diff --git a/internal/services/signalr/signalr_service_data_source.go b/internal/services/signalr/signalr_service_data_source.go index 7ed93dedac9e..5a407dd564d0 100644 --- a/internal/services/signalr/signalr_service_data_source.go +++ b/internal/services/signalr/signalr_service_data_source.go @@ -107,8 +107,8 @@ func dataSourceArmSignalRServiceRead(d *pluginsdk.ResourceData, meta interface{} d.SetId(id.ID()) - d.Set("name", id.SignalRName) - d.Set("resource_group_name", id.ResourceGroup) + d.Set("name", id.ResourceName) + d.Set("resource_group_name", id.ResourceGroupName) if model := resp.Model; model != nil { d.Set("location", location.NormalizeNilable(model.Location)) diff --git a/internal/services/signalr/signalr_service_network_acl_resource.go b/internal/services/signalr/signalr_service_network_acl_resource.go index 036444b4758f..976a0bfc2333 100644 --- a/internal/services/signalr/signalr_service_network_acl_resource.go +++ b/internal/services/signalr/signalr_service_network_acl_resource.go @@ -143,8 +143,8 @@ func resourceSignalRServiceNetworkACLCreateUpdate(d *pluginsdk.ResourceData, met return err } - locks.ByName(id.SignalRName, "azurerm_signalr_service") - defer locks.UnlockByName(id.SignalRName, "azurerm_signalr_service") + locks.ByName(id.ResourceName, "azurerm_signalr_service") + defer locks.UnlockByName(id.ResourceName, "azurerm_signalr_service") resp, err := client.Get(ctx, *id) if err != nil { @@ -249,8 +249,8 @@ func resourceSignalRServiceNetworkACLDelete(d *pluginsdk.ResourceData, meta inte return err } - locks.ByName(id.SignalRName, "azurerm_signalr_service") - defer locks.UnlockByName(id.SignalRName, "azurerm_signalr_service") + locks.ByName(id.ResourceName, "azurerm_signalr_service") + defer locks.UnlockByName(id.ResourceName, "azurerm_signalr_service") resp, err := client.Get(ctx, *id) if err != nil { diff --git a/internal/services/signalr/signalr_service_resource.go b/internal/services/signalr/signalr_service_resource.go index 2f1811547ec6..215ee563cdd9 100644 --- a/internal/services/signalr/signalr_service_resource.go +++ b/internal/services/signalr/signalr_service_resource.go @@ -283,8 +283,8 @@ func resourceArmSignalRServiceRead(d *pluginsdk.ResourceData, meta interface{}) return fmt.Errorf("listing keys for %s: %+v", *id, err) } - d.Set("name", id.SignalRName) - d.Set("resource_group_name", id.ResourceGroup) + d.Set("name", id.ResourceName) + d.Set("resource_group_name", id.ResourceGroupName) if model := resp.Model; model != nil { d.Set("location", location.NormalizeNilable(model.Location))