From d638e8d9a13526b777599eca8dc31d878fadd952 Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Tue, 9 Nov 2021 16:27:57 -0800 Subject: [PATCH] Regenenerate sdk --- ...atabricks_customer_managed_key_resource.go | 10 +- ...icks_customer_managed_key_resource_test.go | 2 +- .../databricks_workspace_data_source.go | 4 +- .../databricks_workspace_resource.go | 6 +- .../databricks_workspace_resource_test.go | 2 +- .../delete/id_privateendpointconnection.go | 165 +++++----- .../id_privateendpointconnection_test.go | 269 ++++++++------- .../client.go | 15 + .../id_workspace.go | 124 +++++++ .../id_workspace_test.go | 264 +++++++++++++++ .../method_list_autorest.go | 65 ++++ .../model_endpointdependency.go | 6 + .../model_endpointdetail.go | 8 + .../model_outboundenvironmentendpoint.go | 6 + .../version.go | 9 + .../privateendpointconnections/client.go | 15 + .../privateendpointconnections/constants.go | 78 +++++ .../id_privateendpointconnection.go | 137 ++++++++ .../id_privateendpointconnection_test.go | 309 ++++++++++++++++++ .../id_workspace.go | 124 +++++++ .../id_workspace_test.go | 264 +++++++++++++++ .../method_get_autorest.go | 64 ++++ .../method_list_autorest.go | 183 +++++++++++ .../model_privateendpoint.go | 5 + .../model_privateendpointconnection.go | 8 + ...del_privateendpointconnectionproperties.go | 7 + ...model_privatelinkserviceconnectionstate.go | 7 + .../privateendpointconnections/predicates.go | 24 ++ .../privateendpointconnections/version.go | 9 + .../privatelinkresources/client.go | 15 + .../id_privatelinkresource.go | 137 ++++++++ .../id_privatelinkresource_test.go | 309 ++++++++++++++++++ .../privatelinkresources/id_workspace.go | 124 +++++++ .../privatelinkresources/id_workspace_test.go | 264 +++++++++++++++ .../method_get_autorest.go | 64 ++++ .../method_list_autorest.go | 183 +++++++++++ .../model_groupidinformation.go | 8 + .../model_groupidinformationproperties.go | 7 + .../privatelinkresources/predicates.go | 24 ++ .../privatelinkresources/version.go | 9 + .../sdk/2021-04-01-preview/put/constants.go | 58 ++++ .../put/id_privateendpointconnection.go | 165 +++++----- .../put/id_privateendpointconnection_test.go | 269 ++++++++------- .../vnetpeering/constants.go | 54 +++ .../vnetpeering/id_virtualnetworkpeering.go | 165 +++++----- .../id_virtualnetworkpeering_test.go | 269 ++++++++------- .../vnetpeering/id_workspace.go | 142 ++++---- .../vnetpeering/id_workspace_test.go | 225 +++++++------ .../workspaces/constants.go | 243 ++++++++++++++ .../workspaces/id_resourcegroup.go | 118 ++++--- .../workspaces/id_resourcegroup_test.go | 149 +++++---- .../workspaces/id_subscription.go | 93 ++++-- .../workspaces/id_subscription_test.go | 97 +++--- .../workspaces/id_workspace.go | 142 ++++---- .../workspaces/id_workspace_test.go | 225 +++++++------ .../workspaces/model_systemdata.go | 30 -- .../workspaces/model_workspaceproperties.go | 18 - 57 files changed, 4641 insertions(+), 1154 deletions(-) create mode 100644 internal/services/databricks/sdk/2021-04-01-preview/outboundnetworkdependenciesendpoints/client.go create mode 100644 internal/services/databricks/sdk/2021-04-01-preview/outboundnetworkdependenciesendpoints/id_workspace.go create mode 100644 internal/services/databricks/sdk/2021-04-01-preview/outboundnetworkdependenciesendpoints/id_workspace_test.go create mode 100644 internal/services/databricks/sdk/2021-04-01-preview/outboundnetworkdependenciesendpoints/method_list_autorest.go create mode 100644 internal/services/databricks/sdk/2021-04-01-preview/outboundnetworkdependenciesendpoints/model_endpointdependency.go create mode 100644 internal/services/databricks/sdk/2021-04-01-preview/outboundnetworkdependenciesendpoints/model_endpointdetail.go create mode 100644 internal/services/databricks/sdk/2021-04-01-preview/outboundnetworkdependenciesendpoints/model_outboundenvironmentendpoint.go create mode 100644 internal/services/databricks/sdk/2021-04-01-preview/outboundnetworkdependenciesendpoints/version.go create mode 100644 internal/services/databricks/sdk/2021-04-01-preview/privateendpointconnections/client.go create mode 100644 internal/services/databricks/sdk/2021-04-01-preview/privateendpointconnections/constants.go create mode 100644 internal/services/databricks/sdk/2021-04-01-preview/privateendpointconnections/id_privateendpointconnection.go create mode 100644 internal/services/databricks/sdk/2021-04-01-preview/privateendpointconnections/id_privateendpointconnection_test.go create mode 100644 internal/services/databricks/sdk/2021-04-01-preview/privateendpointconnections/id_workspace.go create mode 100644 internal/services/databricks/sdk/2021-04-01-preview/privateendpointconnections/id_workspace_test.go create mode 100644 internal/services/databricks/sdk/2021-04-01-preview/privateendpointconnections/method_get_autorest.go create mode 100644 internal/services/databricks/sdk/2021-04-01-preview/privateendpointconnections/method_list_autorest.go create mode 100644 internal/services/databricks/sdk/2021-04-01-preview/privateendpointconnections/model_privateendpoint.go create mode 100644 internal/services/databricks/sdk/2021-04-01-preview/privateendpointconnections/model_privateendpointconnection.go create mode 100644 internal/services/databricks/sdk/2021-04-01-preview/privateendpointconnections/model_privateendpointconnectionproperties.go create mode 100644 internal/services/databricks/sdk/2021-04-01-preview/privateendpointconnections/model_privatelinkserviceconnectionstate.go create mode 100644 internal/services/databricks/sdk/2021-04-01-preview/privateendpointconnections/predicates.go create mode 100644 internal/services/databricks/sdk/2021-04-01-preview/privateendpointconnections/version.go create mode 100644 internal/services/databricks/sdk/2021-04-01-preview/privatelinkresources/client.go create mode 100644 internal/services/databricks/sdk/2021-04-01-preview/privatelinkresources/id_privatelinkresource.go create mode 100644 internal/services/databricks/sdk/2021-04-01-preview/privatelinkresources/id_privatelinkresource_test.go create mode 100644 internal/services/databricks/sdk/2021-04-01-preview/privatelinkresources/id_workspace.go create mode 100644 internal/services/databricks/sdk/2021-04-01-preview/privatelinkresources/id_workspace_test.go create mode 100644 internal/services/databricks/sdk/2021-04-01-preview/privatelinkresources/method_get_autorest.go create mode 100644 internal/services/databricks/sdk/2021-04-01-preview/privatelinkresources/method_list_autorest.go create mode 100644 internal/services/databricks/sdk/2021-04-01-preview/privatelinkresources/model_groupidinformation.go create mode 100644 internal/services/databricks/sdk/2021-04-01-preview/privatelinkresources/model_groupidinformationproperties.go create mode 100644 internal/services/databricks/sdk/2021-04-01-preview/privatelinkresources/predicates.go create mode 100644 internal/services/databricks/sdk/2021-04-01-preview/privatelinkresources/version.go diff --git a/internal/services/databricks/databricks_customer_managed_key_resource.go b/internal/services/databricks/databricks_customer_managed_key_resource.go index 168b824a2592..56d680607bee 100644 --- a/internal/services/databricks/databricks_customer_managed_key_resource.go +++ b/internal/services/databricks/databricks_customer_managed_key_resource.go @@ -98,8 +98,8 @@ func DatabricksWorkspaceCustomerManagedKeyCreateUpdate(d *pluginsdk.ResourceData // Not sure if I should also lock the key vault here too // or at the very least the key? - locks.ByName(id.Name, "azurerm_databricks_workspace") - defer locks.UnlockByName(id.Name, "azurerm_databricks_workspace") + locks.ByName(id.WorkspaceName, "azurerm_databricks_workspace") + defer locks.UnlockByName(id.WorkspaceName, "azurerm_databricks_workspace") var encryptionEnabled, infrastructureEnabled bool workspace, err := workspaceClient.Get(ctx, *id) @@ -130,7 +130,7 @@ func DatabricksWorkspaceCustomerManagedKeyCreateUpdate(d *pluginsdk.ResourceData return fmt.Errorf("retrieving the Resource ID for the Key Vault at URL %q: %+v", key.KeyVaultBaseUrl, err) } - resourceID := parse.NewCustomerManagedKeyID(subscriptionId, id.ResourceGroup, id.Name) + resourceID := parse.NewCustomerManagedKeyID(subscriptionId, id.ResourceGroupName, id.WorkspaceName) if d.IsNewResource() { if workspace.Model != nil && workspace.Model.Properties.Parameters != nil && workspace.Model.Properties.Parameters.Encryption != nil { @@ -242,8 +242,8 @@ func DatabricksWorkspaceCustomerManagedKeyDelete(d *pluginsdk.ResourceData, meta workspaceID := workspaces.NewWorkspaceID(id.SubscriptionId, id.ResourceGroup, id.CustomerMangagedKeyName) // Not sure if I should also lock the key vault here too - locks.ByName(workspaceID.Name, "azurerm_databricks_workspace") - defer locks.UnlockByName(workspaceID.Name, "azurerm_databricks_workspace") + locks.ByName(workspaceID.WorkspaceName, "azurerm_databricks_workspace") + defer locks.UnlockByName(workspaceID.WorkspaceName, "azurerm_databricks_workspace") workspace, err := client.Get(ctx, workspaceID) if err != nil { diff --git a/internal/services/databricks/databricks_customer_managed_key_resource_test.go b/internal/services/databricks/databricks_customer_managed_key_resource_test.go index 2e2a58bcce3d..829885a1a9eb 100644 --- a/internal/services/databricks/databricks_customer_managed_key_resource_test.go +++ b/internal/services/databricks/databricks_customer_managed_key_resource_test.go @@ -111,7 +111,7 @@ func (DatabricksWorkspaceCustomerManagedKeyResource) Exists(ctx context.Context, resp, err := clients.DataBricks.WorkspacesClient.Get(ctx, *id) if err != nil { - return nil, fmt.Errorf("retrieving Databricks Workspace Customer Mangaged Key %q (resource group: %q): %+v", id.Name, id.ResourceGroup, err) + return nil, fmt.Errorf("retrieving %s: %+v", id, err) } // This is the only way we can tell if the CMK has actually been provisioned or not... diff --git a/internal/services/databricks/databricks_workspace_data_source.go b/internal/services/databricks/databricks_workspace_data_source.go index 6ddc1a423723..9dafbff53652 100644 --- a/internal/services/databricks/databricks_workspace_data_source.go +++ b/internal/services/databricks/databricks_workspace_data_source.go @@ -68,8 +68,8 @@ func dataSourceDatabricksWorkspaceRead(d *pluginsdk.ResourceData, meta interface d.SetId(id.ID()) - d.Set("name", id.Name) - d.Set("resource_group_name", id.ResourceGroup) + d.Set("name", id.WorkspaceName) + d.Set("resource_group_name", id.ResourceGroupName) d.Set("sku", resp.Model.Sku.Name) if model := resp.Model; model != nil { d.Set("workspace_id", model.Properties.WorkspaceId) diff --git a/internal/services/databricks/databricks_workspace_resource.go b/internal/services/databricks/databricks_workspace_resource.go index 2778f82ace32..8e6c62244f5a 100644 --- a/internal/services/databricks/databricks_workspace_resource.go +++ b/internal/services/databricks/databricks_workspace_resource.go @@ -368,7 +368,7 @@ func resourceDatabricksWorkspaceCreateUpdate(d *pluginsdk.ResourceData, meta int if managedResourceGroupName == "" { // no managed resource group name was provided, we use the default pattern log.Printf("[DEBUG][azurerm_databricks_workspace] no managed resource group id was provided, we use the default pattern.") - managedResourceGroupName = fmt.Sprintf("databricks-rg-%s", id.ResourceGroup) + managedResourceGroupName = fmt.Sprintf("databricks-rg-%s", id.ResourceGroupName) } managedResourceGroupID := resourcesParse.NewResourceGroupID(subscriptionId, managedResourceGroupName).ID() @@ -515,8 +515,8 @@ func resourceDatabricksWorkspaceRead(d *pluginsdk.ResourceData, meta interface{} return fmt.Errorf("retrieving %s: %+v", *id, err) } - d.Set("name", id.Name) - d.Set("resource_group_name", id.ResourceGroup) + d.Set("name", id.WorkspaceName) + d.Set("resource_group_name", id.ResourceGroupName) if model := resp.Model; model != nil { d.Set("location", azure.NormalizeLocation(model.Location)) diff --git a/internal/services/databricks/databricks_workspace_resource_test.go b/internal/services/databricks/databricks_workspace_resource_test.go index 51246b7cf732..c3e87ac50ea8 100644 --- a/internal/services/databricks/databricks_workspace_resource_test.go +++ b/internal/services/databricks/databricks_workspace_resource_test.go @@ -268,7 +268,7 @@ func (DatabricksWorkspaceResource) Exists(ctx context.Context, clients *clients. resp, err := clients.DataBricks.WorkspacesClient.Get(ctx, *id) if err != nil { - return nil, fmt.Errorf("retrieving Analysis Services Server %q (resource group: %q): %+v", id.Name, id.ResourceGroup, err) + return nil, fmt.Errorf("retrieving Analysis Services Server %q (resource group: %q): %+v", id.WorkspaceName, id.ResourceGroupName, err) } return utils.Bool(resp.Model != nil), nil diff --git a/internal/services/databricks/sdk/2021-04-01-preview/delete/id_privateendpointconnection.go b/internal/services/databricks/sdk/2021-04-01-preview/delete/id_privateendpointconnection.go index f052dd34cc82..1aace477bfe4 100644 --- a/internal/services/databricks/sdk/2021-04-01-preview/delete/id_privateendpointconnection.go +++ b/internal/services/databricks/sdk/2021-04-01-preview/delete/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 - WorkspaceName string - Name string + SubscriptionId string + ResourceGroupName string + WorkspaceName string + PrivateEndpointConnectionName string } -func NewPrivateEndpointConnectionID(subscriptionId, resourceGroup, workspaceName, name string) PrivateEndpointConnectionId { +// NewPrivateEndpointConnectionID returns a new PrivateEndpointConnectionId struct +func NewPrivateEndpointConnectionID(subscriptionId string, resourceGroupName string, workspaceName string, privateEndpointConnectionName string) PrivateEndpointConnectionId { return PrivateEndpointConnectionId{ - SubscriptionId: subscriptionId, - ResourceGroup: resourceGroup, - WorkspaceName: workspaceName, - Name: name, + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + PrivateEndpointConnectionName: privateEndpointConnectionName, } } -func (id PrivateEndpointConnectionId) String() string { - segments := []string{ - fmt.Sprintf("Name %q", id.Name), - fmt.Sprintf("Workspace Name %q", id.WorkspaceName), - fmt.Sprintf("Resource Group %q", id.ResourceGroup), - } - 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.Databricks/workspaces/%s/privateEndpointConnections/%s" - return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.WorkspaceName, 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.WorkspaceName, err = id.PopSegment("workspaces"); err != nil { - return nil, err - } - if resourceId.Name, err = id.PopSegment("privateEndpointConnections"); err != nil { - return nil, err + if id.WorkspaceName, ok = parsed.Parsed["workspaceName"]; !ok { + return nil, fmt.Errorf("the segment 'workspaceName' 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 'workspaces' segment - workspacesKey := "workspaces" - for key := range id.Path { - if strings.EqualFold(key, workspacesKey) { - workspacesKey = key - break - } + if id.WorkspaceName, ok = parsed.Parsed["workspaceName"]; !ok { + return nil, fmt.Errorf("the segment 'workspaceName' was not found in the resource id %q", input) } - if resourceId.WorkspaceName, err = id.PopSegment(workspacesKey); 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.Databricks/workspaces/%s/privateEndpointConnections/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, 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("microsoftDatabricks", "Microsoft.Databricks", "Microsoft.Databricks"), + resourceids.StaticSegment("workspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + 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("Workspace Name: %q", id.WorkspaceName), + 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/databricks/sdk/2021-04-01-preview/delete/id_privateendpointconnection_test.go b/internal/services/databricks/sdk/2021-04-01-preview/delete/id_privateendpointconnection_test.go index 19f1dcd0bbce..a2461df644be 100644 --- a/internal/services/databricks/sdk/2021-04-01-preview/delete/id_privateendpointconnection_test.go +++ b/internal/services/databricks/sdk/2021-04-01-preview/delete/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}", "{workspaceName}", "{privateEndpointConnectionName}").ID() - expected := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Databricks/workspaces/{workspaceName}/privateEndpointConnections/{privateEndpointConnectionName}" +func TestNewPrivateEndpointConnectionID(t *testing.T) { + id := NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "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.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + 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", "workspaceValue", "privateEndpointConnectionValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces/workspaceValue/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 WorkspaceName - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Databricks/", + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", Error: true, }, - { - // missing value for WorkspaceName - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Databricks/workspaces/", + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks", Error: true, }, - { - // missing Name - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Databricks/workspaces/{workspaceName}/", + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces", Error: true, }, - { - // missing value for Name - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Databricks/workspaces/{workspaceName}/privateEndpointConnections/", + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces/workspaceValue/privateEndpointConnections", Error: true, }, - { - // valid - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Databricks/workspaces/{workspaceName}/privateEndpointConnections/{privateEndpointConnectionName}", + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces/workspaceValue/privateEndpointConnections/privateEndpointConnectionValue", Expected: &PrivateEndpointConnectionId{ - SubscriptionId: "{subscriptionId}", - ResourceGroup: "{resourceGroupName}", - WorkspaceName: "{workspaceName}", - Name: "{privateEndpointConnectionName}", + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + PrivateEndpointConnectionName: "privateEndpointConnectionValue", }, }, - { - // upper-cased - Input: "/SUBSCRIPTIONS/{SUBSCRIPTIONID}/RESOURCEGROUPS/{RESOURCEGROUPNAME}/PROVIDERS/MICROSOFT.DATABRICKS/WORKSPACES/{WORKSPACENAME}/PRIVATEENDPOINTCONNECTIONS/{PRIVATEENDPOINTCONNECTIONNAME}", + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces/workspaceValue/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.WorkspaceName != v.Expected.WorkspaceName { t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) } - 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 WorkspaceName - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Databricks/", + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", Error: true, }, - { - // missing value for WorkspaceName - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Databricks/workspaces/", + // 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.Databricks/workspaces/{workspaceName}/", + // 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.Databricks/workspaces/{workspaceName}/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.Databricks/workspaces/{workspaceName}/privateEndpointConnections/{privateEndpointConnectionName}", - Expected: &PrivateEndpointConnectionId{ - SubscriptionId: "{subscriptionId}", - ResourceGroup: "{resourceGroupName}", - WorkspaceName: "{workspaceName}", - 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.Databricks/workspaces/{workspaceName}/privateendpointconnections/{privateEndpointConnectionName}", - Expected: &PrivateEndpointConnectionId{ - SubscriptionId: "{subscriptionId}", - ResourceGroup: "{resourceGroupName}", - WorkspaceName: "{workspaceName}", - 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.Databricks", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAbRiCkS", + Error: true, }, - { - // upper-cased segment names - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Databricks/WORKSPACES/{workspaceName}/PRIVATEENDPOINTCONNECTIONS/{privateEndpointConnectionName}", + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAbRiCkS/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAbRiCkS/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces/workspaceValue/privateEndpointConnections", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAbRiCkS/wOrKsPaCeS/wOrKsPaCeVaLuE/pRiVaTeEnDpOiNtCoNnEcTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces/workspaceValue/privateEndpointConnections/privateEndpointConnectionValue", Expected: &PrivateEndpointConnectionId{ - SubscriptionId: "{subscriptionId}", - ResourceGroup: "{resourceGroupName}", - WorkspaceName: "{workspaceName}", - Name: "{privateEndpointConnectionName}", + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + PrivateEndpointConnectionName: "privateEndpointConnectionValue", }, }, - { - // mixed-cased segment names - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Databricks/WoRkSpAcEs/{workspaceName}/PrIvAtEeNdPoInTcOnNeCtIoNs/{privateEndpointConnectionName}", + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces/workspaceValue/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.dAtAbRiCkS/wOrKsPaCeS/wOrKsPaCeVaLuE/pRiVaTeEnDpOiNtCoNnEcTiOnS/pRiVaTeEnDpOiNtCoNnEcTiOnVaLuE", Expected: &PrivateEndpointConnectionId{ - SubscriptionId: "{subscriptionId}", - ResourceGroup: "{resourceGroupName}", - WorkspaceName: "{workspaceName}", - Name: "{privateEndpointConnectionName}", + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + 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.dAtAbRiCkS/wOrKsPaCeS/wOrKsPaCeVaLuE/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.WorkspaceName != v.Expected.WorkspaceName { t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) } - 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/databricks/sdk/2021-04-01-preview/outboundnetworkdependenciesendpoints/client.go b/internal/services/databricks/sdk/2021-04-01-preview/outboundnetworkdependenciesendpoints/client.go new file mode 100644 index 000000000000..c1f9e041af10 --- /dev/null +++ b/internal/services/databricks/sdk/2021-04-01-preview/outboundnetworkdependenciesendpoints/client.go @@ -0,0 +1,15 @@ +package outboundnetworkdependenciesendpoints + +import "github.com/Azure/go-autorest/autorest" + +type OutboundNetworkDependenciesEndpointsClient struct { + Client autorest.Client + baseUri string +} + +func NewOutboundNetworkDependenciesEndpointsClientWithBaseURI(endpoint string) OutboundNetworkDependenciesEndpointsClient { + return OutboundNetworkDependenciesEndpointsClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/internal/services/databricks/sdk/2021-04-01-preview/outboundnetworkdependenciesendpoints/id_workspace.go b/internal/services/databricks/sdk/2021-04-01-preview/outboundnetworkdependenciesendpoints/id_workspace.go new file mode 100644 index 000000000000..a42f3142f998 --- /dev/null +++ b/internal/services/databricks/sdk/2021-04-01-preview/outboundnetworkdependenciesendpoints/id_workspace.go @@ -0,0 +1,124 @@ +package outboundnetworkdependenciesendpoints + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace +type WorkspaceId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string +} + +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, workspaceName string) WorkspaceId { + return WorkspaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + } +} + +// ParseWorkspaceID parses 'input' into a WorkspaceId +func ParseWorkspaceID(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(WorkspaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := WorkspaceId{} + + 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 id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.WorkspaceName, ok = parsed.Parsed["workspaceName"]; !ok { + return nil, fmt.Errorf("the segment 'workspaceName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(WorkspaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := WorkspaceId{} + + 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 id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.WorkspaceName, ok = parsed.Parsed["workspaceName"]; !ok { + return nil, fmt.Errorf("the segment 'workspaceName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(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 := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Databricks/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) 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("microsoftDatabricks", "Microsoft.Databricks", "Microsoft.Databricks"), + resourceids.StaticSegment("workspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + } +} + +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) +} diff --git a/internal/services/databricks/sdk/2021-04-01-preview/outboundnetworkdependenciesendpoints/id_workspace_test.go b/internal/services/databricks/sdk/2021-04-01-preview/outboundnetworkdependenciesendpoints/id_workspace_test.go new file mode 100644 index 000000000000..ad9994213dfa --- /dev/null +++ b/internal/services/databricks/sdk/2021-04-01-preview/outboundnetworkdependenciesendpoints/id_workspace_test.go @@ -0,0 +1,264 @@ +package outboundnetworkdependenciesendpoints + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = WorkspaceId{} + +func TestNewWorkspaceID(t *testing.T) { + id := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + + 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.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } +} + +func TestFormatWorkspaceID(t *testing.T) { + actual := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces/workspaceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", actual, expected) + } +} + +func TestParseWorkspaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces/workspaceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestParseWorkspaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAbRiCkS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAbRiCkS/wOrKsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces/workspaceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAbRiCkS/wOrKsPaCeS/wOrKsPaCeVaLuE", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + }, + }, + { + // 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.dAtAbRiCkS/wOrKsPaCeS/wOrKsPaCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} diff --git a/internal/services/databricks/sdk/2021-04-01-preview/outboundnetworkdependenciesendpoints/method_list_autorest.go b/internal/services/databricks/sdk/2021-04-01-preview/outboundnetworkdependenciesendpoints/method_list_autorest.go new file mode 100644 index 000000000000..5a0f9bff7de1 --- /dev/null +++ b/internal/services/databricks/sdk/2021-04-01-preview/outboundnetworkdependenciesendpoints/method_list_autorest.go @@ -0,0 +1,65 @@ +package outboundnetworkdependenciesendpoints + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +type ListResponse struct { + HttpResponse *http.Response + Model *[]OutboundEnvironmentEndpoint +} + +// List ... +func (c OutboundNetworkDependenciesEndpointsClient) List(ctx context.Context, id WorkspaceId) (result ListResponse, err error) { + req, err := c.preparerForList(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "outboundnetworkdependenciesendpoints.OutboundNetworkDependenciesEndpointsClient", "List", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "outboundnetworkdependenciesendpoints.OutboundNetworkDependenciesEndpointsClient", "List", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "outboundnetworkdependenciesendpoints.OutboundNetworkDependenciesEndpointsClient", "List", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForList prepares the List request. +func (c OutboundNetworkDependenciesEndpointsClient) preparerForList(ctx context.Context, id WorkspaceId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/outboundNetworkDependenciesEndpoints", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForList handles the response to the List request. The method always +// closes the http.Response Body. +func (c OutboundNetworkDependenciesEndpointsClient) responderForList(resp *http.Response) (result ListResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/internal/services/databricks/sdk/2021-04-01-preview/outboundnetworkdependenciesendpoints/model_endpointdependency.go b/internal/services/databricks/sdk/2021-04-01-preview/outboundnetworkdependenciesendpoints/model_endpointdependency.go new file mode 100644 index 000000000000..b2b3ad40cc07 --- /dev/null +++ b/internal/services/databricks/sdk/2021-04-01-preview/outboundnetworkdependenciesendpoints/model_endpointdependency.go @@ -0,0 +1,6 @@ +package outboundnetworkdependenciesendpoints + +type EndpointDependency struct { + DomainName *string `json:"domainName,omitempty"` + EndpointDetails *[]EndpointDetail `json:"endpointDetails,omitempty"` +} diff --git a/internal/services/databricks/sdk/2021-04-01-preview/outboundnetworkdependenciesendpoints/model_endpointdetail.go b/internal/services/databricks/sdk/2021-04-01-preview/outboundnetworkdependenciesendpoints/model_endpointdetail.go new file mode 100644 index 000000000000..f55234a7b3e6 --- /dev/null +++ b/internal/services/databricks/sdk/2021-04-01-preview/outboundnetworkdependenciesendpoints/model_endpointdetail.go @@ -0,0 +1,8 @@ +package outboundnetworkdependenciesendpoints + +type EndpointDetail struct { + IpAddress *string `json:"ipAddress,omitempty"` + IsAccessible *bool `json:"isAccessible,omitempty"` + Latency *float64 `json:"latency,omitempty"` + Port *int64 `json:"port,omitempty"` +} diff --git a/internal/services/databricks/sdk/2021-04-01-preview/outboundnetworkdependenciesendpoints/model_outboundenvironmentendpoint.go b/internal/services/databricks/sdk/2021-04-01-preview/outboundnetworkdependenciesendpoints/model_outboundenvironmentendpoint.go new file mode 100644 index 000000000000..886707727431 --- /dev/null +++ b/internal/services/databricks/sdk/2021-04-01-preview/outboundnetworkdependenciesendpoints/model_outboundenvironmentendpoint.go @@ -0,0 +1,6 @@ +package outboundnetworkdependenciesendpoints + +type OutboundEnvironmentEndpoint struct { + Category *string `json:"category,omitempty"` + Endpoints *[]EndpointDependency `json:"endpoints,omitempty"` +} diff --git a/internal/services/databricks/sdk/2021-04-01-preview/outboundnetworkdependenciesendpoints/version.go b/internal/services/databricks/sdk/2021-04-01-preview/outboundnetworkdependenciesendpoints/version.go new file mode 100644 index 000000000000..748f4e7a5b3e --- /dev/null +++ b/internal/services/databricks/sdk/2021-04-01-preview/outboundnetworkdependenciesendpoints/version.go @@ -0,0 +1,9 @@ +package outboundnetworkdependenciesendpoints + +import "fmt" + +const defaultApiVersion = "2021-04-01-preview" + +func userAgent() string { + return fmt.Sprintf("pandora/outboundnetworkdependenciesendpoints/%s", defaultApiVersion) +} diff --git a/internal/services/databricks/sdk/2021-04-01-preview/privateendpointconnections/client.go b/internal/services/databricks/sdk/2021-04-01-preview/privateendpointconnections/client.go new file mode 100644 index 000000000000..adc4283affb2 --- /dev/null +++ b/internal/services/databricks/sdk/2021-04-01-preview/privateendpointconnections/client.go @@ -0,0 +1,15 @@ +package privateendpointconnections + +import "github.com/Azure/go-autorest/autorest" + +type PrivateEndpointConnectionsClient struct { + Client autorest.Client + baseUri string +} + +func NewPrivateEndpointConnectionsClientWithBaseURI(endpoint string) PrivateEndpointConnectionsClient { + return PrivateEndpointConnectionsClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/internal/services/databricks/sdk/2021-04-01-preview/privateendpointconnections/constants.go b/internal/services/databricks/sdk/2021-04-01-preview/privateendpointconnections/constants.go new file mode 100644 index 000000000000..4649bfc8148c --- /dev/null +++ b/internal/services/databricks/sdk/2021-04-01-preview/privateendpointconnections/constants.go @@ -0,0 +1,78 @@ +package privateendpointconnections + +import "strings" + +type PrivateEndpointConnectionProvisioningState string + +const ( + PrivateEndpointConnectionProvisioningStateCreating PrivateEndpointConnectionProvisioningState = "Creating" + PrivateEndpointConnectionProvisioningStateDeleting PrivateEndpointConnectionProvisioningState = "Deleting" + PrivateEndpointConnectionProvisioningStateFailed PrivateEndpointConnectionProvisioningState = "Failed" + PrivateEndpointConnectionProvisioningStateSucceeded PrivateEndpointConnectionProvisioningState = "Succeeded" + PrivateEndpointConnectionProvisioningStateUpdating PrivateEndpointConnectionProvisioningState = "Updating" +) + +func PossibleValuesForPrivateEndpointConnectionProvisioningState() []string { + return []string{ + "Creating", + "Deleting", + "Failed", + "Succeeded", + "Updating", + } +} + +func parsePrivateEndpointConnectionProvisioningState(input string) (*PrivateEndpointConnectionProvisioningState, error) { + vals := map[string]PrivateEndpointConnectionProvisioningState{ + "creating": "Creating", + "deleting": "Deleting", + "failed": "Failed", + "succeeded": "Succeeded", + "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 := PrivateEndpointConnectionProvisioningState(v) + return &out, nil +} + +type PrivateLinkServiceConnectionStatus string + +const ( + PrivateLinkServiceConnectionStatusApproved PrivateLinkServiceConnectionStatus = "Approved" + PrivateLinkServiceConnectionStatusDisconnected PrivateLinkServiceConnectionStatus = "Disconnected" + PrivateLinkServiceConnectionStatusPending PrivateLinkServiceConnectionStatus = "Pending" + 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 +} diff --git a/internal/services/databricks/sdk/2021-04-01-preview/privateendpointconnections/id_privateendpointconnection.go b/internal/services/databricks/sdk/2021-04-01-preview/privateendpointconnections/id_privateendpointconnection.go new file mode 100644 index 000000000000..acde749231cd --- /dev/null +++ b/internal/services/databricks/sdk/2021-04-01-preview/privateendpointconnections/id_privateendpointconnection.go @@ -0,0 +1,137 @@ +package privateendpointconnections + +import ( + "fmt" + "strings" + + "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 + ResourceGroupName string + WorkspaceName string + PrivateEndpointConnectionName string +} + +// NewPrivateEndpointConnectionID returns a new PrivateEndpointConnectionId struct +func NewPrivateEndpointConnectionID(subscriptionId string, resourceGroupName string, workspaceName string, privateEndpointConnectionName string) PrivateEndpointConnectionId { + return PrivateEndpointConnectionId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + PrivateEndpointConnectionName: privateEndpointConnectionName, + } +} + +// ParsePrivateEndpointConnectionID parses 'input' into a PrivateEndpointConnectionId +func ParsePrivateEndpointConnectionID(input string) (*PrivateEndpointConnectionId, error) { + parser := resourceids.NewParserFromResourceIdType(PrivateEndpointConnectionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := PrivateEndpointConnectionId{} + + 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 id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.WorkspaceName, ok = parsed.Parsed["workspaceName"]; !ok { + return nil, fmt.Errorf("the segment 'workspaceName' was not found in the resource id %q", input) + } + + 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 &id, nil +} + +// 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) { + parser := resourceids.NewParserFromResourceIdType(PrivateEndpointConnectionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := PrivateEndpointConnectionId{} + + 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 id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.WorkspaceName, ok = parsed.Parsed["workspaceName"]; !ok { + return nil, fmt.Errorf("the segment 'workspaceName' was not found in the resource id %q", input) + } + + 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 &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 _, err := ParsePrivateEndpointConnectionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Private Endpoint Connection ID +func (id PrivateEndpointConnectionId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Databricks/workspaces/%s/privateEndpointConnections/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, 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("microsoftDatabricks", "Microsoft.Databricks", "Microsoft.Databricks"), + resourceids.StaticSegment("workspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("privateEndpointConnections", "privateEndpointConnections", "privateEndpointConnections"), + resourceids.UserSpecifiedSegment("privateEndpointConnectionName", "privateEndpointConnectionValue"), + } +} + +// 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("Workspace Name: %q", id.WorkspaceName), + 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/databricks/sdk/2021-04-01-preview/privateendpointconnections/id_privateendpointconnection_test.go b/internal/services/databricks/sdk/2021-04-01-preview/privateendpointconnections/id_privateendpointconnection_test.go new file mode 100644 index 000000000000..ba780168c140 --- /dev/null +++ b/internal/services/databricks/sdk/2021-04-01-preview/privateendpointconnections/id_privateendpointconnection_test.go @@ -0,0 +1,309 @@ +package privateendpointconnections + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = PrivateEndpointConnectionId{} + +func TestNewPrivateEndpointConnectionID(t *testing.T) { + id := NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "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.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + 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", "workspaceValue", "privateEndpointConnectionValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces/workspaceValue/privateEndpointConnections/privateEndpointConnectionValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", actual, expected) + } +} + +func TestParsePrivateEndpointConnectionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateEndpointConnectionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces/workspaceValue/privateEndpointConnections", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces/workspaceValue/privateEndpointConnections/privateEndpointConnectionValue", + Expected: &PrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + PrivateEndpointConnectionName: "privateEndpointConnectionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces/workspaceValue/privateEndpointConnections/privateEndpointConnectionValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateEndpointConnectionID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.PrivateEndpointConnectionName != v.Expected.PrivateEndpointConnectionName { + t.Fatalf("Expected %q but got %q for PrivateEndpointConnectionName", v.Expected.PrivateEndpointConnectionName, actual.PrivateEndpointConnectionName) + } + + } +} + +func TestParsePrivateEndpointConnectionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateEndpointConnectionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAbRiCkS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAbRiCkS/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAbRiCkS/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces/workspaceValue/privateEndpointConnections", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAbRiCkS/wOrKsPaCeS/wOrKsPaCeVaLuE/pRiVaTeEnDpOiNtCoNnEcTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces/workspaceValue/privateEndpointConnections/privateEndpointConnectionValue", + Expected: &PrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + PrivateEndpointConnectionName: "privateEndpointConnectionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces/workspaceValue/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.dAtAbRiCkS/wOrKsPaCeS/wOrKsPaCeVaLuE/pRiVaTeEnDpOiNtCoNnEcTiOnS/pRiVaTeEnDpOiNtCoNnEcTiOnVaLuE", + Expected: &PrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + 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.dAtAbRiCkS/wOrKsPaCeS/wOrKsPaCeVaLuE/pRiVaTeEnDpOiNtCoNnEcTiOnS/pRiVaTeEnDpOiNtCoNnEcTiOnVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateEndpointConnectionIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + 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/databricks/sdk/2021-04-01-preview/privateendpointconnections/id_workspace.go b/internal/services/databricks/sdk/2021-04-01-preview/privateendpointconnections/id_workspace.go new file mode 100644 index 000000000000..3b33ae5dd874 --- /dev/null +++ b/internal/services/databricks/sdk/2021-04-01-preview/privateendpointconnections/id_workspace.go @@ -0,0 +1,124 @@ +package privateendpointconnections + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace +type WorkspaceId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string +} + +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, workspaceName string) WorkspaceId { + return WorkspaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + } +} + +// ParseWorkspaceID parses 'input' into a WorkspaceId +func ParseWorkspaceID(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(WorkspaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := WorkspaceId{} + + 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 id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.WorkspaceName, ok = parsed.Parsed["workspaceName"]; !ok { + return nil, fmt.Errorf("the segment 'workspaceName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(WorkspaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := WorkspaceId{} + + 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 id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.WorkspaceName, ok = parsed.Parsed["workspaceName"]; !ok { + return nil, fmt.Errorf("the segment 'workspaceName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(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 := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Databricks/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) 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("microsoftDatabricks", "Microsoft.Databricks", "Microsoft.Databricks"), + resourceids.StaticSegment("workspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + } +} + +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) +} diff --git a/internal/services/databricks/sdk/2021-04-01-preview/privateendpointconnections/id_workspace_test.go b/internal/services/databricks/sdk/2021-04-01-preview/privateendpointconnections/id_workspace_test.go new file mode 100644 index 000000000000..719eff954e75 --- /dev/null +++ b/internal/services/databricks/sdk/2021-04-01-preview/privateendpointconnections/id_workspace_test.go @@ -0,0 +1,264 @@ +package privateendpointconnections + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = WorkspaceId{} + +func TestNewWorkspaceID(t *testing.T) { + id := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + + 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.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } +} + +func TestFormatWorkspaceID(t *testing.T) { + actual := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces/workspaceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", actual, expected) + } +} + +func TestParseWorkspaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces/workspaceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestParseWorkspaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAbRiCkS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAbRiCkS/wOrKsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces/workspaceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAbRiCkS/wOrKsPaCeS/wOrKsPaCeVaLuE", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + }, + }, + { + // 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.dAtAbRiCkS/wOrKsPaCeS/wOrKsPaCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} diff --git a/internal/services/databricks/sdk/2021-04-01-preview/privateendpointconnections/method_get_autorest.go b/internal/services/databricks/sdk/2021-04-01-preview/privateendpointconnections/method_get_autorest.go new file mode 100644 index 000000000000..10ec2007dc6d --- /dev/null +++ b/internal/services/databricks/sdk/2021-04-01-preview/privateendpointconnections/method_get_autorest.go @@ -0,0 +1,64 @@ +package privateendpointconnections + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +type GetResponse struct { + HttpResponse *http.Response + Model *PrivateEndpointConnection +} + +// Get ... +func (c PrivateEndpointConnectionsClient) Get(ctx context.Context, id PrivateEndpointConnectionId) (result GetResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "privateendpointconnections.PrivateEndpointConnectionsClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "privateendpointconnections.PrivateEndpointConnectionsClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "privateendpointconnections.PrivateEndpointConnectionsClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c PrivateEndpointConnectionsClient) preparerForGet(ctx context.Context, id PrivateEndpointConnectionId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForGet handles the response to the Get request. The method always +// closes the http.Response Body. +func (c PrivateEndpointConnectionsClient) responderForGet(resp *http.Response) (result GetResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/internal/services/databricks/sdk/2021-04-01-preview/privateendpointconnections/method_list_autorest.go b/internal/services/databricks/sdk/2021-04-01-preview/privateendpointconnections/method_list_autorest.go new file mode 100644 index 000000000000..2a41d61f7253 --- /dev/null +++ b/internal/services/databricks/sdk/2021-04-01-preview/privateendpointconnections/method_list_autorest.go @@ -0,0 +1,183 @@ +package privateendpointconnections + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +type ListResponse struct { + HttpResponse *http.Response + Model *[]PrivateEndpointConnection + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListResponse, error) +} + +type ListCompleteResult struct { + Items []PrivateEndpointConnection +} + +func (r ListResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListResponse) LoadMore(ctx context.Context) (resp ListResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// List ... +func (c PrivateEndpointConnectionsClient) List(ctx context.Context, id WorkspaceId) (resp ListResponse, err error) { + req, err := c.preparerForList(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "privateendpointconnections.PrivateEndpointConnectionsClient", "List", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "privateendpointconnections.PrivateEndpointConnectionsClient", "List", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForList(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "privateendpointconnections.PrivateEndpointConnectionsClient", "List", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// ListComplete retrieves all of the results into a single object +func (c PrivateEndpointConnectionsClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, PrivateEndpointConnectionPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c PrivateEndpointConnectionsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate PrivateEndpointConnectionPredicate) (resp ListCompleteResult, err error) { + items := make([]PrivateEndpointConnection, 0) + + page, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListCompleteResult{ + Items: items, + } + return out, nil +} + +// preparerForList prepares the List request. +func (c PrivateEndpointConnectionsClient) preparerForList(ctx context.Context, id WorkspaceId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/privateEndpointConnections", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListWithNextLink prepares the List request with the given nextLink token. +func (c PrivateEndpointConnectionsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForList handles the response to the List request. The method always +// closes the http.Response Body. +func (c PrivateEndpointConnectionsClient) responderForList(resp *http.Response) (result ListResponse, err error) { + type page struct { + Values []PrivateEndpointConnection `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListResponse, err error) { + req, err := c.preparerForListWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "privateendpointconnections.PrivateEndpointConnectionsClient", "List", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "privateendpointconnections.PrivateEndpointConnectionsClient", "List", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "privateendpointconnections.PrivateEndpointConnectionsClient", "List", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} diff --git a/internal/services/databricks/sdk/2021-04-01-preview/privateendpointconnections/model_privateendpoint.go b/internal/services/databricks/sdk/2021-04-01-preview/privateendpointconnections/model_privateendpoint.go new file mode 100644 index 000000000000..33ffc888d58a --- /dev/null +++ b/internal/services/databricks/sdk/2021-04-01-preview/privateendpointconnections/model_privateendpoint.go @@ -0,0 +1,5 @@ +package privateendpointconnections + +type PrivateEndpoint struct { + Id *string `json:"id,omitempty"` +} diff --git a/internal/services/databricks/sdk/2021-04-01-preview/privateendpointconnections/model_privateendpointconnection.go b/internal/services/databricks/sdk/2021-04-01-preview/privateendpointconnections/model_privateendpointconnection.go new file mode 100644 index 000000000000..a7282003caf6 --- /dev/null +++ b/internal/services/databricks/sdk/2021-04-01-preview/privateendpointconnections/model_privateendpointconnection.go @@ -0,0 +1,8 @@ +package privateendpointconnections + +type PrivateEndpointConnection struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties PrivateEndpointConnectionProperties `json:"properties"` + Type *string `json:"type,omitempty"` +} diff --git a/internal/services/databricks/sdk/2021-04-01-preview/privateendpointconnections/model_privateendpointconnectionproperties.go b/internal/services/databricks/sdk/2021-04-01-preview/privateendpointconnections/model_privateendpointconnectionproperties.go new file mode 100644 index 000000000000..252bd91cbe86 --- /dev/null +++ b/internal/services/databricks/sdk/2021-04-01-preview/privateendpointconnections/model_privateendpointconnectionproperties.go @@ -0,0 +1,7 @@ +package privateendpointconnections + +type PrivateEndpointConnectionProperties struct { + PrivateEndpoint *PrivateEndpoint `json:"privateEndpoint,omitempty"` + PrivateLinkServiceConnectionState PrivateLinkServiceConnectionState `json:"privateLinkServiceConnectionState"` + ProvisioningState *PrivateEndpointConnectionProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/internal/services/databricks/sdk/2021-04-01-preview/privateendpointconnections/model_privatelinkserviceconnectionstate.go b/internal/services/databricks/sdk/2021-04-01-preview/privateendpointconnections/model_privatelinkserviceconnectionstate.go new file mode 100644 index 000000000000..c2f16e525600 --- /dev/null +++ b/internal/services/databricks/sdk/2021-04-01-preview/privateendpointconnections/model_privatelinkserviceconnectionstate.go @@ -0,0 +1,7 @@ +package privateendpointconnections + +type PrivateLinkServiceConnectionState struct { + ActionRequired *string `json:"actionRequired,omitempty"` + Description *string `json:"description,omitempty"` + Status PrivateLinkServiceConnectionStatus `json:"status"` +} diff --git a/internal/services/databricks/sdk/2021-04-01-preview/privateendpointconnections/predicates.go b/internal/services/databricks/sdk/2021-04-01-preview/privateendpointconnections/predicates.go new file mode 100644 index 000000000000..088034749cf2 --- /dev/null +++ b/internal/services/databricks/sdk/2021-04-01-preview/privateendpointconnections/predicates.go @@ -0,0 +1,24 @@ +package privateendpointconnections + +type PrivateEndpointConnectionPredicate struct { + Id *string + Name *string + Type *string +} + +func (p PrivateEndpointConnectionPredicate) Matches(input PrivateEndpointConnection) bool { + + if p.Id != nil && (input.Id == nil && *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil && *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil && *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/internal/services/databricks/sdk/2021-04-01-preview/privateendpointconnections/version.go b/internal/services/databricks/sdk/2021-04-01-preview/privateendpointconnections/version.go new file mode 100644 index 000000000000..0e0108f8f914 --- /dev/null +++ b/internal/services/databricks/sdk/2021-04-01-preview/privateendpointconnections/version.go @@ -0,0 +1,9 @@ +package privateendpointconnections + +import "fmt" + +const defaultApiVersion = "2021-04-01-preview" + +func userAgent() string { + return fmt.Sprintf("pandora/privateendpointconnections/%s", defaultApiVersion) +} diff --git a/internal/services/databricks/sdk/2021-04-01-preview/privatelinkresources/client.go b/internal/services/databricks/sdk/2021-04-01-preview/privatelinkresources/client.go new file mode 100644 index 000000000000..3ccc015d4fe1 --- /dev/null +++ b/internal/services/databricks/sdk/2021-04-01-preview/privatelinkresources/client.go @@ -0,0 +1,15 @@ +package privatelinkresources + +import "github.com/Azure/go-autorest/autorest" + +type PrivateLinkResourcesClient struct { + Client autorest.Client + baseUri string +} + +func NewPrivateLinkResourcesClientWithBaseURI(endpoint string) PrivateLinkResourcesClient { + return PrivateLinkResourcesClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/internal/services/databricks/sdk/2021-04-01-preview/privatelinkresources/id_privatelinkresource.go b/internal/services/databricks/sdk/2021-04-01-preview/privatelinkresources/id_privatelinkresource.go new file mode 100644 index 000000000000..5cc3c820aad1 --- /dev/null +++ b/internal/services/databricks/sdk/2021-04-01-preview/privatelinkresources/id_privatelinkresource.go @@ -0,0 +1,137 @@ +package privatelinkresources + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = PrivateLinkResourceId{} + +// PrivateLinkResourceId is a struct representing the Resource ID for a Private Link Resource +type PrivateLinkResourceId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + GroupId string +} + +// NewPrivateLinkResourceID returns a new PrivateLinkResourceId struct +func NewPrivateLinkResourceID(subscriptionId string, resourceGroupName string, workspaceName string, groupId string) PrivateLinkResourceId { + return PrivateLinkResourceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + GroupId: groupId, + } +} + +// ParsePrivateLinkResourceID parses 'input' into a PrivateLinkResourceId +func ParsePrivateLinkResourceID(input string) (*PrivateLinkResourceId, error) { + parser := resourceids.NewParserFromResourceIdType(PrivateLinkResourceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := PrivateLinkResourceId{} + + 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 id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.WorkspaceName, ok = parsed.Parsed["workspaceName"]; !ok { + return nil, fmt.Errorf("the segment 'workspaceName' was not found in the resource id %q", input) + } + + if id.GroupId, ok = parsed.Parsed["groupId"]; !ok { + return nil, fmt.Errorf("the segment 'groupId' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParsePrivateLinkResourceIDInsensitively parses 'input' case-insensitively into a PrivateLinkResourceId +// note: this method should only be used for API response data and not user input +func ParsePrivateLinkResourceIDInsensitively(input string) (*PrivateLinkResourceId, error) { + parser := resourceids.NewParserFromResourceIdType(PrivateLinkResourceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := PrivateLinkResourceId{} + + 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 id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.WorkspaceName, ok = parsed.Parsed["workspaceName"]; !ok { + return nil, fmt.Errorf("the segment 'workspaceName' was not found in the resource id %q", input) + } + + if id.GroupId, ok = parsed.Parsed["groupId"]; !ok { + return nil, fmt.Errorf("the segment 'groupId' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidatePrivateLinkResourceID checks that 'input' can be parsed as a Private Link Resource ID +func ValidatePrivateLinkResourceID(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 := ParsePrivateLinkResourceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Private Link Resource ID +func (id PrivateLinkResourceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Databricks/workspaces/%s/privateLinkResources/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.GroupId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Private Link Resource ID +func (id PrivateLinkResourceId) 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("microsoftDatabricks", "Microsoft.Databricks", "Microsoft.Databricks"), + resourceids.StaticSegment("workspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("privateLinkResources", "privateLinkResources", "privateLinkResources"), + resourceids.UserSpecifiedSegment("groupId", "groupIdValue"), + } +} + +// String returns a human-readable description of this Private Link Resource ID +func (id PrivateLinkResourceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Group: %q", id.GroupId), + } + return fmt.Sprintf("Private Link Resource (%s)", strings.Join(components, "\n")) +} diff --git a/internal/services/databricks/sdk/2021-04-01-preview/privatelinkresources/id_privatelinkresource_test.go b/internal/services/databricks/sdk/2021-04-01-preview/privatelinkresources/id_privatelinkresource_test.go new file mode 100644 index 000000000000..93e4201856fb --- /dev/null +++ b/internal/services/databricks/sdk/2021-04-01-preview/privatelinkresources/id_privatelinkresource_test.go @@ -0,0 +1,309 @@ +package privatelinkresources + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = PrivateLinkResourceId{} + +func TestNewPrivateLinkResourceID(t *testing.T) { + id := NewPrivateLinkResourceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "groupIdValue") + + 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.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.GroupId != "groupIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'GroupId'", id.GroupId, "groupIdValue") + } +} + +func TestFormatPrivateLinkResourceID(t *testing.T) { + actual := NewPrivateLinkResourceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "groupIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces/workspaceValue/privateLinkResources/groupIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", actual, expected) + } +} + +func TestParsePrivateLinkResourceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateLinkResourceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces/workspaceValue/privateLinkResources", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces/workspaceValue/privateLinkResources/groupIdValue", + Expected: &PrivateLinkResourceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + GroupId: "groupIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces/workspaceValue/privateLinkResources/groupIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateLinkResourceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.GroupId != v.Expected.GroupId { + t.Fatalf("Expected %q but got %q for GroupId", v.Expected.GroupId, actual.GroupId) + } + + } +} + +func TestParsePrivateLinkResourceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateLinkResourceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAbRiCkS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAbRiCkS/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAbRiCkS/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces/workspaceValue/privateLinkResources", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAbRiCkS/wOrKsPaCeS/wOrKsPaCeVaLuE/pRiVaTeLiNkReSoUrCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces/workspaceValue/privateLinkResources/groupIdValue", + Expected: &PrivateLinkResourceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + GroupId: "groupIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces/workspaceValue/privateLinkResources/groupIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAbRiCkS/wOrKsPaCeS/wOrKsPaCeVaLuE/pRiVaTeLiNkReSoUrCeS/gRoUpIdVaLuE", + Expected: &PrivateLinkResourceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + GroupId: "gRoUpIdVaLuE", + }, + }, + { + // 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.dAtAbRiCkS/wOrKsPaCeS/wOrKsPaCeVaLuE/pRiVaTeLiNkReSoUrCeS/gRoUpIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateLinkResourceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.GroupId != v.Expected.GroupId { + t.Fatalf("Expected %q but got %q for GroupId", v.Expected.GroupId, actual.GroupId) + } + + } +} diff --git a/internal/services/databricks/sdk/2021-04-01-preview/privatelinkresources/id_workspace.go b/internal/services/databricks/sdk/2021-04-01-preview/privatelinkresources/id_workspace.go new file mode 100644 index 000000000000..fb3c55d19634 --- /dev/null +++ b/internal/services/databricks/sdk/2021-04-01-preview/privatelinkresources/id_workspace.go @@ -0,0 +1,124 @@ +package privatelinkresources + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace +type WorkspaceId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string +} + +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, workspaceName string) WorkspaceId { + return WorkspaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + } +} + +// ParseWorkspaceID parses 'input' into a WorkspaceId +func ParseWorkspaceID(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(WorkspaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := WorkspaceId{} + + 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 id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.WorkspaceName, ok = parsed.Parsed["workspaceName"]; !ok { + return nil, fmt.Errorf("the segment 'workspaceName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(WorkspaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := WorkspaceId{} + + 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 id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.WorkspaceName, ok = parsed.Parsed["workspaceName"]; !ok { + return nil, fmt.Errorf("the segment 'workspaceName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(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 := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Databricks/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) 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("microsoftDatabricks", "Microsoft.Databricks", "Microsoft.Databricks"), + resourceids.StaticSegment("workspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + } +} + +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) +} diff --git a/internal/services/databricks/sdk/2021-04-01-preview/privatelinkresources/id_workspace_test.go b/internal/services/databricks/sdk/2021-04-01-preview/privatelinkresources/id_workspace_test.go new file mode 100644 index 000000000000..f2cff2e59b67 --- /dev/null +++ b/internal/services/databricks/sdk/2021-04-01-preview/privatelinkresources/id_workspace_test.go @@ -0,0 +1,264 @@ +package privatelinkresources + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = WorkspaceId{} + +func TestNewWorkspaceID(t *testing.T) { + id := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + + 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.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } +} + +func TestFormatWorkspaceID(t *testing.T) { + actual := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces/workspaceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", actual, expected) + } +} + +func TestParseWorkspaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces/workspaceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestParseWorkspaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAbRiCkS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAbRiCkS/wOrKsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces/workspaceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAbRiCkS/wOrKsPaCeS/wOrKsPaCeVaLuE", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + }, + }, + { + // 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.dAtAbRiCkS/wOrKsPaCeS/wOrKsPaCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} diff --git a/internal/services/databricks/sdk/2021-04-01-preview/privatelinkresources/method_get_autorest.go b/internal/services/databricks/sdk/2021-04-01-preview/privatelinkresources/method_get_autorest.go new file mode 100644 index 000000000000..85fc3cffa7a3 --- /dev/null +++ b/internal/services/databricks/sdk/2021-04-01-preview/privatelinkresources/method_get_autorest.go @@ -0,0 +1,64 @@ +package privatelinkresources + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +type GetResponse struct { + HttpResponse *http.Response + Model *GroupIdInformation +} + +// Get ... +func (c PrivateLinkResourcesClient) Get(ctx context.Context, id PrivateLinkResourceId) (result GetResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelinkresources.PrivateLinkResourcesClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelinkresources.PrivateLinkResourcesClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelinkresources.PrivateLinkResourcesClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c PrivateLinkResourcesClient) preparerForGet(ctx context.Context, id PrivateLinkResourceId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForGet handles the response to the Get request. The method always +// closes the http.Response Body. +func (c PrivateLinkResourcesClient) responderForGet(resp *http.Response) (result GetResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/internal/services/databricks/sdk/2021-04-01-preview/privatelinkresources/method_list_autorest.go b/internal/services/databricks/sdk/2021-04-01-preview/privatelinkresources/method_list_autorest.go new file mode 100644 index 000000000000..5bb350cb743f --- /dev/null +++ b/internal/services/databricks/sdk/2021-04-01-preview/privatelinkresources/method_list_autorest.go @@ -0,0 +1,183 @@ +package privatelinkresources + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +type ListResponse struct { + HttpResponse *http.Response + Model *[]GroupIdInformation + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListResponse, error) +} + +type ListCompleteResult struct { + Items []GroupIdInformation +} + +func (r ListResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListResponse) LoadMore(ctx context.Context) (resp ListResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// List ... +func (c PrivateLinkResourcesClient) List(ctx context.Context, id WorkspaceId) (resp ListResponse, err error) { + req, err := c.preparerForList(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelinkresources.PrivateLinkResourcesClient", "List", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelinkresources.PrivateLinkResourcesClient", "List", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForList(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelinkresources.PrivateLinkResourcesClient", "List", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// ListComplete retrieves all of the results into a single object +func (c PrivateLinkResourcesClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, GroupIdInformationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c PrivateLinkResourcesClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate GroupIdInformationPredicate) (resp ListCompleteResult, err error) { + items := make([]GroupIdInformation, 0) + + page, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListCompleteResult{ + Items: items, + } + return out, nil +} + +// preparerForList prepares the List request. +func (c PrivateLinkResourcesClient) preparerForList(ctx context.Context, id WorkspaceId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/privateLinkResources", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListWithNextLink prepares the List request with the given nextLink token. +func (c PrivateLinkResourcesClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForList handles the response to the List request. The method always +// closes the http.Response Body. +func (c PrivateLinkResourcesClient) responderForList(resp *http.Response) (result ListResponse, err error) { + type page struct { + Values []GroupIdInformation `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListResponse, err error) { + req, err := c.preparerForListWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelinkresources.PrivateLinkResourcesClient", "List", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelinkresources.PrivateLinkResourcesClient", "List", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelinkresources.PrivateLinkResourcesClient", "List", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} diff --git a/internal/services/databricks/sdk/2021-04-01-preview/privatelinkresources/model_groupidinformation.go b/internal/services/databricks/sdk/2021-04-01-preview/privatelinkresources/model_groupidinformation.go new file mode 100644 index 000000000000..89daef7c7be7 --- /dev/null +++ b/internal/services/databricks/sdk/2021-04-01-preview/privatelinkresources/model_groupidinformation.go @@ -0,0 +1,8 @@ +package privatelinkresources + +type GroupIdInformation struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties GroupIdInformationProperties `json:"properties"` + Type *string `json:"type,omitempty"` +} diff --git a/internal/services/databricks/sdk/2021-04-01-preview/privatelinkresources/model_groupidinformationproperties.go b/internal/services/databricks/sdk/2021-04-01-preview/privatelinkresources/model_groupidinformationproperties.go new file mode 100644 index 000000000000..e0c04b2fc608 --- /dev/null +++ b/internal/services/databricks/sdk/2021-04-01-preview/privatelinkresources/model_groupidinformationproperties.go @@ -0,0 +1,7 @@ +package privatelinkresources + +type GroupIdInformationProperties struct { + GroupId *string `json:"groupId,omitempty"` + RequiredMembers *[]string `json:"requiredMembers,omitempty"` + RequiredZoneNames *[]string `json:"requiredZoneNames,omitempty"` +} diff --git a/internal/services/databricks/sdk/2021-04-01-preview/privatelinkresources/predicates.go b/internal/services/databricks/sdk/2021-04-01-preview/privatelinkresources/predicates.go new file mode 100644 index 000000000000..e6b7f52e6fc0 --- /dev/null +++ b/internal/services/databricks/sdk/2021-04-01-preview/privatelinkresources/predicates.go @@ -0,0 +1,24 @@ +package privatelinkresources + +type GroupIdInformationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p GroupIdInformationPredicate) Matches(input GroupIdInformation) bool { + + if p.Id != nil && (input.Id == nil && *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil && *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil && *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/internal/services/databricks/sdk/2021-04-01-preview/privatelinkresources/version.go b/internal/services/databricks/sdk/2021-04-01-preview/privatelinkresources/version.go new file mode 100644 index 000000000000..8b95dfdb6be8 --- /dev/null +++ b/internal/services/databricks/sdk/2021-04-01-preview/privatelinkresources/version.go @@ -0,0 +1,9 @@ +package privatelinkresources + +import "fmt" + +const defaultApiVersion = "2021-04-01-preview" + +func userAgent() string { + return fmt.Sprintf("pandora/privatelinkresources/%s", defaultApiVersion) +} diff --git a/internal/services/databricks/sdk/2021-04-01-preview/put/constants.go b/internal/services/databricks/sdk/2021-04-01-preview/put/constants.go index b26a64181486..6c47ad4ca74f 100644 --- a/internal/services/databricks/sdk/2021-04-01-preview/put/constants.go +++ b/internal/services/databricks/sdk/2021-04-01-preview/put/constants.go @@ -1,5 +1,7 @@ package put +import "strings" + type PrivateEndpointConnectionProvisioningState string const ( @@ -10,6 +12,35 @@ const ( PrivateEndpointConnectionProvisioningStateUpdating PrivateEndpointConnectionProvisioningState = "Updating" ) +func PossibleValuesForPrivateEndpointConnectionProvisioningState() []string { + return []string{ + "Creating", + "Deleting", + "Failed", + "Succeeded", + "Updating", + } +} + +func parsePrivateEndpointConnectionProvisioningState(input string) (*PrivateEndpointConnectionProvisioningState, error) { + vals := map[string]PrivateEndpointConnectionProvisioningState{ + "creating": "Creating", + "deleting": "Deleting", + "failed": "Failed", + "succeeded": "Succeeded", + "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 := PrivateEndpointConnectionProvisioningState(v) + return &out, nil +} + type PrivateLinkServiceConnectionStatus string const ( @@ -18,3 +49,30 @@ const ( PrivateLinkServiceConnectionStatusPending PrivateLinkServiceConnectionStatus = "Pending" 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 +} diff --git a/internal/services/databricks/sdk/2021-04-01-preview/put/id_privateendpointconnection.go b/internal/services/databricks/sdk/2021-04-01-preview/put/id_privateendpointconnection.go index cbdf5f66f51a..dd865ea548e9 100644 --- a/internal/services/databricks/sdk/2021-04-01-preview/put/id_privateendpointconnection.go +++ b/internal/services/databricks/sdk/2021-04-01-preview/put/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 - WorkspaceName string - Name string + SubscriptionId string + ResourceGroupName string + WorkspaceName string + PrivateEndpointConnectionName string } -func NewPrivateEndpointConnectionID(subscriptionId, resourceGroup, workspaceName, name string) PrivateEndpointConnectionId { +// NewPrivateEndpointConnectionID returns a new PrivateEndpointConnectionId struct +func NewPrivateEndpointConnectionID(subscriptionId string, resourceGroupName string, workspaceName string, privateEndpointConnectionName string) PrivateEndpointConnectionId { return PrivateEndpointConnectionId{ - SubscriptionId: subscriptionId, - ResourceGroup: resourceGroup, - WorkspaceName: workspaceName, - Name: name, + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + PrivateEndpointConnectionName: privateEndpointConnectionName, } } -func (id PrivateEndpointConnectionId) String() string { - segments := []string{ - fmt.Sprintf("Name %q", id.Name), - fmt.Sprintf("Workspace Name %q", id.WorkspaceName), - fmt.Sprintf("Resource Group %q", id.ResourceGroup), - } - 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.Databricks/workspaces/%s/privateEndpointConnections/%s" - return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.WorkspaceName, 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.WorkspaceName, err = id.PopSegment("workspaces"); err != nil { - return nil, err - } - if resourceId.Name, err = id.PopSegment("privateEndpointConnections"); err != nil { - return nil, err + if id.WorkspaceName, ok = parsed.Parsed["workspaceName"]; !ok { + return nil, fmt.Errorf("the segment 'workspaceName' 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 'workspaces' segment - workspacesKey := "workspaces" - for key := range id.Path { - if strings.EqualFold(key, workspacesKey) { - workspacesKey = key - break - } + if id.WorkspaceName, ok = parsed.Parsed["workspaceName"]; !ok { + return nil, fmt.Errorf("the segment 'workspaceName' was not found in the resource id %q", input) } - if resourceId.WorkspaceName, err = id.PopSegment(workspacesKey); 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.Databricks/workspaces/%s/privateEndpointConnections/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, 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("microsoftDatabricks", "Microsoft.Databricks", "Microsoft.Databricks"), + resourceids.StaticSegment("workspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + 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("Workspace Name: %q", id.WorkspaceName), + 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/databricks/sdk/2021-04-01-preview/put/id_privateendpointconnection_test.go b/internal/services/databricks/sdk/2021-04-01-preview/put/id_privateendpointconnection_test.go index 2a1ac675df57..fef4e94abf72 100644 --- a/internal/services/databricks/sdk/2021-04-01-preview/put/id_privateendpointconnection_test.go +++ b/internal/services/databricks/sdk/2021-04-01-preview/put/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}", "{workspaceName}", "{privateEndpointConnectionName}").ID() - expected := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Databricks/workspaces/{workspaceName}/privateEndpointConnections/{privateEndpointConnectionName}" +func TestNewPrivateEndpointConnectionID(t *testing.T) { + id := NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "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.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + 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", "workspaceValue", "privateEndpointConnectionValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces/workspaceValue/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 WorkspaceName - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Databricks/", + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", Error: true, }, - { - // missing value for WorkspaceName - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Databricks/workspaces/", + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks", Error: true, }, - { - // missing Name - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Databricks/workspaces/{workspaceName}/", + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces", Error: true, }, - { - // missing value for Name - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Databricks/workspaces/{workspaceName}/privateEndpointConnections/", + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces/workspaceValue/privateEndpointConnections", Error: true, }, - { - // valid - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Databricks/workspaces/{workspaceName}/privateEndpointConnections/{privateEndpointConnectionName}", + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces/workspaceValue/privateEndpointConnections/privateEndpointConnectionValue", Expected: &PrivateEndpointConnectionId{ - SubscriptionId: "{subscriptionId}", - ResourceGroup: "{resourceGroupName}", - WorkspaceName: "{workspaceName}", - Name: "{privateEndpointConnectionName}", + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + PrivateEndpointConnectionName: "privateEndpointConnectionValue", }, }, - { - // upper-cased - Input: "/SUBSCRIPTIONS/{SUBSCRIPTIONID}/RESOURCEGROUPS/{RESOURCEGROUPNAME}/PROVIDERS/MICROSOFT.DATABRICKS/WORKSPACES/{WORKSPACENAME}/PRIVATEENDPOINTCONNECTIONS/{PRIVATEENDPOINTCONNECTIONNAME}", + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces/workspaceValue/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.WorkspaceName != v.Expected.WorkspaceName { t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) } - 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 WorkspaceName - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Databricks/", + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", Error: true, }, - { - // missing value for WorkspaceName - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Databricks/workspaces/", + // 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.Databricks/workspaces/{workspaceName}/", + // 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.Databricks/workspaces/{workspaceName}/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.Databricks/workspaces/{workspaceName}/privateEndpointConnections/{privateEndpointConnectionName}", - Expected: &PrivateEndpointConnectionId{ - SubscriptionId: "{subscriptionId}", - ResourceGroup: "{resourceGroupName}", - WorkspaceName: "{workspaceName}", - 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.Databricks/workspaces/{workspaceName}/privateendpointconnections/{privateEndpointConnectionName}", - Expected: &PrivateEndpointConnectionId{ - SubscriptionId: "{subscriptionId}", - ResourceGroup: "{resourceGroupName}", - WorkspaceName: "{workspaceName}", - 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.Databricks", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAbRiCkS", + Error: true, }, - { - // upper-cased segment names - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Databricks/WORKSPACES/{workspaceName}/PRIVATEENDPOINTCONNECTIONS/{privateEndpointConnectionName}", + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAbRiCkS/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAbRiCkS/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces/workspaceValue/privateEndpointConnections", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAbRiCkS/wOrKsPaCeS/wOrKsPaCeVaLuE/pRiVaTeEnDpOiNtCoNnEcTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces/workspaceValue/privateEndpointConnections/privateEndpointConnectionValue", Expected: &PrivateEndpointConnectionId{ - SubscriptionId: "{subscriptionId}", - ResourceGroup: "{resourceGroupName}", - WorkspaceName: "{workspaceName}", - Name: "{privateEndpointConnectionName}", + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + PrivateEndpointConnectionName: "privateEndpointConnectionValue", }, }, - { - // mixed-cased segment names - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Databricks/WoRkSpAcEs/{workspaceName}/PrIvAtEeNdPoInTcOnNeCtIoNs/{privateEndpointConnectionName}", + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces/workspaceValue/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.dAtAbRiCkS/wOrKsPaCeS/wOrKsPaCeVaLuE/pRiVaTeEnDpOiNtCoNnEcTiOnS/pRiVaTeEnDpOiNtCoNnEcTiOnVaLuE", Expected: &PrivateEndpointConnectionId{ - SubscriptionId: "{subscriptionId}", - ResourceGroup: "{resourceGroupName}", - WorkspaceName: "{workspaceName}", - Name: "{privateEndpointConnectionName}", + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + 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.dAtAbRiCkS/wOrKsPaCeS/wOrKsPaCeVaLuE/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.WorkspaceName != v.Expected.WorkspaceName { t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) } - 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/databricks/sdk/2021-04-01-preview/vnetpeering/constants.go b/internal/services/databricks/sdk/2021-04-01-preview/vnetpeering/constants.go index a1fc3f6665db..6aeb853df6c8 100644 --- a/internal/services/databricks/sdk/2021-04-01-preview/vnetpeering/constants.go +++ b/internal/services/databricks/sdk/2021-04-01-preview/vnetpeering/constants.go @@ -1,5 +1,7 @@ package vnetpeering +import "strings" + type PeeringProvisioningState string const ( @@ -9,6 +11,33 @@ const ( PeeringProvisioningStateUpdating PeeringProvisioningState = "Updating" ) +func PossibleValuesForPeeringProvisioningState() []string { + return []string{ + "Deleting", + "Failed", + "Succeeded", + "Updating", + } +} + +func parsePeeringProvisioningState(input string) (*PeeringProvisioningState, error) { + vals := map[string]PeeringProvisioningState{ + "deleting": "Deleting", + "failed": "Failed", + "succeeded": "Succeeded", + "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 := PeeringProvisioningState(v) + return &out, nil +} + type PeeringState string const ( @@ -16,3 +45,28 @@ const ( PeeringStateDisconnected PeeringState = "Disconnected" PeeringStateInitiated PeeringState = "Initiated" ) + +func PossibleValuesForPeeringState() []string { + return []string{ + "Connected", + "Disconnected", + "Initiated", + } +} + +func parsePeeringState(input string) (*PeeringState, error) { + vals := map[string]PeeringState{ + "connected": "Connected", + "disconnected": "Disconnected", + "initiated": "Initiated", + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // it could be a new value - best effort convert this + v := input + + out := PeeringState(v) + return &out, nil +} diff --git a/internal/services/databricks/sdk/2021-04-01-preview/vnetpeering/id_virtualnetworkpeering.go b/internal/services/databricks/sdk/2021-04-01-preview/vnetpeering/id_virtualnetworkpeering.go index fc25b84aae70..0eac9e831595 100644 --- a/internal/services/databricks/sdk/2021-04-01-preview/vnetpeering/id_virtualnetworkpeering.go +++ b/internal/services/databricks/sdk/2021-04-01-preview/vnetpeering/id_virtualnetworkpeering.go @@ -7,120 +7,131 @@ import ( "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" ) +var _ resourceids.ResourceId = VirtualNetworkPeeringId{} + +// VirtualNetworkPeeringId is a struct representing the Resource ID for a Virtual Network Peering type VirtualNetworkPeeringId struct { - SubscriptionId string - ResourceGroup string - WorkspaceName string - Name string + SubscriptionId string + ResourceGroupName string + WorkspaceName string + PeeringName string } -func NewVirtualNetworkPeeringID(subscriptionId, resourceGroup, workspaceName, name string) VirtualNetworkPeeringId { +// NewVirtualNetworkPeeringID returns a new VirtualNetworkPeeringId struct +func NewVirtualNetworkPeeringID(subscriptionId string, resourceGroupName string, workspaceName string, peeringName string) VirtualNetworkPeeringId { return VirtualNetworkPeeringId{ - SubscriptionId: subscriptionId, - ResourceGroup: resourceGroup, - WorkspaceName: workspaceName, - Name: name, + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + PeeringName: peeringName, } } -func (id VirtualNetworkPeeringId) String() string { - segments := []string{ - fmt.Sprintf("Name %q", id.Name), - fmt.Sprintf("Workspace Name %q", id.WorkspaceName), - fmt.Sprintf("Resource Group %q", id.ResourceGroup), - } - segmentsStr := strings.Join(segments, " / ") - return fmt.Sprintf("%s: (%s)", "Virtual Network Peering", segmentsStr) -} - -func (id VirtualNetworkPeeringId) ID() string { - fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Databricks/workspaces/%s/virtualNetworkPeerings/%s" - return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.WorkspaceName, id.Name) -} - -// ParseVirtualNetworkPeeringID parses a VirtualNetworkPeering ID into an VirtualNetworkPeeringId struct +// ParseVirtualNetworkPeeringID parses 'input' into a VirtualNetworkPeeringId func ParseVirtualNetworkPeeringID(input string) (*VirtualNetworkPeeringId, error) { - id, err := resourceids.ParseAzureResourceID(input) + parser := resourceids.NewParserFromResourceIdType(VirtualNetworkPeeringId{}) + parsed, err := parser.Parse(input, false) if err != nil { - return nil, err + return nil, fmt.Errorf("parsing %q: %+v", input, err) } - resourceId := VirtualNetworkPeeringId{ - SubscriptionId: id.SubscriptionID, - ResourceGroup: id.ResourceGroup, - } + var ok bool + id := VirtualNetworkPeeringId{} - 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.WorkspaceName, err = id.PopSegment("workspaces"); err != nil { - return nil, err - } - if resourceId.Name, err = id.PopSegment("virtualNetworkPeerings"); err != nil { - return nil, err + if id.WorkspaceName, ok = parsed.Parsed["workspaceName"]; !ok { + return nil, fmt.Errorf("the segment 'workspaceName' was not found in the resource id %q", input) } - if err := id.ValidateNoEmptySegments(input); err != nil { - return nil, err + if id.PeeringName, ok = parsed.Parsed["peeringName"]; !ok { + return nil, fmt.Errorf("the segment 'peeringName' was not found in the resource id %q", input) } - return &resourceId, nil + return &id, nil } -// ParseVirtualNetworkPeeringIDInsensitively parses an VirtualNetworkPeering ID into an VirtualNetworkPeeringId struct, insensitively -// This should only be used to parse an ID for rewriting to a consistent casing, -// the ParseVirtualNetworkPeeringID method should be used instead for validation etc. +// ParseVirtualNetworkPeeringIDInsensitively parses 'input' case-insensitively into a VirtualNetworkPeeringId +// note: this method should only be used for API response data and not user input func ParseVirtualNetworkPeeringIDInsensitively(input string) (*VirtualNetworkPeeringId, error) { - id, err := resourceids.ParseAzureResourceID(input) + parser := resourceids.NewParserFromResourceIdType(VirtualNetworkPeeringId{}) + parsed, err := parser.Parse(input, true) if err != nil { - return nil, err + return nil, fmt.Errorf("parsing %q: %+v", input, err) } - resourceId := VirtualNetworkPeeringId{ - SubscriptionId: id.SubscriptionID, - ResourceGroup: id.ResourceGroup, - } + var ok bool + id := VirtualNetworkPeeringId{} - 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 'workspaces' segment - workspacesKey := "workspaces" - for key := range id.Path { - if strings.EqualFold(key, workspacesKey) { - workspacesKey = key - break - } + if id.WorkspaceName, ok = parsed.Parsed["workspaceName"]; !ok { + return nil, fmt.Errorf("the segment 'workspaceName' was not found in the resource id %q", input) } - if resourceId.WorkspaceName, err = id.PopSegment(workspacesKey); err != nil { - return nil, err + + if id.PeeringName, ok = parsed.Parsed["peeringName"]; !ok { + return nil, fmt.Errorf("the segment 'peeringName' was not found in the resource id %q", input) } - // find the correct casing for the 'virtualNetworkPeerings' segment - virtualNetworkPeeringsKey := "virtualNetworkPeerings" - for key := range id.Path { - if strings.EqualFold(key, virtualNetworkPeeringsKey) { - virtualNetworkPeeringsKey = key - break - } + return &id, nil +} + +// ValidateVirtualNetworkPeeringID checks that 'input' can be parsed as a Virtual Network Peering ID +func ValidateVirtualNetworkPeeringID(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(virtualNetworkPeeringsKey); err != nil { - return nil, err + + if _, err := ParseVirtualNetworkPeeringID(v); err != nil { + errors = append(errors, err) } - if err := id.ValidateNoEmptySegments(input); err != nil { - return nil, err + return +} + +// ID returns the formatted Virtual Network Peering ID +func (id VirtualNetworkPeeringId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Databricks/workspaces/%s/virtualNetworkPeerings/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.PeeringName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Virtual Network Peering ID +func (id VirtualNetworkPeeringId) 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("microsoftDatabricks", "Microsoft.Databricks", "Microsoft.Databricks"), + resourceids.StaticSegment("workspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("virtualNetworkPeerings", "virtualNetworkPeerings", "virtualNetworkPeerings"), + resourceids.UserSpecifiedSegment("peeringName", "peeringValue"), } +} - return &resourceId, nil +// String returns a human-readable description of this Virtual Network Peering ID +func (id VirtualNetworkPeeringId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Peering Name: %q", id.PeeringName), + } + return fmt.Sprintf("Virtual Network Peering (%s)", strings.Join(components, "\n")) } diff --git a/internal/services/databricks/sdk/2021-04-01-preview/vnetpeering/id_virtualnetworkpeering_test.go b/internal/services/databricks/sdk/2021-04-01-preview/vnetpeering/id_virtualnetworkpeering_test.go index f71ac57209ce..983cee3571e1 100644 --- a/internal/services/databricks/sdk/2021-04-01-preview/vnetpeering/id_virtualnetworkpeering_test.go +++ b/internal/services/databricks/sdk/2021-04-01-preview/vnetpeering/id_virtualnetworkpeering_test.go @@ -6,13 +6,33 @@ import ( "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" ) -var _ resourceids.Id = VirtualNetworkPeeringId{} +var _ resourceids.ResourceId = VirtualNetworkPeeringId{} -func TestVirtualNetworkPeeringIDFormatter(t *testing.T) { - actual := NewVirtualNetworkPeeringID("{subscriptionId}", "{resourceGroupName}", "{workspaceName}", "{peeringName}").ID() - expected := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Databricks/workspaces/{workspaceName}/virtualNetworkPeerings/{peeringName}" +func TestNewVirtualNetworkPeeringID(t *testing.T) { + id := NewVirtualNetworkPeeringID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "peeringValue") + + 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.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.PeeringName != "peeringValue" { + t.Fatalf("Expected %q but got %q for Segment 'PeeringName'", id.PeeringName, "peeringValue") + } +} + +func TestFormatVirtualNetworkPeeringID(t *testing.T) { + actual := NewVirtualNetworkPeeringID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "peeringValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces/workspaceValue/virtualNetworkPeerings/peeringValue" 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 TestParseVirtualNetworkPeeringID(t *testing.T) { Error bool Expected *VirtualNetworkPeeringId }{ - { - // 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 WorkspaceName - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Databricks/", + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", Error: true, }, - { - // missing value for WorkspaceName - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Databricks/workspaces/", + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks", Error: true, }, - { - // missing Name - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Databricks/workspaces/{workspaceName}/", + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces", Error: true, }, - { - // missing value for Name - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Databricks/workspaces/{workspaceName}/virtualNetworkPeerings/", + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces/workspaceValue/virtualNetworkPeerings", Error: true, }, - { - // valid - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Databricks/workspaces/{workspaceName}/virtualNetworkPeerings/{peeringName}", + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces/workspaceValue/virtualNetworkPeerings/peeringValue", Expected: &VirtualNetworkPeeringId{ - SubscriptionId: "{subscriptionId}", - ResourceGroup: "{resourceGroupName}", - WorkspaceName: "{workspaceName}", - Name: "{peeringName}", + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + PeeringName: "peeringValue", }, }, - { - // upper-cased - Input: "/SUBSCRIPTIONS/{SUBSCRIPTIONID}/RESOURCEGROUPS/{RESOURCEGROUPNAME}/PROVIDERS/MICROSOFT.DATABRICKS/WORKSPACES/{WORKSPACENAME}/VIRTUALNETWORKPEERINGS/{PEERINGNAME}", + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces/workspaceValue/virtualNetworkPeerings/peeringValue/extra", Error: true, }, } - for _, v := range testData { t.Logf("[DEBUG] Testing %q", v.Input) @@ -104,7 +117,7 @@ func TestParseVirtualNetworkPeeringID(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 TestParseVirtualNetworkPeeringID(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.WorkspaceName != v.Expected.WorkspaceName { t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) } - if actual.Name != v.Expected.Name { - t.Fatalf("Expected %q but got %q for Name", v.Expected.Name, actual.Name) + + if actual.PeeringName != v.Expected.PeeringName { + t.Fatalf("Expected %q but got %q for PeeringName", v.Expected.PeeringName, actual.PeeringName) } + } } @@ -131,106 +148,132 @@ func TestParseVirtualNetworkPeeringIDInsensitively(t *testing.T) { Error bool Expected *VirtualNetworkPeeringId }{ - { - // 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 WorkspaceName - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Databricks/", + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", Error: true, }, - { - // missing value for WorkspaceName - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Databricks/workspaces/", + // 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.Databricks/workspaces/{workspaceName}/", + // 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.Databricks/workspaces/{workspaceName}/virtualNetworkPeerings/", + // 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.Databricks/workspaces/{workspaceName}/virtualNetworkPeerings/{peeringName}", - Expected: &VirtualNetworkPeeringId{ - SubscriptionId: "{subscriptionId}", - ResourceGroup: "{resourceGroupName}", - WorkspaceName: "{workspaceName}", - Name: "{peeringName}", - }, + // 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.Databricks/workspaces/{workspaceName}/virtualnetworkpeerings/{peeringName}", - Expected: &VirtualNetworkPeeringId{ - SubscriptionId: "{subscriptionId}", - ResourceGroup: "{resourceGroupName}", - WorkspaceName: "{workspaceName}", - Name: "{peeringName}", - }, + // 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.Databricks", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAbRiCkS", + Error: true, }, - { - // upper-cased segment names - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Databricks/WORKSPACES/{workspaceName}/VIRTUALNETWORKPEERINGS/{peeringName}", + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAbRiCkS/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAbRiCkS/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces/workspaceValue/virtualNetworkPeerings", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAbRiCkS/wOrKsPaCeS/wOrKsPaCeVaLuE/vIrTuAlNeTwOrKpEeRiNgS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces/workspaceValue/virtualNetworkPeerings/peeringValue", Expected: &VirtualNetworkPeeringId{ - SubscriptionId: "{subscriptionId}", - ResourceGroup: "{resourceGroupName}", - WorkspaceName: "{workspaceName}", - Name: "{peeringName}", + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + PeeringName: "peeringValue", }, }, - { - // mixed-cased segment names - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Databricks/WoRkSpAcEs/{workspaceName}/ViRtUaLnEtWoRkPeErInGs/{peeringName}", + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces/workspaceValue/virtualNetworkPeerings/peeringValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAbRiCkS/wOrKsPaCeS/wOrKsPaCeVaLuE/vIrTuAlNeTwOrKpEeRiNgS/pEeRiNgVaLuE", Expected: &VirtualNetworkPeeringId{ - SubscriptionId: "{subscriptionId}", - ResourceGroup: "{resourceGroupName}", - WorkspaceName: "{workspaceName}", - Name: "{peeringName}", + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + PeeringName: "pEeRiNgVaLuE", }, }, + { + // 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.dAtAbRiCkS/wOrKsPaCeS/wOrKsPaCeVaLuE/vIrTuAlNeTwOrKpEeRiNgS/pEeRiNgVaLuE/extra", + Error: true, + }, } - for _, v := range testData { t.Logf("[DEBUG] Testing %q", v.Input) @@ -240,7 +283,7 @@ func TestParseVirtualNetworkPeeringIDInsensitively(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 TestParseVirtualNetworkPeeringIDInsensitively(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.WorkspaceName != v.Expected.WorkspaceName { t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) } - if actual.Name != v.Expected.Name { - t.Fatalf("Expected %q but got %q for Name", v.Expected.Name, actual.Name) + + if actual.PeeringName != v.Expected.PeeringName { + t.Fatalf("Expected %q but got %q for PeeringName", v.Expected.PeeringName, actual.PeeringName) } + } } diff --git a/internal/services/databricks/sdk/2021-04-01-preview/vnetpeering/id_workspace.go b/internal/services/databricks/sdk/2021-04-01-preview/vnetpeering/id_workspace.go index 80a70f6d7baa..a5e830b3e61e 100644 --- a/internal/services/databricks/sdk/2021-04-01-preview/vnetpeering/id_workspace.go +++ b/internal/services/databricks/sdk/2021-04-01-preview/vnetpeering/id_workspace.go @@ -7,102 +7,118 @@ import ( "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" ) +var _ resourceids.ResourceId = WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace type WorkspaceId struct { - SubscriptionId string - ResourceGroup string - Name string + SubscriptionId string + ResourceGroupName string + WorkspaceName string } -func NewWorkspaceID(subscriptionId, resourceGroup, name string) WorkspaceId { +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, workspaceName string) WorkspaceId { return WorkspaceId{ - SubscriptionId: subscriptionId, - ResourceGroup: resourceGroup, - Name: name, + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, } } -func (id WorkspaceId) String() string { - segments := []string{ - fmt.Sprintf("Name %q", id.Name), - fmt.Sprintf("Resource Group %q", id.ResourceGroup), - } - segmentsStr := strings.Join(segments, " / ") - return fmt.Sprintf("%s: (%s)", "Workspace", segmentsStr) -} - -func (id WorkspaceId) ID() string { - fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Databricks/workspaces/%s" - return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.Name) -} - -// ParseWorkspaceID parses a Workspace ID into an WorkspaceId struct +// ParseWorkspaceID parses 'input' into a WorkspaceId func ParseWorkspaceID(input string) (*WorkspaceId, error) { - id, err := resourceids.ParseAzureResourceID(input) + parser := resourceids.NewParserFromResourceIdType(WorkspaceId{}) + parsed, err := parser.Parse(input, false) if err != nil { - return nil, err - } - - resourceId := WorkspaceId{ - 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 := WorkspaceId{} - 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.Name, err = id.PopSegment("workspaces"); 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.WorkspaceName, ok = parsed.Parsed["workspaceName"]; !ok { + return nil, fmt.Errorf("the segment 'workspaceName' was not found in the resource id %q", input) } - return &resourceId, nil + return &id, nil } -// ParseWorkspaceIDInsensitively parses an Workspace ID into an WorkspaceId struct, insensitively -// This should only be used to parse an ID for rewriting to a consistent casing, -// the ParseWorkspaceID method should be used instead for validation etc. +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { - id, err := resourceids.ParseAzureResourceID(input) + parser := resourceids.NewParserFromResourceIdType(WorkspaceId{}) + parsed, err := parser.Parse(input, true) if err != nil { - return nil, err + return nil, fmt.Errorf("parsing %q: %+v", input, err) } - resourceId := WorkspaceId{ - SubscriptionId: id.SubscriptionID, - ResourceGroup: id.ResourceGroup, + var ok bool + id := WorkspaceId{} + + 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.WorkspaceName, ok = parsed.Parsed["workspaceName"]; !ok { + return nil, fmt.Errorf("the segment 'workspaceName' was not found in the resource id %q", input) } - // find the correct casing for the 'workspaces' segment - workspacesKey := "workspaces" - for key := range id.Path { - if strings.EqualFold(key, workspacesKey) { - workspacesKey = key - break - } + return &id, nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(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(workspacesKey); err != nil { - return nil, err + + if _, err := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) } - if err := id.ValidateNoEmptySegments(input); err != nil { - return nil, err + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Databricks/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) 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("microsoftDatabricks", "Microsoft.Databricks", "Microsoft.Databricks"), + resourceids.StaticSegment("workspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), } +} - return &resourceId, nil +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) } diff --git a/internal/services/databricks/sdk/2021-04-01-preview/vnetpeering/id_workspace_test.go b/internal/services/databricks/sdk/2021-04-01-preview/vnetpeering/id_workspace_test.go index 653657763efb..e736ac5d6a8b 100644 --- a/internal/services/databricks/sdk/2021-04-01-preview/vnetpeering/id_workspace_test.go +++ b/internal/services/databricks/sdk/2021-04-01-preview/vnetpeering/id_workspace_test.go @@ -6,13 +6,29 @@ import ( "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" ) -var _ resourceids.Id = WorkspaceId{} +var _ resourceids.ResourceId = WorkspaceId{} -func TestWorkspaceIDFormatter(t *testing.T) { - actual := NewWorkspaceID("{subscriptionId}", "{resourceGroupName}", "{workspaceName}").ID() - expected := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Databricks/workspaces/{workspaceName}" +func TestNewWorkspaceID(t *testing.T) { + id := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + + 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.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } +} + +func TestFormatWorkspaceID(t *testing.T) { + actual := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces/workspaceValue" 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 TestParseWorkspaceID(t *testing.T) { Error bool Expected *WorkspaceId }{ - { - // 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 Name - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Databricks/", + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", Error: true, }, - { - // missing value for Name - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Databricks/workspaces/", + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks", Error: true, }, - { - // valid - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Databricks/workspaces/{workspaceName}", + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces/workspaceValue", Expected: &WorkspaceId{ - SubscriptionId: "{subscriptionId}", - ResourceGroup: "{resourceGroupName}", - Name: "{workspaceName}", + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", }, }, - { - // upper-cased - Input: "/SUBSCRIPTIONS/{SUBSCRIPTIONID}/RESOURCEGROUPS/{RESOURCEGROUPNAME}/PROVIDERS/MICROSOFT.DATABRICKS/WORKSPACES/{WORKSPACENAME}", + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces/workspaceValue/extra", Error: true, }, } - for _, v := range testData { t.Logf("[DEBUG] Testing %q", v.Input) @@ -91,7 +102,7 @@ func TestParseWorkspaceID(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 TestParseWorkspaceID(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.Name != v.Expected.Name { - t.Fatalf("Expected %q but got %q for Name", v.Expected.Name, actual.Name) + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) } + } } @@ -115,90 +129,110 @@ func TestParseWorkspaceIDInsensitively(t *testing.T) { Error bool Expected *WorkspaceId }{ - { - // 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 Name - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Databricks/", + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", Error: true, }, - { - // missing value for Name - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Databricks/workspaces/", + // 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.Databricks/workspaces/{workspaceName}", - Expected: &WorkspaceId{ - SubscriptionId: "{subscriptionId}", - ResourceGroup: "{resourceGroupName}", - Name: "{workspaceName}", - }, + // 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.Databricks/workspaces/{workspaceName}", - Expected: &WorkspaceId{ - SubscriptionId: "{subscriptionId}", - ResourceGroup: "{resourceGroupName}", - Name: "{workspaceName}", - }, + // 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.Databricks", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAbRiCkS", + Error: true, }, - { - // upper-cased segment names - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Databricks/WORKSPACES/{workspaceName}", + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAbRiCkS/wOrKsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces/workspaceValue", Expected: &WorkspaceId{ - SubscriptionId: "{subscriptionId}", - ResourceGroup: "{resourceGroupName}", - Name: "{workspaceName}", + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", }, }, - { - // mixed-cased segment names - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Databricks/WoRkSpAcEs/{workspaceName}", + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces/workspaceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAbRiCkS/wOrKsPaCeS/wOrKsPaCeVaLuE", Expected: &WorkspaceId{ - SubscriptionId: "{subscriptionId}", - ResourceGroup: "{resourceGroupName}", - Name: "{workspaceName}", + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", }, }, + { + // 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.dAtAbRiCkS/wOrKsPaCeS/wOrKsPaCeVaLuE/extra", + Error: true, + }, } - for _, v := range testData { t.Logf("[DEBUG] Testing %q", v.Input) @@ -208,7 +242,7 @@ func TestParseWorkspaceIDInsensitively(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 TestParseWorkspaceIDInsensitively(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.Name != v.Expected.Name { - t.Fatalf("Expected %q but got %q for Name", v.Expected.Name, actual.Name) + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) } + } } diff --git a/internal/services/databricks/sdk/2021-04-01-preview/workspaces/constants.go b/internal/services/databricks/sdk/2021-04-01-preview/workspaces/constants.go index 06948ba728ce..d615baf6746f 100644 --- a/internal/services/databricks/sdk/2021-04-01-preview/workspaces/constants.go +++ b/internal/services/databricks/sdk/2021-04-01-preview/workspaces/constants.go @@ -1,5 +1,7 @@ package workspaces +import "strings" + type CreatedByType string const ( @@ -9,6 +11,33 @@ const ( CreatedByTypeUser CreatedByType = "User" ) +func PossibleValuesForCreatedByType() []string { + return []string{ + "Application", + "Key", + "ManagedIdentity", + "User", + } +} + +func parseCreatedByType(input string) (*CreatedByType, error) { + vals := map[string]CreatedByType{ + "application": "Application", + "key": "Key", + "managedidentity": "ManagedIdentity", + "user": "User", + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // it could be a new value - best effort convert this + v := input + + out := CreatedByType(v) + return &out, nil +} + type CustomParameterType string const ( @@ -17,12 +46,58 @@ const ( CustomParameterTypeString CustomParameterType = "String" ) +func PossibleValuesForCustomParameterType() []string { + return []string{ + "Bool", + "Object", + "String", + } +} + +func parseCustomParameterType(input string) (*CustomParameterType, error) { + vals := map[string]CustomParameterType{ + "bool": "Bool", + "object": "Object", + "string": "String", + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // it could be a new value - best effort convert this + v := input + + out := CustomParameterType(v) + return &out, nil +} + type EncryptionKeySource string const ( EncryptionKeySourceMicrosoftPointKeyvault EncryptionKeySource = "Microsoft.Keyvault" ) +func PossibleValuesForEncryptionKeySource() []string { + return []string{ + "Microsoft.Keyvault", + } +} + +func parseEncryptionKeySource(input string) (*EncryptionKeySource, error) { + vals := map[string]EncryptionKeySource{ + "microsoftpointkeyvault": "Microsoft.Keyvault", + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // it could be a new value - best effort convert this + v := input + + out := EncryptionKeySource(v) + return &out, nil +} + type KeySource string const ( @@ -30,6 +105,29 @@ const ( KeySourceMicrosoftPointKeyvault KeySource = "Microsoft.Keyvault" ) +func PossibleValuesForKeySource() []string { + return []string{ + "Default", + "Microsoft.Keyvault", + } +} + +func parseKeySource(input string) (*KeySource, error) { + vals := map[string]KeySource{ + "default": "Default", + "microsoftpointkeyvault": "Microsoft.Keyvault", + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // it could be a new value - best effort convert this + v := input + + out := KeySource(v) + return &out, nil +} + type PrivateEndpointConnectionProvisioningState string const ( @@ -40,6 +138,35 @@ const ( PrivateEndpointConnectionProvisioningStateUpdating PrivateEndpointConnectionProvisioningState = "Updating" ) +func PossibleValuesForPrivateEndpointConnectionProvisioningState() []string { + return []string{ + "Creating", + "Deleting", + "Failed", + "Succeeded", + "Updating", + } +} + +func parsePrivateEndpointConnectionProvisioningState(input string) (*PrivateEndpointConnectionProvisioningState, error) { + vals := map[string]PrivateEndpointConnectionProvisioningState{ + "creating": "Creating", + "deleting": "Deleting", + "failed": "Failed", + "succeeded": "Succeeded", + "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 := PrivateEndpointConnectionProvisioningState(v) + return &out, nil +} + type PrivateLinkServiceConnectionStatus string const ( @@ -49,6 +176,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 ( @@ -65,6 +219,47 @@ const ( ProvisioningStateUpdating ProvisioningState = "Updating" ) +func PossibleValuesForProvisioningState() []string { + return []string{ + "Accepted", + "Canceled", + "Created", + "Creating", + "Deleted", + "Deleting", + "Failed", + "Ready", + "Running", + "Succeeded", + "Updating", + } +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "accepted": "Accepted", + "canceled": "Canceled", + "created": "Created", + "creating": "Creating", + "deleted": "Deleted", + "deleting": "Deleting", + "failed": "Failed", + "ready": "Ready", + "running": "Running", + "succeeded": "Succeeded", + "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 PublicNetworkAccess string const ( @@ -72,6 +267,29 @@ const ( PublicNetworkAccessEnabled PublicNetworkAccess = "Enabled" ) +func PossibleValuesForPublicNetworkAccess() []string { + return []string{ + "Disabled", + "Enabled", + } +} + +func parsePublicNetworkAccess(input string) (*PublicNetworkAccess, error) { + vals := map[string]PublicNetworkAccess{ + "disabled": "Disabled", + "enabled": "Enabled", + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // it could be a new value - best effort convert this + v := input + + out := PublicNetworkAccess(v) + return &out, nil +} + type RequiredNsgRules string const ( @@ -79,3 +297,28 @@ const ( RequiredNsgRulesNoAzureDatabricksRules RequiredNsgRules = "NoAzureDatabricksRules" RequiredNsgRulesNoAzureServiceRules RequiredNsgRules = "NoAzureServiceRules" ) + +func PossibleValuesForRequiredNsgRules() []string { + return []string{ + "AllRules", + "NoAzureDatabricksRules", + "NoAzureServiceRules", + } +} + +func parseRequiredNsgRules(input string) (*RequiredNsgRules, error) { + vals := map[string]RequiredNsgRules{ + "allrules": "AllRules", + "noazuredatabricksrules": "NoAzureDatabricksRules", + "noazureservicerules": "NoAzureServiceRules", + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // it could be a new value - best effort convert this + v := input + + out := RequiredNsgRules(v) + return &out, nil +} diff --git a/internal/services/databricks/sdk/2021-04-01-preview/workspaces/id_resourcegroup.go b/internal/services/databricks/sdk/2021-04-01-preview/workspaces/id_resourcegroup.go index c18545606c88..7fc48051bf51 100644 --- a/internal/services/databricks/sdk/2021-04-01-preview/workspaces/id_resourcegroup.go +++ b/internal/services/databricks/sdk/2021-04-01-preview/workspaces/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/databricks/sdk/2021-04-01-preview/workspaces/id_resourcegroup_test.go b/internal/services/databricks/sdk/2021-04-01-preview/workspaces/id_resourcegroup_test.go index 23a5f67a7d9b..3aadceae80f1 100644 --- a/internal/services/databricks/sdk/2021-04-01-preview/workspaces/id_resourcegroup_test.go +++ b/internal/services/databricks/sdk/2021-04-01-preview/workspaces/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/databricks/sdk/2021-04-01-preview/workspaces/id_subscription.go b/internal/services/databricks/sdk/2021-04-01-preview/workspaces/id_subscription.go index 809dbcfbb739..79a3c1c21b29 100644 --- a/internal/services/databricks/sdk/2021-04-01-preview/workspaces/id_subscription.go +++ b/internal/services/databricks/sdk/2021-04-01-preview/workspaces/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/databricks/sdk/2021-04-01-preview/workspaces/id_subscription_test.go b/internal/services/databricks/sdk/2021-04-01-preview/workspaces/id_subscription_test.go index ba3fb4fba30d..50ca833bffba 100644 --- a/internal/services/databricks/sdk/2021-04-01-preview/workspaces/id_subscription_test.go +++ b/internal/services/databricks/sdk/2021-04-01-preview/workspaces/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/databricks/sdk/2021-04-01-preview/workspaces/id_workspace.go b/internal/services/databricks/sdk/2021-04-01-preview/workspaces/id_workspace.go index fe25582ecf5c..94fb99b0a418 100644 --- a/internal/services/databricks/sdk/2021-04-01-preview/workspaces/id_workspace.go +++ b/internal/services/databricks/sdk/2021-04-01-preview/workspaces/id_workspace.go @@ -7,102 +7,118 @@ import ( "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" ) +var _ resourceids.ResourceId = WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace type WorkspaceId struct { - SubscriptionId string - ResourceGroup string - Name string + SubscriptionId string + ResourceGroupName string + WorkspaceName string } -func NewWorkspaceID(subscriptionId, resourceGroup, name string) WorkspaceId { +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, workspaceName string) WorkspaceId { return WorkspaceId{ - SubscriptionId: subscriptionId, - ResourceGroup: resourceGroup, - Name: name, + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, } } -func (id WorkspaceId) String() string { - segments := []string{ - fmt.Sprintf("Name %q", id.Name), - fmt.Sprintf("Resource Group %q", id.ResourceGroup), - } - segmentsStr := strings.Join(segments, " / ") - return fmt.Sprintf("%s: (%s)", "Workspace", segmentsStr) -} - -func (id WorkspaceId) ID() string { - fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Databricks/workspaces/%s" - return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.Name) -} - -// ParseWorkspaceID parses a Workspace ID into an WorkspaceId struct +// ParseWorkspaceID parses 'input' into a WorkspaceId func ParseWorkspaceID(input string) (*WorkspaceId, error) { - id, err := resourceids.ParseAzureResourceID(input) + parser := resourceids.NewParserFromResourceIdType(WorkspaceId{}) + parsed, err := parser.Parse(input, false) if err != nil { - return nil, err - } - - resourceId := WorkspaceId{ - 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 := WorkspaceId{} - 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.Name, err = id.PopSegment("workspaces"); 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.WorkspaceName, ok = parsed.Parsed["workspaceName"]; !ok { + return nil, fmt.Errorf("the segment 'workspaceName' was not found in the resource id %q", input) } - return &resourceId, nil + return &id, nil } -// ParseWorkspaceIDInsensitively parses an Workspace ID into an WorkspaceId struct, insensitively -// This should only be used to parse an ID for rewriting to a consistent casing, -// the ParseWorkspaceID method should be used instead for validation etc. +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { - id, err := resourceids.ParseAzureResourceID(input) + parser := resourceids.NewParserFromResourceIdType(WorkspaceId{}) + parsed, err := parser.Parse(input, true) if err != nil { - return nil, err + return nil, fmt.Errorf("parsing %q: %+v", input, err) } - resourceId := WorkspaceId{ - SubscriptionId: id.SubscriptionID, - ResourceGroup: id.ResourceGroup, + var ok bool + id := WorkspaceId{} + + 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.WorkspaceName, ok = parsed.Parsed["workspaceName"]; !ok { + return nil, fmt.Errorf("the segment 'workspaceName' was not found in the resource id %q", input) } - // find the correct casing for the 'workspaces' segment - workspacesKey := "workspaces" - for key := range id.Path { - if strings.EqualFold(key, workspacesKey) { - workspacesKey = key - break - } + return &id, nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(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(workspacesKey); err != nil { - return nil, err + + if _, err := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) } - if err := id.ValidateNoEmptySegments(input); err != nil { - return nil, err + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Databricks/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) 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("microsoftDatabricks", "Microsoft.Databricks", "Microsoft.Databricks"), + resourceids.StaticSegment("workspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), } +} - return &resourceId, nil +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) } diff --git a/internal/services/databricks/sdk/2021-04-01-preview/workspaces/id_workspace_test.go b/internal/services/databricks/sdk/2021-04-01-preview/workspaces/id_workspace_test.go index 5b9fc0d0f7a2..23828d2b1bce 100644 --- a/internal/services/databricks/sdk/2021-04-01-preview/workspaces/id_workspace_test.go +++ b/internal/services/databricks/sdk/2021-04-01-preview/workspaces/id_workspace_test.go @@ -6,13 +6,29 @@ import ( "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" ) -var _ resourceids.Id = WorkspaceId{} +var _ resourceids.ResourceId = WorkspaceId{} -func TestWorkspaceIDFormatter(t *testing.T) { - actual := NewWorkspaceID("{subscriptionId}", "{resourceGroupName}", "{workspaceName}").ID() - expected := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Databricks/workspaces/{workspaceName}" +func TestNewWorkspaceID(t *testing.T) { + id := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + + 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.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } +} + +func TestFormatWorkspaceID(t *testing.T) { + actual := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces/workspaceValue" 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 TestParseWorkspaceID(t *testing.T) { Error bool Expected *WorkspaceId }{ - { - // 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 Name - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Databricks/", + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", Error: true, }, - { - // missing value for Name - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Databricks/workspaces/", + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks", Error: true, }, - { - // valid - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Databricks/workspaces/{workspaceName}", + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces/workspaceValue", Expected: &WorkspaceId{ - SubscriptionId: "{subscriptionId}", - ResourceGroup: "{resourceGroupName}", - Name: "{workspaceName}", + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", }, }, - { - // upper-cased - Input: "/SUBSCRIPTIONS/{SUBSCRIPTIONID}/RESOURCEGROUPS/{RESOURCEGROUPNAME}/PROVIDERS/MICROSOFT.DATABRICKS/WORKSPACES/{WORKSPACENAME}", + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces/workspaceValue/extra", Error: true, }, } - for _, v := range testData { t.Logf("[DEBUG] Testing %q", v.Input) @@ -91,7 +102,7 @@ func TestParseWorkspaceID(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 TestParseWorkspaceID(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.Name != v.Expected.Name { - t.Fatalf("Expected %q but got %q for Name", v.Expected.Name, actual.Name) + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) } + } } @@ -115,90 +129,110 @@ func TestParseWorkspaceIDInsensitively(t *testing.T) { Error bool Expected *WorkspaceId }{ - { - // 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 Name - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Databricks/", + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", Error: true, }, - { - // missing value for Name - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Databricks/workspaces/", + // 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.Databricks/workspaces/{workspaceName}", - Expected: &WorkspaceId{ - SubscriptionId: "{subscriptionId}", - ResourceGroup: "{resourceGroupName}", - Name: "{workspaceName}", - }, + // 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.Databricks/workspaces/{workspaceName}", - Expected: &WorkspaceId{ - SubscriptionId: "{subscriptionId}", - ResourceGroup: "{resourceGroupName}", - Name: "{workspaceName}", - }, + // 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.Databricks", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAbRiCkS", + Error: true, }, - { - // upper-cased segment names - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Databricks/WORKSPACES/{workspaceName}", + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAbRiCkS/wOrKsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces/workspaceValue", Expected: &WorkspaceId{ - SubscriptionId: "{subscriptionId}", - ResourceGroup: "{resourceGroupName}", - Name: "{workspaceName}", + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", }, }, - { - // mixed-cased segment names - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Databricks/WoRkSpAcEs/{workspaceName}", + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Databricks/workspaces/workspaceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAbRiCkS/wOrKsPaCeS/wOrKsPaCeVaLuE", Expected: &WorkspaceId{ - SubscriptionId: "{subscriptionId}", - ResourceGroup: "{resourceGroupName}", - Name: "{workspaceName}", + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", }, }, + { + // 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.dAtAbRiCkS/wOrKsPaCeS/wOrKsPaCeVaLuE/extra", + Error: true, + }, } - for _, v := range testData { t.Logf("[DEBUG] Testing %q", v.Input) @@ -208,7 +242,7 @@ func TestParseWorkspaceIDInsensitively(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 TestParseWorkspaceIDInsensitively(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.Name != v.Expected.Name { - t.Fatalf("Expected %q but got %q for Name", v.Expected.Name, actual.Name) + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) } + } } diff --git a/internal/services/databricks/sdk/2021-04-01-preview/workspaces/model_systemdata.go b/internal/services/databricks/sdk/2021-04-01-preview/workspaces/model_systemdata.go index c7da0009ca71..abdcca8a66b1 100644 --- a/internal/services/databricks/sdk/2021-04-01-preview/workspaces/model_systemdata.go +++ b/internal/services/databricks/sdk/2021-04-01-preview/workspaces/model_systemdata.go @@ -1,11 +1,5 @@ package workspaces -import ( - "time" - - "github.com/hashicorp/go-azure-helpers/lang/dates" -) - type SystemData struct { CreatedAt *string `json:"createdAt,omitempty"` CreatedBy *string `json:"createdBy,omitempty"` @@ -14,27 +8,3 @@ type SystemData struct { LastModifiedBy *string `json:"lastModifiedBy,omitempty"` LastModifiedByType *CreatedByType `json:"lastModifiedByType,omitempty"` } - -func (o SystemData) GetCreatedAtAsTime() (*time.Time, error) { - if o.CreatedAt == nil { - return nil, nil - } - return dates.ParseAsFormat(o.CreatedAt, "2006-01-02T15:04:05Z07:00") -} - -func (o SystemData) SetCreatedAtAsTime(input time.Time) { - formatted := input.Format("2006-01-02T15:04:05Z07:00") - o.CreatedAt = &formatted -} - -func (o SystemData) GetLastModifiedAtAsTime() (*time.Time, error) { - if o.LastModifiedAt == nil { - return nil, nil - } - return dates.ParseAsFormat(o.LastModifiedAt, "2006-01-02T15:04:05Z07:00") -} - -func (o SystemData) SetLastModifiedAtAsTime(input time.Time) { - formatted := input.Format("2006-01-02T15:04:05Z07:00") - o.LastModifiedAt = &formatted -} diff --git a/internal/services/databricks/sdk/2021-04-01-preview/workspaces/model_workspaceproperties.go b/internal/services/databricks/sdk/2021-04-01-preview/workspaces/model_workspaceproperties.go index 34a8dd6b8ba6..9f8012789abe 100644 --- a/internal/services/databricks/sdk/2021-04-01-preview/workspaces/model_workspaceproperties.go +++ b/internal/services/databricks/sdk/2021-04-01-preview/workspaces/model_workspaceproperties.go @@ -1,11 +1,5 @@ package workspaces -import ( - "time" - - "github.com/hashicorp/go-azure-helpers/lang/dates" -) - type WorkspaceProperties struct { Authorizations *[]WorkspaceProviderAuthorization `json:"authorizations,omitempty"` CreatedBy *CreatedBy `json:"createdBy,omitempty"` @@ -23,15 +17,3 @@ type WorkspaceProperties struct { WorkspaceId *string `json:"workspaceId,omitempty"` WorkspaceUrl *string `json:"workspaceUrl,omitempty"` } - -func (o WorkspaceProperties) GetCreatedDateTimeAsTime() (*time.Time, error) { - if o.CreatedDateTime == nil { - return nil, nil - } - return dates.ParseAsFormat(o.CreatedDateTime, "2006-01-02T15:04:05Z07:00") -} - -func (o WorkspaceProperties) SetCreatedDateTimeAsTime(input time.Time) { - formatted := input.Format("2006-01-02T15:04:05Z07:00") - o.CreatedDateTime = &formatted -}