diff --git a/internal/services/powerbi/powerbi_embedded_resource.go b/internal/services/powerbi/powerbi_embedded_resource.go index 3fde3b313e21..8ce78b40541b 100644 --- a/internal/services/powerbi/powerbi_embedded_resource.go +++ b/internal/services/powerbi/powerbi_embedded_resource.go @@ -150,8 +150,8 @@ func resourcePowerBIEmbeddedRead(d *pluginsdk.ResourceData, meta interface{}) er return fmt.Errorf("retrieving %s: %+v", *id, err) } - d.Set("name", id.CapacityName) - d.Set("resource_group_name", id.ResourceGroup) + d.Set("name", id.DedicatedCapacityName) + d.Set("resource_group_name", id.ResourceGroupName) if model := resp.Model; model != nil { d.Set("location", location.Normalize(model.Location)) diff --git a/internal/services/powerbi/sdk/2021-01-01/autoscalevcores/client.go b/internal/services/powerbi/sdk/2021-01-01/autoscalevcores/client.go new file mode 100644 index 000000000000..a7625c7b9ece --- /dev/null +++ b/internal/services/powerbi/sdk/2021-01-01/autoscalevcores/client.go @@ -0,0 +1,15 @@ +package autoscalevcores + +import "github.com/Azure/go-autorest/autorest" + +type AutoScaleVCoresClient struct { + Client autorest.Client + baseUri string +} + +func NewAutoScaleVCoresClientWithBaseURI(endpoint string) AutoScaleVCoresClient { + return AutoScaleVCoresClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/internal/services/powerbi/sdk/2021-01-01/autoscalevcores/constants.go b/internal/services/powerbi/sdk/2021-01-01/autoscalevcores/constants.go new file mode 100644 index 000000000000..827f158a5089 --- /dev/null +++ b/internal/services/powerbi/sdk/2021-01-01/autoscalevcores/constants.go @@ -0,0 +1,87 @@ +package autoscalevcores + +import "strings" + +type IdentityType string + +const ( + IdentityTypeApplication IdentityType = "Application" + IdentityTypeKey IdentityType = "Key" + IdentityTypeManagedIdentity IdentityType = "ManagedIdentity" + IdentityTypeUser IdentityType = "User" +) + +func PossibleValuesForIdentityType() []string { + return []string{ + string(IdentityTypeApplication), + string(IdentityTypeKey), + string(IdentityTypeManagedIdentity), + string(IdentityTypeUser), + } +} + +func parseIdentityType(input string) (*IdentityType, error) { + vals := map[string]IdentityType{ + "application": IdentityTypeApplication, + "key": IdentityTypeKey, + "managedidentity": IdentityTypeManagedIdentity, + "user": IdentityTypeUser, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := IdentityType(input) + return &out, nil +} + +type VCoreProvisioningState string + +const ( + VCoreProvisioningStateSucceeded VCoreProvisioningState = "Succeeded" +) + +func PossibleValuesForVCoreProvisioningState() []string { + return []string{ + string(VCoreProvisioningStateSucceeded), + } +} + +func parseVCoreProvisioningState(input string) (*VCoreProvisioningState, error) { + vals := map[string]VCoreProvisioningState{ + "succeeded": VCoreProvisioningStateSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := VCoreProvisioningState(input) + return &out, nil +} + +type VCoreSkuTier string + +const ( + VCoreSkuTierAutoScale VCoreSkuTier = "AutoScale" +) + +func PossibleValuesForVCoreSkuTier() []string { + return []string{ + string(VCoreSkuTierAutoScale), + } +} + +func parseVCoreSkuTier(input string) (*VCoreSkuTier, error) { + vals := map[string]VCoreSkuTier{ + "autoscale": VCoreSkuTierAutoScale, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := VCoreSkuTier(input) + return &out, nil +} diff --git a/internal/services/powerbi/sdk/2021-01-01/autoscalevcores/id_autoscalevcore.go b/internal/services/powerbi/sdk/2021-01-01/autoscalevcores/id_autoscalevcore.go new file mode 100644 index 000000000000..2ac6b000cee0 --- /dev/null +++ b/internal/services/powerbi/sdk/2021-01-01/autoscalevcores/id_autoscalevcore.go @@ -0,0 +1,124 @@ +package autoscalevcores + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = AutoScaleVCoreId{} + +// AutoScaleVCoreId is a struct representing the Resource ID for a Auto Scale V Core +type AutoScaleVCoreId struct { + SubscriptionId string + ResourceGroupName string + VcoreName string +} + +// NewAutoScaleVCoreID returns a new AutoScaleVCoreId struct +func NewAutoScaleVCoreID(subscriptionId string, resourceGroupName string, vcoreName string) AutoScaleVCoreId { + return AutoScaleVCoreId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VcoreName: vcoreName, + } +} + +// ParseAutoScaleVCoreID parses 'input' into a AutoScaleVCoreId +func ParseAutoScaleVCoreID(input string) (*AutoScaleVCoreId, error) { + parser := resourceids.NewParserFromResourceIdType(AutoScaleVCoreId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := AutoScaleVCoreId{} + + 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.VcoreName, ok = parsed.Parsed["vcoreName"]; !ok { + return nil, fmt.Errorf("the segment 'vcoreName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseAutoScaleVCoreIDInsensitively parses 'input' case-insensitively into a AutoScaleVCoreId +// note: this method should only be used for API response data and not user input +func ParseAutoScaleVCoreIDInsensitively(input string) (*AutoScaleVCoreId, error) { + parser := resourceids.NewParserFromResourceIdType(AutoScaleVCoreId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := AutoScaleVCoreId{} + + 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.VcoreName, ok = parsed.Parsed["vcoreName"]; !ok { + return nil, fmt.Errorf("the segment 'vcoreName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateAutoScaleVCoreID checks that 'input' can be parsed as a Auto Scale V Core ID +func ValidateAutoScaleVCoreID(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 := ParseAutoScaleVCoreID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Auto Scale V Core ID +func (id AutoScaleVCoreId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.PowerBIDedicated/autoScaleVCores/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VcoreName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Auto Scale V Core ID +func (id AutoScaleVCoreId) 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("microsoftPowerBIDedicated", "Microsoft.PowerBIDedicated", "Microsoft.PowerBIDedicated"), + resourceids.StaticSegment("autoScaleVCores", "autoScaleVCores", "autoScaleVCores"), + resourceids.UserSpecifiedSegment("vcoreName", "vcoreValue"), + } +} + +// String returns a human-readable description of this Auto Scale V Core ID +func (id AutoScaleVCoreId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vcore Name: %q", id.VcoreName), + } + return fmt.Sprintf("Auto Scale V Core (%s)", strings.Join(components, "\n")) +} diff --git a/internal/services/powerbi/sdk/2021-01-01/autoscalevcores/id_autoscalevcore_test.go b/internal/services/powerbi/sdk/2021-01-01/autoscalevcores/id_autoscalevcore_test.go new file mode 100644 index 000000000000..4abe6424836a --- /dev/null +++ b/internal/services/powerbi/sdk/2021-01-01/autoscalevcores/id_autoscalevcore_test.go @@ -0,0 +1,264 @@ +package autoscalevcores + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = AutoScaleVCoreId{} + +func TestNewAutoScaleVCoreID(t *testing.T) { + id := NewAutoScaleVCoreID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vcoreValue") + + 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.VcoreName != "vcoreValue" { + t.Fatalf("Expected %q but got %q for Segment 'VcoreName'", id.VcoreName, "vcoreValue") + } +} + +func TestFormatAutoScaleVCoreID(t *testing.T) { + actual := NewAutoScaleVCoreID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vcoreValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.PowerBIDedicated/autoScaleVCores/vcoreValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", actual, expected) + } +} + +func TestParseAutoScaleVCoreID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AutoScaleVCoreId + }{ + { + // 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.PowerBIDedicated", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.PowerBIDedicated/autoScaleVCores", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.PowerBIDedicated/autoScaleVCores/vcoreValue", + Expected: &AutoScaleVCoreId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VcoreName: "vcoreValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.PowerBIDedicated/autoScaleVCores/vcoreValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAutoScaleVCoreID(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.VcoreName != v.Expected.VcoreName { + t.Fatalf("Expected %q but got %q for VcoreName", v.Expected.VcoreName, actual.VcoreName) + } + + } +} + +func TestParseAutoScaleVCoreIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AutoScaleVCoreId + }{ + { + // 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.PowerBIDedicated", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.pOwErBiDeDiCaTeD", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.PowerBIDedicated/autoScaleVCores", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.pOwErBiDeDiCaTeD/aUtOsCaLeVcOrEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.PowerBIDedicated/autoScaleVCores/vcoreValue", + Expected: &AutoScaleVCoreId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VcoreName: "vcoreValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.PowerBIDedicated/autoScaleVCores/vcoreValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.pOwErBiDeDiCaTeD/aUtOsCaLeVcOrEs/vCoReVaLuE", + Expected: &AutoScaleVCoreId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VcoreName: "vCoReVaLuE", + }, + }, + { + // 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.pOwErBiDeDiCaTeD/aUtOsCaLeVcOrEs/vCoReVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAutoScaleVCoreIDInsensitively(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.VcoreName != v.Expected.VcoreName { + t.Fatalf("Expected %q but got %q for VcoreName", v.Expected.VcoreName, actual.VcoreName) + } + + } +} diff --git a/internal/services/powerbi/sdk/2021-01-01/autoscalevcores/id_resourcegroup.go b/internal/services/powerbi/sdk/2021-01-01/autoscalevcores/id_resourcegroup.go new file mode 100644 index 000000000000..8e1b3ed8d1ce --- /dev/null +++ b/internal/services/powerbi/sdk/2021-01-01/autoscalevcores/id_resourcegroup.go @@ -0,0 +1,109 @@ +package autoscalevcores + +import ( + "fmt" + "strings" + + "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 + ResourceGroupName string +} + +// NewResourceGroupID returns a new ResourceGroupId struct +func NewResourceGroupID(subscriptionId string, resourceGroupName string) ResourceGroupId { + return ResourceGroupId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + } +} + +// ParseResourceGroupID parses 'input' into a ResourceGroupId +func ParseResourceGroupID(input string) (*ResourceGroupId, error) { + parser := resourceids.NewParserFromResourceIdType(ResourceGroupId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + 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) + } + + 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 &id, nil +} + +// 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) { + parser := resourceids.NewParserFromResourceIdType(ResourceGroupId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + 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) + } + + 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 &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 _, err := ParseResourceGroupID(v); err != nil { + errors = append(errors, 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"), + } +} + +// 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/powerbi/sdk/2021-01-01/autoscalevcores/id_resourcegroup_test.go b/internal/services/powerbi/sdk/2021-01-01/autoscalevcores/id_resourcegroup_test.go new file mode 100644 index 000000000000..6f734268c646 --- /dev/null +++ b/internal/services/powerbi/sdk/2021-01-01/autoscalevcores/id_resourcegroup_test.go @@ -0,0 +1,189 @@ +package autoscalevcores + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = ResourceGroupId{} + +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 the Formatted ID to be %q but got %q", actual, expected) + } +} + +func TestParseResourceGroupID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ResourceGroupId + }{ + { + // 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, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Expected: &ResourceGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + }, + }, + { + // 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) + + actual, err := ParseResourceGroupID(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) + } + + } +} + +func TestParseResourceGroupIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ResourceGroupId + }{ + { + // 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, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Expected: &ResourceGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + }, + }, + { + // 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: "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) + + actual, err := ParseResourceGroupIDInsensitively(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) + } + + } +} diff --git a/internal/services/powerbi/sdk/2021-01-01/autoscalevcores/id_subscription.go b/internal/services/powerbi/sdk/2021-01-01/autoscalevcores/id_subscription.go new file mode 100644 index 000000000000..740d99f27486 --- /dev/null +++ b/internal/services/powerbi/sdk/2021-01-01/autoscalevcores/id_subscription.go @@ -0,0 +1,96 @@ +package autoscalevcores + +import ( + "fmt" + "strings" + + "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, + } +} + +// ParseSubscriptionID parses 'input' into a SubscriptionId +func ParseSubscriptionID(input string) (*SubscriptionId, error) { + parser := resourceids.NewParserFromResourceIdType(SubscriptionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + 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) + } + + return &id, nil +} + +// 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) { + parser := resourceids.NewParserFromResourceIdType(SubscriptionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + 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) + } + + 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 := ParseSubscriptionID(v); err != nil { + errors = append(errors, err) + } + + 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/powerbi/sdk/2021-01-01/autoscalevcores/id_subscription_test.go b/internal/services/powerbi/sdk/2021-01-01/autoscalevcores/id_subscription_test.go new file mode 100644 index 000000000000..16385280abf9 --- /dev/null +++ b/internal/services/powerbi/sdk/2021-01-01/autoscalevcores/id_subscription_test.go @@ -0,0 +1,144 @@ +package autoscalevcores + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = 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 the Formatted ID to be %q but got %q", actual, expected) + } +} + +func TestParseSubscriptionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SubscriptionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Expected: &SubscriptionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + }, + }, + { + // 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) + + actual, err := ParseSubscriptionID(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) + } + + } +} + +func TestParseSubscriptionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SubscriptionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Expected: &SubscriptionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Expected: &SubscriptionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + }, + }, + { + // 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) + + actual, err := ParseSubscriptionIDInsensitively(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) + } + + } +} diff --git a/internal/services/powerbi/sdk/2021-01-01/autoscalevcores/method_create_autorest.go b/internal/services/powerbi/sdk/2021-01-01/autoscalevcores/method_create_autorest.go new file mode 100644 index 000000000000..372c0a5d2f76 --- /dev/null +++ b/internal/services/powerbi/sdk/2021-01-01/autoscalevcores/method_create_autorest.go @@ -0,0 +1,65 @@ +package autoscalevcores + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +type CreateResponse struct { + HttpResponse *http.Response + Model *AutoScaleVCore +} + +// Create ... +func (c AutoScaleVCoresClient) Create(ctx context.Context, id AutoScaleVCoreId, input AutoScaleVCore) (result CreateResponse, err error) { + req, err := c.preparerForCreate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "autoscalevcores.AutoScaleVCoresClient", "Create", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "autoscalevcores.AutoScaleVCoresClient", "Create", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForCreate(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "autoscalevcores.AutoScaleVCoresClient", "Create", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForCreate prepares the Create request. +func (c AutoScaleVCoresClient) preparerForCreate(ctx context.Context, id AutoScaleVCoreId, input AutoScaleVCore) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForCreate handles the response to the Create request. The method always +// closes the http.Response Body. +func (c AutoScaleVCoresClient) responderForCreate(resp *http.Response) (result CreateResponse, 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/powerbi/sdk/2021-01-01/autoscalevcores/method_delete_autorest.go b/internal/services/powerbi/sdk/2021-01-01/autoscalevcores/method_delete_autorest.go new file mode 100644 index 000000000000..8bf6c4cdb9a5 --- /dev/null +++ b/internal/services/powerbi/sdk/2021-01-01/autoscalevcores/method_delete_autorest.go @@ -0,0 +1,61 @@ +package autoscalevcores + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +type DeleteResponse struct { + HttpResponse *http.Response +} + +// Delete ... +func (c AutoScaleVCoresClient) Delete(ctx context.Context, id AutoScaleVCoreId) (result DeleteResponse, err error) { + req, err := c.preparerForDelete(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "autoscalevcores.AutoScaleVCoresClient", "Delete", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "autoscalevcores.AutoScaleVCoresClient", "Delete", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForDelete(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "autoscalevcores.AutoScaleVCoresClient", "Delete", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForDelete prepares the Delete request. +func (c AutoScaleVCoresClient) preparerForDelete(ctx context.Context, id AutoScaleVCoreId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsDelete(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForDelete handles the response to the Delete request. The method always +// closes the http.Response Body. +func (c AutoScaleVCoresClient) responderForDelete(resp *http.Response) (result DeleteResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/internal/services/powerbi/sdk/2021-01-01/autoscalevcores/method_get_autorest.go b/internal/services/powerbi/sdk/2021-01-01/autoscalevcores/method_get_autorest.go new file mode 100644 index 000000000000..9b3ff12c2066 --- /dev/null +++ b/internal/services/powerbi/sdk/2021-01-01/autoscalevcores/method_get_autorest.go @@ -0,0 +1,64 @@ +package autoscalevcores + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +type GetResponse struct { + HttpResponse *http.Response + Model *AutoScaleVCore +} + +// Get ... +func (c AutoScaleVCoresClient) Get(ctx context.Context, id AutoScaleVCoreId) (result GetResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "autoscalevcores.AutoScaleVCoresClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "autoscalevcores.AutoScaleVCoresClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "autoscalevcores.AutoScaleVCoresClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c AutoScaleVCoresClient) preparerForGet(ctx context.Context, id AutoScaleVCoreId) (*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 AutoScaleVCoresClient) 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/powerbi/sdk/2021-01-01/autoscalevcores/method_listbyresourcegroup_autorest.go b/internal/services/powerbi/sdk/2021-01-01/autoscalevcores/method_listbyresourcegroup_autorest.go new file mode 100644 index 000000000000..9dabf28e853a --- /dev/null +++ b/internal/services/powerbi/sdk/2021-01-01/autoscalevcores/method_listbyresourcegroup_autorest.go @@ -0,0 +1,65 @@ +package autoscalevcores + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +type ListByResourceGroupResponse struct { + HttpResponse *http.Response + Model *AutoScaleVCoreListResult +} + +// ListByResourceGroup ... +func (c AutoScaleVCoresClient) ListByResourceGroup(ctx context.Context, id ResourceGroupId) (result ListByResourceGroupResponse, err error) { + req, err := c.preparerForListByResourceGroup(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "autoscalevcores.AutoScaleVCoresClient", "ListByResourceGroup", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "autoscalevcores.AutoScaleVCoresClient", "ListByResourceGroup", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForListByResourceGroup(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "autoscalevcores.AutoScaleVCoresClient", "ListByResourceGroup", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForListByResourceGroup prepares the ListByResourceGroup request. +func (c AutoScaleVCoresClient) preparerForListByResourceGroup(ctx context.Context, id ResourceGroupId) (*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/providers/Microsoft.PowerBIDedicated/autoScaleVCores", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForListByResourceGroup handles the response to the ListByResourceGroup request. The method always +// closes the http.Response Body. +func (c AutoScaleVCoresClient) responderForListByResourceGroup(resp *http.Response) (result ListByResourceGroupResponse, 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/powerbi/sdk/2021-01-01/autoscalevcores/method_listbysubscription_autorest.go b/internal/services/powerbi/sdk/2021-01-01/autoscalevcores/method_listbysubscription_autorest.go new file mode 100644 index 000000000000..722376fb7333 --- /dev/null +++ b/internal/services/powerbi/sdk/2021-01-01/autoscalevcores/method_listbysubscription_autorest.go @@ -0,0 +1,65 @@ +package autoscalevcores + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +type ListBySubscriptionResponse struct { + HttpResponse *http.Response + Model *AutoScaleVCoreListResult +} + +// ListBySubscription ... +func (c AutoScaleVCoresClient) ListBySubscription(ctx context.Context, id SubscriptionId) (result ListBySubscriptionResponse, err error) { + req, err := c.preparerForListBySubscription(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "autoscalevcores.AutoScaleVCoresClient", "ListBySubscription", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "autoscalevcores.AutoScaleVCoresClient", "ListBySubscription", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForListBySubscription(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "autoscalevcores.AutoScaleVCoresClient", "ListBySubscription", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForListBySubscription prepares the ListBySubscription request. +func (c AutoScaleVCoresClient) preparerForListBySubscription(ctx context.Context, id SubscriptionId) (*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/providers/Microsoft.PowerBIDedicated/autoScaleVCores", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForListBySubscription handles the response to the ListBySubscription request. The method always +// closes the http.Response Body. +func (c AutoScaleVCoresClient) responderForListBySubscription(resp *http.Response) (result ListBySubscriptionResponse, 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/powerbi/sdk/2021-01-01/autoscalevcores/method_update_autorest.go b/internal/services/powerbi/sdk/2021-01-01/autoscalevcores/method_update_autorest.go new file mode 100644 index 000000000000..ef8391901d01 --- /dev/null +++ b/internal/services/powerbi/sdk/2021-01-01/autoscalevcores/method_update_autorest.go @@ -0,0 +1,65 @@ +package autoscalevcores + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +type UpdateResponse struct { + HttpResponse *http.Response + Model *AutoScaleVCore +} + +// Update ... +func (c AutoScaleVCoresClient) Update(ctx context.Context, id AutoScaleVCoreId, input AutoScaleVCoreUpdateParameters) (result UpdateResponse, err error) { + req, err := c.preparerForUpdate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "autoscalevcores.AutoScaleVCoresClient", "Update", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "autoscalevcores.AutoScaleVCoresClient", "Update", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForUpdate(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "autoscalevcores.AutoScaleVCoresClient", "Update", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForUpdate prepares the Update request. +func (c AutoScaleVCoresClient) preparerForUpdate(ctx context.Context, id AutoScaleVCoreId, input AutoScaleVCoreUpdateParameters) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPatch(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForUpdate handles the response to the Update request. The method always +// closes the http.Response Body. +func (c AutoScaleVCoresClient) responderForUpdate(resp *http.Response) (result UpdateResponse, 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/powerbi/sdk/2021-01-01/autoscalevcores/model_autoscalevcore.go b/internal/services/powerbi/sdk/2021-01-01/autoscalevcores/model_autoscalevcore.go new file mode 100644 index 000000000000..db52cb1f77d1 --- /dev/null +++ b/internal/services/powerbi/sdk/2021-01-01/autoscalevcores/model_autoscalevcore.go @@ -0,0 +1,12 @@ +package autoscalevcores + +type AutoScaleVCore struct { + Id *string `json:"id,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *AutoScaleVCoreProperties `json:"properties,omitempty"` + Sku AutoScaleVCoreSku `json:"sku"` + SystemData *SystemData `json:"systemData,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/internal/services/powerbi/sdk/2021-01-01/autoscalevcores/model_autoscalevcorelistresult.go b/internal/services/powerbi/sdk/2021-01-01/autoscalevcores/model_autoscalevcorelistresult.go new file mode 100644 index 000000000000..6734ef056c57 --- /dev/null +++ b/internal/services/powerbi/sdk/2021-01-01/autoscalevcores/model_autoscalevcorelistresult.go @@ -0,0 +1,5 @@ +package autoscalevcores + +type AutoScaleVCoreListResult struct { + Value []AutoScaleVCore `json:"value"` +} diff --git a/internal/services/powerbi/sdk/2021-01-01/autoscalevcores/model_autoscalevcoremutableproperties.go b/internal/services/powerbi/sdk/2021-01-01/autoscalevcores/model_autoscalevcoremutableproperties.go new file mode 100644 index 000000000000..113f9078c786 --- /dev/null +++ b/internal/services/powerbi/sdk/2021-01-01/autoscalevcores/model_autoscalevcoremutableproperties.go @@ -0,0 +1,5 @@ +package autoscalevcores + +type AutoScaleVCoreMutableProperties struct { + CapacityLimit *int64 `json:"capacityLimit,omitempty"` +} diff --git a/internal/services/powerbi/sdk/2021-01-01/autoscalevcores/model_autoscalevcoreproperties.go b/internal/services/powerbi/sdk/2021-01-01/autoscalevcores/model_autoscalevcoreproperties.go new file mode 100644 index 000000000000..74342b8fd1ff --- /dev/null +++ b/internal/services/powerbi/sdk/2021-01-01/autoscalevcores/model_autoscalevcoreproperties.go @@ -0,0 +1,7 @@ +package autoscalevcores + +type AutoScaleVCoreProperties struct { + CapacityLimit *int64 `json:"capacityLimit,omitempty"` + CapacityObjectId *string `json:"capacityObjectId,omitempty"` + ProvisioningState *VCoreProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/internal/services/powerbi/sdk/2021-01-01/autoscalevcores/model_autoscalevcoresku.go b/internal/services/powerbi/sdk/2021-01-01/autoscalevcores/model_autoscalevcoresku.go new file mode 100644 index 000000000000..6c6feab87eea --- /dev/null +++ b/internal/services/powerbi/sdk/2021-01-01/autoscalevcores/model_autoscalevcoresku.go @@ -0,0 +1,7 @@ +package autoscalevcores + +type AutoScaleVCoreSku struct { + Capacity *int64 `json:"capacity,omitempty"` + Name string `json:"name"` + Tier *VCoreSkuTier `json:"tier,omitempty"` +} diff --git a/internal/services/powerbi/sdk/2021-01-01/autoscalevcores/model_autoscalevcoreupdateparameters.go b/internal/services/powerbi/sdk/2021-01-01/autoscalevcores/model_autoscalevcoreupdateparameters.go new file mode 100644 index 000000000000..7f5d6193331e --- /dev/null +++ b/internal/services/powerbi/sdk/2021-01-01/autoscalevcores/model_autoscalevcoreupdateparameters.go @@ -0,0 +1,7 @@ +package autoscalevcores + +type AutoScaleVCoreUpdateParameters struct { + Properties *AutoScaleVCoreMutableProperties `json:"properties,omitempty"` + Sku *AutoScaleVCoreSku `json:"sku,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/internal/services/powerbi/sdk/2021-01-01/autoscalevcores/model_systemdata.go b/internal/services/powerbi/sdk/2021-01-01/autoscalevcores/model_systemdata.go new file mode 100644 index 000000000000..5c0537b0207e --- /dev/null +++ b/internal/services/powerbi/sdk/2021-01-01/autoscalevcores/model_systemdata.go @@ -0,0 +1,10 @@ +package autoscalevcores + +type SystemData struct { + CreatedAt *string `json:"createdAt,omitempty"` + CreatedBy *string `json:"createdBy,omitempty"` + CreatedByType *IdentityType `json:"createdByType,omitempty"` + LastModifiedAt *string `json:"lastModifiedAt,omitempty"` + LastModifiedBy *string `json:"lastModifiedBy,omitempty"` + LastModifiedByType *IdentityType `json:"lastModifiedByType,omitempty"` +} diff --git a/internal/services/powerbi/sdk/2021-01-01/autoscalevcores/version.go b/internal/services/powerbi/sdk/2021-01-01/autoscalevcores/version.go new file mode 100644 index 000000000000..47778c7d2579 --- /dev/null +++ b/internal/services/powerbi/sdk/2021-01-01/autoscalevcores/version.go @@ -0,0 +1,9 @@ +package autoscalevcores + +import "fmt" + +const defaultApiVersion = "2021-01-01" + +func userAgent() string { + return fmt.Sprintf("pandora/autoscalevcores/%s", defaultApiVersion) +} diff --git a/internal/services/powerbi/sdk/2021-01-01/capacities/constants.go b/internal/services/powerbi/sdk/2021-01-01/capacities/constants.go index 15fb5e891da7..566d7842dc47 100644 --- a/internal/services/powerbi/sdk/2021-01-01/capacities/constants.go +++ b/internal/services/powerbi/sdk/2021-01-01/capacities/constants.go @@ -1,5 +1,7 @@ package capacities +import "strings" + type CapacityProvisioningState string const ( @@ -17,6 +19,47 @@ const ( CapacityProvisioningStateUpdating CapacityProvisioningState = "Updating" ) +func PossibleValuesForCapacityProvisioningState() []string { + return []string{ + string(CapacityProvisioningStateDeleting), + string(CapacityProvisioningStateFailed), + string(CapacityProvisioningStatePaused), + string(CapacityProvisioningStatePausing), + string(CapacityProvisioningStatePreparing), + string(CapacityProvisioningStateProvisioning), + string(CapacityProvisioningStateResuming), + string(CapacityProvisioningStateScaling), + string(CapacityProvisioningStateSucceeded), + string(CapacityProvisioningStateSuspended), + string(CapacityProvisioningStateSuspending), + string(CapacityProvisioningStateUpdating), + } +} + +func parseCapacityProvisioningState(input string) (*CapacityProvisioningState, error) { + vals := map[string]CapacityProvisioningState{ + "deleting": CapacityProvisioningStateDeleting, + "failed": CapacityProvisioningStateFailed, + "paused": CapacityProvisioningStatePaused, + "pausing": CapacityProvisioningStatePausing, + "preparing": CapacityProvisioningStatePreparing, + "provisioning": CapacityProvisioningStateProvisioning, + "resuming": CapacityProvisioningStateResuming, + "scaling": CapacityProvisioningStateScaling, + "succeeded": CapacityProvisioningStateSucceeded, + "suspended": CapacityProvisioningStateSuspended, + "suspending": CapacityProvisioningStateSuspending, + "updating": CapacityProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CapacityProvisioningState(input) + return &out, nil +} + type CapacitySkuTier string const ( @@ -25,6 +68,29 @@ const ( CapacitySkuTierPremium CapacitySkuTier = "Premium" ) +func PossibleValuesForCapacitySkuTier() []string { + return []string{ + string(CapacitySkuTierAutoPremiumHost), + string(CapacitySkuTierPBIEAzure), + string(CapacitySkuTierPremium), + } +} + +func parseCapacitySkuTier(input string) (*CapacitySkuTier, error) { + vals := map[string]CapacitySkuTier{ + "autopremiumhost": CapacitySkuTierAutoPremiumHost, + "pbie_azure": CapacitySkuTierPBIEAzure, + "premium": CapacitySkuTierPremium, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CapacitySkuTier(input) + return &out, nil +} + type IdentityType string const ( @@ -34,6 +100,31 @@ const ( IdentityTypeUser IdentityType = "User" ) +func PossibleValuesForIdentityType() []string { + return []string{ + string(IdentityTypeApplication), + string(IdentityTypeKey), + string(IdentityTypeManagedIdentity), + string(IdentityTypeUser), + } +} + +func parseIdentityType(input string) (*IdentityType, error) { + vals := map[string]IdentityType{ + "application": IdentityTypeApplication, + "key": IdentityTypeKey, + "managedidentity": IdentityTypeManagedIdentity, + "user": IdentityTypeUser, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := IdentityType(input) + return &out, nil +} + type Mode string const ( @@ -41,6 +132,27 @@ const ( ModeGenTwo Mode = "Gen2" ) +func PossibleValuesForMode() []string { + return []string{ + string(ModeGenOne), + string(ModeGenTwo), + } +} + +func parseMode(input string) (*Mode, error) { + vals := map[string]Mode{ + "gen1": ModeGenOne, + "gen2": ModeGenTwo, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Mode(input) + return &out, nil +} + type State string const ( @@ -57,3 +169,44 @@ const ( StateSuspending State = "Suspending" StateUpdating State = "Updating" ) + +func PossibleValuesForState() []string { + return []string{ + string(StateDeleting), + string(StateFailed), + string(StatePaused), + string(StatePausing), + string(StatePreparing), + string(StateProvisioning), + string(StateResuming), + string(StateScaling), + string(StateSucceeded), + string(StateSuspended), + string(StateSuspending), + string(StateUpdating), + } +} + +func parseState(input string) (*State, error) { + vals := map[string]State{ + "deleting": StateDeleting, + "failed": StateFailed, + "paused": StatePaused, + "pausing": StatePausing, + "preparing": StatePreparing, + "provisioning": StateProvisioning, + "resuming": StateResuming, + "scaling": StateScaling, + "succeeded": StateSucceeded, + "suspended": StateSuspended, + "suspending": StateSuspending, + "updating": StateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := State(input) + return &out, nil +} diff --git a/internal/services/powerbi/sdk/2021-01-01/capacities/id_capacities.go b/internal/services/powerbi/sdk/2021-01-01/capacities/id_capacities.go index ab339450cf3d..3349915de44c 100644 --- a/internal/services/powerbi/sdk/2021-01-01/capacities/id_capacities.go +++ b/internal/services/powerbi/sdk/2021-01-01/capacities/id_capacities.go @@ -7,102 +7,118 @@ import ( "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" ) +var _ resourceids.ResourceId = CapacitiesId{} + +// CapacitiesId is a struct representing the Resource ID for a Capacities type CapacitiesId struct { - SubscriptionId string - ResourceGroup string - CapacityName string + SubscriptionId string + ResourceGroupName string + DedicatedCapacityName string } -func NewCapacitiesID(subscriptionId, resourceGroup, capacityName string) CapacitiesId { +// NewCapacitiesID returns a new CapacitiesId struct +func NewCapacitiesID(subscriptionId string, resourceGroupName string, dedicatedCapacityName string) CapacitiesId { return CapacitiesId{ - SubscriptionId: subscriptionId, - ResourceGroup: resourceGroup, - CapacityName: capacityName, + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + DedicatedCapacityName: dedicatedCapacityName, } } -func (id CapacitiesId) String() string { - segments := []string{ - fmt.Sprintf("Capacity Name %q", id.CapacityName), - fmt.Sprintf("Resource Group %q", id.ResourceGroup), - } - segmentsStr := strings.Join(segments, " / ") - return fmt.Sprintf("%s: (%s)", "Capacities", segmentsStr) -} - -func (id CapacitiesId) ID() string { - fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.PowerBIDedicated/capacities/%s" - return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.CapacityName) -} - -// ParseCapacitiesID parses a Capacities ID into an CapacitiesId struct +// ParseCapacitiesID parses 'input' into a CapacitiesId func ParseCapacitiesID(input string) (*CapacitiesId, error) { - id, err := resourceids.ParseAzureResourceID(input) + parser := resourceids.NewParserFromResourceIdType(CapacitiesId{}) + parsed, err := parser.Parse(input, false) if err != nil { - return nil, err - } - - resourceId := CapacitiesId{ - 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 := CapacitiesId{} - 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.CapacityName, err = id.PopSegment("capacities"); 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.DedicatedCapacityName, ok = parsed.Parsed["dedicatedCapacityName"]; !ok { + return nil, fmt.Errorf("the segment 'dedicatedCapacityName' was not found in the resource id %q", input) } - return &resourceId, nil + return &id, nil } -// ParseCapacitiesIDInsensitively parses an Capacities ID into an CapacitiesId struct, insensitively -// This should only be used to parse an ID for rewriting to a consistent casing, -// the ParseCapacitiesID method should be used instead for validation etc. +// ParseCapacitiesIDInsensitively parses 'input' case-insensitively into a CapacitiesId +// note: this method should only be used for API response data and not user input func ParseCapacitiesIDInsensitively(input string) (*CapacitiesId, error) { - id, err := resourceids.ParseAzureResourceID(input) + parser := resourceids.NewParserFromResourceIdType(CapacitiesId{}) + parsed, err := parser.Parse(input, true) if err != nil { - return nil, err + return nil, fmt.Errorf("parsing %q: %+v", input, err) } - resourceId := CapacitiesId{ - SubscriptionId: id.SubscriptionID, - ResourceGroup: id.ResourceGroup, + var ok bool + id := CapacitiesId{} + + 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.DedicatedCapacityName, ok = parsed.Parsed["dedicatedCapacityName"]; !ok { + return nil, fmt.Errorf("the segment 'dedicatedCapacityName' was not found in the resource id %q", input) } - // find the correct casing for the 'capacities' segment - capacitiesKey := "capacities" - for key := range id.Path { - if strings.EqualFold(key, capacitiesKey) { - capacitiesKey = key - break - } + return &id, nil +} + +// ValidateCapacitiesID checks that 'input' can be parsed as a Capacities ID +func ValidateCapacitiesID(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.CapacityName, err = id.PopSegment(capacitiesKey); err != nil { - return nil, err + + if _, err := ParseCapacitiesID(v); err != nil { + errors = append(errors, err) } - if err := id.ValidateNoEmptySegments(input); err != nil { - return nil, err + return +} + +// ID returns the formatted Capacities ID +func (id CapacitiesId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.PowerBIDedicated/capacities/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.DedicatedCapacityName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Capacities ID +func (id CapacitiesId) 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("microsoftPowerBIDedicated", "Microsoft.PowerBIDedicated", "Microsoft.PowerBIDedicated"), + resourceids.StaticSegment("capacities", "capacities", "capacities"), + resourceids.UserSpecifiedSegment("dedicatedCapacityName", "dedicatedCapacityValue"), } +} - return &resourceId, nil +// String returns a human-readable description of this Capacities ID +func (id CapacitiesId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Dedicated Capacity Name: %q", id.DedicatedCapacityName), + } + return fmt.Sprintf("Capacities (%s)", strings.Join(components, "\n")) } diff --git a/internal/services/powerbi/sdk/2021-01-01/capacities/id_capacities_test.go b/internal/services/powerbi/sdk/2021-01-01/capacities/id_capacities_test.go index 13712863cdfc..67bc097327c1 100644 --- a/internal/services/powerbi/sdk/2021-01-01/capacities/id_capacities_test.go +++ b/internal/services/powerbi/sdk/2021-01-01/capacities/id_capacities_test.go @@ -6,13 +6,29 @@ import ( "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" ) -var _ resourceids.Id = CapacitiesId{} +var _ resourceids.ResourceId = CapacitiesId{} -func TestCapacitiesIDFormatter(t *testing.T) { - actual := NewCapacitiesID("{subscriptionId}", "{resourceGroupName}", "{dedicatedCapacityName}").ID() - expected := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PowerBIDedicated/capacities/{dedicatedCapacityName}" +func TestNewCapacitiesID(t *testing.T) { + id := NewCapacitiesID("12345678-1234-9876-4563-123456789012", "example-resource-group", "dedicatedCapacityValue") + + 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.DedicatedCapacityName != "dedicatedCapacityValue" { + t.Fatalf("Expected %q but got %q for Segment 'DedicatedCapacityName'", id.DedicatedCapacityName, "dedicatedCapacityValue") + } +} + +func TestFormatCapacitiesID(t *testing.T) { + actual := NewCapacitiesID("12345678-1234-9876-4563-123456789012", "example-resource-group", "dedicatedCapacityValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.PowerBIDedicated/capacities/dedicatedCapacityValue" 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 TestParseCapacitiesID(t *testing.T) { Error bool Expected *CapacitiesId }{ - { - // 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 CapacityName - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PowerBIDedicated/", + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", Error: true, }, - { - // missing value for CapacityName - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PowerBIDedicated/capacities/", + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.PowerBIDedicated", Error: true, }, - { - // valid - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PowerBIDedicated/capacities/{dedicatedCapacityName}", + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.PowerBIDedicated/capacities", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.PowerBIDedicated/capacities/dedicatedCapacityValue", Expected: &CapacitiesId{ - SubscriptionId: "{subscriptionId}", - ResourceGroup: "{resourceGroupName}", - CapacityName: "{dedicatedCapacityName}", + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + DedicatedCapacityName: "dedicatedCapacityValue", }, }, - { - // upper-cased - Input: "/SUBSCRIPTIONS/{SUBSCRIPTIONID}/RESOURCEGROUPS/{RESOURCEGROUPNAME}/PROVIDERS/MICROSOFT.POWERBIDEDICATED/CAPACITIES/{DEDICATEDCAPACITYNAME}", + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.PowerBIDedicated/capacities/dedicatedCapacityValue/extra", Error: true, }, } - for _, v := range testData { t.Logf("[DEBUG] Testing %q", v.Input) @@ -91,7 +102,7 @@ func TestParseCapacitiesID(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 TestParseCapacitiesID(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.CapacityName != v.Expected.CapacityName { - t.Fatalf("Expected %q but got %q for CapacityName", v.Expected.CapacityName, actual.CapacityName) + + if actual.DedicatedCapacityName != v.Expected.DedicatedCapacityName { + t.Fatalf("Expected %q but got %q for DedicatedCapacityName", v.Expected.DedicatedCapacityName, actual.DedicatedCapacityName) } + } } @@ -115,90 +129,110 @@ func TestParseCapacitiesIDInsensitively(t *testing.T) { Error bool Expected *CapacitiesId }{ - { - // 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 CapacityName - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PowerBIDedicated/", + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", Error: true, }, - { - // missing value for CapacityName - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PowerBIDedicated/capacities/", + // 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.PowerBIDedicated/capacities/{dedicatedCapacityName}", - Expected: &CapacitiesId{ - SubscriptionId: "{subscriptionId}", - ResourceGroup: "{resourceGroupName}", - CapacityName: "{dedicatedCapacityName}", - }, + // 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.PowerBIDedicated/capacities/{dedicatedCapacityName}", - Expected: &CapacitiesId{ - SubscriptionId: "{subscriptionId}", - ResourceGroup: "{resourceGroupName}", - CapacityName: "{dedicatedCapacityName}", - }, + // 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.PowerBIDedicated", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.pOwErBiDeDiCaTeD", + Error: true, }, - { - // upper-cased segment names - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PowerBIDedicated/CAPACITIES/{dedicatedCapacityName}", + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.PowerBIDedicated/capacities", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.pOwErBiDeDiCaTeD/cApAcItIeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.PowerBIDedicated/capacities/dedicatedCapacityValue", Expected: &CapacitiesId{ - SubscriptionId: "{subscriptionId}", - ResourceGroup: "{resourceGroupName}", - CapacityName: "{dedicatedCapacityName}", + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + DedicatedCapacityName: "dedicatedCapacityValue", }, }, - { - // mixed-cased segment names - Input: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PowerBIDedicated/CaPaCiTiEs/{dedicatedCapacityName}", + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.PowerBIDedicated/capacities/dedicatedCapacityValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.pOwErBiDeDiCaTeD/cApAcItIeS/dEdIcAtEdCaPaCiTyVaLuE", Expected: &CapacitiesId{ - SubscriptionId: "{subscriptionId}", - ResourceGroup: "{resourceGroupName}", - CapacityName: "{dedicatedCapacityName}", + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + DedicatedCapacityName: "dEdIcAtEdCaPaCiTyVaLuE", }, }, + { + // 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.pOwErBiDeDiCaTeD/cApAcItIeS/dEdIcAtEdCaPaCiTyVaLuE/extra", + Error: true, + }, } - for _, v := range testData { t.Logf("[DEBUG] Testing %q", v.Input) @@ -208,7 +242,7 @@ func TestParseCapacitiesIDInsensitively(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 TestParseCapacitiesIDInsensitively(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.CapacityName != v.Expected.CapacityName { - t.Fatalf("Expected %q but got %q for CapacityName", v.Expected.CapacityName, actual.CapacityName) + + if actual.DedicatedCapacityName != v.Expected.DedicatedCapacityName { + t.Fatalf("Expected %q but got %q for DedicatedCapacityName", v.Expected.DedicatedCapacityName, actual.DedicatedCapacityName) } + } } diff --git a/internal/services/powerbi/sdk/2021-01-01/capacities/id_location.go b/internal/services/powerbi/sdk/2021-01-01/capacities/id_location.go index 5a0a0e671b73..06db7f0ea427 100644 --- a/internal/services/powerbi/sdk/2021-01-01/capacities/id_location.go +++ b/internal/services/powerbi/sdk/2021-01-01/capacities/id_location.go @@ -7,89 +7,105 @@ import ( "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" ) +var _ resourceids.ResourceId = LocationId{} + +// LocationId is a struct representing the Resource ID for a Location type LocationId struct { SubscriptionId string - Name string + Location string } -func NewLocationID(subscriptionId, name string) LocationId { +// NewLocationID returns a new LocationId struct +func NewLocationID(subscriptionId string, location string) LocationId { return LocationId{ SubscriptionId: subscriptionId, - Name: name, + Location: location, } } -func (id LocationId) String() string { - segments := []string{ - fmt.Sprintf("Name %q", id.Name), - } - segmentsStr := strings.Join(segments, " / ") - return fmt.Sprintf("%s: (%s)", "Location", segmentsStr) -} - -func (id LocationId) ID() string { - fmtString := "/subscriptions/%s/providers/Microsoft.PowerBIDedicated/locations/%s" - return fmt.Sprintf(fmtString, id.SubscriptionId, id.Name) -} - -// ParseLocationID parses a Location ID into an LocationId struct +// ParseLocationID parses 'input' into a LocationId func ParseLocationID(input string) (*LocationId, error) { - id, err := resourceids.ParseAzureResourceID(input) + parser := resourceids.NewParserFromResourceIdType(LocationId{}) + parsed, err := parser.Parse(input, false) if err != nil { - return nil, err - } - - resourceId := LocationId{ - SubscriptionId: id.SubscriptionID, + return nil, fmt.Errorf("parsing %q: %+v", input, err) } - if resourceId.SubscriptionId == "" { - return nil, fmt.Errorf("ID was missing the 'subscriptions' element") - } + var ok bool + id := LocationId{} - if resourceId.Name, err = id.PopSegment("locations"); err != nil { - return nil, err + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) } - if err := id.ValidateNoEmptySegments(input); err != nil { - return nil, err + if id.Location, ok = parsed.Parsed["location"]; !ok { + return nil, fmt.Errorf("the segment 'location' was not found in the resource id %q", input) } - return &resourceId, nil + return &id, nil } -// ParseLocationIDInsensitively parses an Location ID into an LocationId struct, insensitively -// This should only be used to parse an ID for rewriting to a consistent casing, -// the ParseLocationID method should be used instead for validation etc. +// ParseLocationIDInsensitively parses 'input' case-insensitively into a LocationId +// note: this method should only be used for API response data and not user input func ParseLocationIDInsensitively(input string) (*LocationId, error) { - id, err := resourceids.ParseAzureResourceID(input) + parser := resourceids.NewParserFromResourceIdType(LocationId{}) + parsed, err := parser.Parse(input, true) if err != nil { - return nil, err + return nil, fmt.Errorf("parsing %q: %+v", input, err) } - resourceId := LocationId{ - SubscriptionId: id.SubscriptionID, + var ok bool + id := LocationId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) } - if resourceId.SubscriptionId == "" { - return nil, fmt.Errorf("ID was missing the 'subscriptions' element") + if id.Location, ok = parsed.Parsed["location"]; !ok { + return nil, fmt.Errorf("the segment 'location' was not found in the resource id %q", input) } - // find the correct casing for the 'locations' segment - locationsKey := "locations" - for key := range id.Path { - if strings.EqualFold(key, locationsKey) { - locationsKey = key - break - } + return &id, nil +} + +// ValidateLocationID checks that 'input' can be parsed as a Location ID +func ValidateLocationID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return } - if resourceId.Name, err = id.PopSegment(locationsKey); err != nil { - return nil, err + + if _, err := ParseLocationID(v); err != nil { + errors = append(errors, err) } - if err := id.ValidateNoEmptySegments(input); err != nil { - return nil, err + return +} + +// ID returns the formatted Location ID +func (id LocationId) ID() string { + fmtString := "/subscriptions/%s/providers/Microsoft.PowerBIDedicated/locations/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.Location) +} + +// Segments returns a slice of Resource ID Segments which comprise this Location ID +func (id LocationId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("subscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("providers", "providers", "providers"), + resourceids.ResourceProviderSegment("microsoftPowerBIDedicated", "Microsoft.PowerBIDedicated", "Microsoft.PowerBIDedicated"), + resourceids.StaticSegment("locations", "locations", "locations"), + resourceids.UserSpecifiedSegment("location", "locationValue"), } +} - return &resourceId, nil +// String returns a human-readable description of this Location ID +func (id LocationId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Location: %q", id.Location), + } + return fmt.Sprintf("Location (%s)", strings.Join(components, "\n")) } diff --git a/internal/services/powerbi/sdk/2021-01-01/capacities/id_location_test.go b/internal/services/powerbi/sdk/2021-01-01/capacities/id_location_test.go index d388d66558b8..d7c765a36379 100644 --- a/internal/services/powerbi/sdk/2021-01-01/capacities/id_location_test.go +++ b/internal/services/powerbi/sdk/2021-01-01/capacities/id_location_test.go @@ -6,13 +6,25 @@ import ( "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" ) -var _ resourceids.Id = LocationId{} +var _ resourceids.ResourceId = LocationId{} -func TestLocationIDFormatter(t *testing.T) { - actual := NewLocationID("{subscriptionId}", "{location}").ID() - expected := "/subscriptions/{subscriptionId}/providers/Microsoft.PowerBIDedicated/locations/{location}" +func TestNewLocationID(t *testing.T) { + id := NewLocationID("12345678-1234-9876-4563-123456789012", "locationValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.Location != "locationValue" { + t.Fatalf("Expected %q but got %q for Segment 'Location'", id.Location, "locationValue") + } +} + +func TestFormatLocationID(t *testing.T) { + actual := NewLocationID("12345678-1234-9876-4563-123456789012", "locationValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.PowerBIDedicated/locations/locationValue" if actual != expected { - t.Fatalf("Expected %q but got %q", expected, actual) + t.Fatalf("Expected the Formatted ID to be %q but got %q", actual, expected) } } @@ -22,53 +34,50 @@ func TestParseLocationID(t *testing.T) { Error bool Expected *LocationId }{ - { - // empty + // Incomplete URI Input: "", Error: true, }, - { - // missing SubscriptionId - Input: "/", + // Incomplete URI + Input: "/subscriptions", Error: true, }, - { - // missing value for SubscriptionId - Input: "/subscriptions/", + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", Error: true, }, - { - // missing Name - Input: "/subscriptions/{subscriptionId}/providers/Microsoft.PowerBIDedicated/", + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers", Error: true, }, - { - // missing value for Name - Input: "/subscriptions/{subscriptionId}/providers/Microsoft.PowerBIDedicated/locations/", + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.PowerBIDedicated", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.PowerBIDedicated/locations", Error: true, }, - { - // valid - Input: "/subscriptions/{subscriptionId}/providers/Microsoft.PowerBIDedicated/locations/{location}", + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.PowerBIDedicated/locations/locationValue", Expected: &LocationId{ - SubscriptionId: "{subscriptionId}", - Name: "{location}", + SubscriptionId: "12345678-1234-9876-4563-123456789012", + Location: "locationValue", }, }, - { - // upper-cased - Input: "/SUBSCRIPTIONS/{SUBSCRIPTIONID}/PROVIDERS/MICROSOFT.POWERBIDEDICATED/LOCATIONS/{LOCATION}", + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.PowerBIDedicated/locations/locationValue/extra", Error: true, }, } - for _, v := range testData { t.Logf("[DEBUG] Testing %q", v.Input) @@ -78,7 +87,7 @@ func TestParseLocationID(t *testing.T) { continue } - t.Fatalf("Expect a value but got an error: %s", err) + t.Fatalf("Expect a value but got an error: %+v", err) } if v.Error { t.Fatal("Expect an error but didn't get one") @@ -87,9 +96,11 @@ func TestParseLocationID(t *testing.T) { if actual.SubscriptionId != v.Expected.SubscriptionId { t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) } - if actual.Name != v.Expected.Name { - t.Fatalf("Expected %q but got %q for Name", v.Expected.Name, actual.Name) + + if actual.Location != v.Expected.Location { + t.Fatalf("Expected %q but got %q for Location", v.Expected.Location, actual.Location) } + } } @@ -99,74 +110,88 @@ func TestParseLocationIDInsensitively(t *testing.T) { Error bool Expected *LocationId }{ - { - // empty + // Incomplete URI Input: "", Error: true, }, - { - // missing SubscriptionId - Input: "/", + // Incomplete URI + Input: "/subscriptions", Error: true, }, - { - // missing value for SubscriptionId - Input: "/subscriptions/", + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", Error: true, }, - { - // missing Name - Input: "/subscriptions/{subscriptionId}/providers/Microsoft.PowerBIDedicated/", + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", Error: true, }, - { - // missing value for Name - Input: "/subscriptions/{subscriptionId}/providers/Microsoft.PowerBIDedicated/locations/", + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", Error: true, }, - { - // valid - Input: "/subscriptions/{subscriptionId}/providers/Microsoft.PowerBIDedicated/locations/{location}", - Expected: &LocationId{ - SubscriptionId: "{subscriptionId}", - Name: "{location}", - }, + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, }, - { - // lower-cased segment names - Input: "/subscriptions/{subscriptionId}/providers/Microsoft.PowerBIDedicated/locations/{location}", - Expected: &LocationId{ - SubscriptionId: "{subscriptionId}", - Name: "{location}", - }, + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.PowerBIDedicated", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.pOwErBiDeDiCaTeD", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.PowerBIDedicated/locations", + Error: true, }, - { - // upper-cased segment names - Input: "/subscriptions/{subscriptionId}/providers/Microsoft.PowerBIDedicated/LOCATIONS/{location}", + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.pOwErBiDeDiCaTeD/lOcAtIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.PowerBIDedicated/locations/locationValue", Expected: &LocationId{ - SubscriptionId: "{subscriptionId}", - Name: "{location}", + SubscriptionId: "12345678-1234-9876-4563-123456789012", + Location: "locationValue", }, }, - { - // mixed-cased segment names - Input: "/subscriptions/{subscriptionId}/providers/Microsoft.PowerBIDedicated/LoCaTiOnS/{location}", + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.PowerBIDedicated/locations/locationValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.pOwErBiDeDiCaTeD/lOcAtIoNs/lOcAtIoNvAlUe", Expected: &LocationId{ - SubscriptionId: "{subscriptionId}", - Name: "{location}", + SubscriptionId: "12345678-1234-9876-4563-123456789012", + Location: "lOcAtIoNvAlUe", }, }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.pOwErBiDeDiCaTeD/lOcAtIoNs/lOcAtIoNvAlUe/extra", + Error: true, + }, } - for _, v := range testData { t.Logf("[DEBUG] Testing %q", v.Input) @@ -176,7 +201,7 @@ func TestParseLocationIDInsensitively(t *testing.T) { continue } - t.Fatalf("Expect a value but got an error: %s", err) + t.Fatalf("Expect a value but got an error: %+v", err) } if v.Error { t.Fatal("Expect an error but didn't get one") @@ -185,8 +210,10 @@ func TestParseLocationIDInsensitively(t *testing.T) { if actual.SubscriptionId != v.Expected.SubscriptionId { t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) } - if actual.Name != v.Expected.Name { - t.Fatalf("Expected %q but got %q for Name", v.Expected.Name, actual.Name) + + if actual.Location != v.Expected.Location { + t.Fatalf("Expected %q but got %q for Location", v.Expected.Location, actual.Location) } + } } diff --git a/internal/services/powerbi/sdk/2021-01-01/capacities/id_resourcegroup.go b/internal/services/powerbi/sdk/2021-01-01/capacities/id_resourcegroup.go index 3da781140fbe..7e9c16e2e162 100644 --- a/internal/services/powerbi/sdk/2021-01-01/capacities/id_resourcegroup.go +++ b/internal/services/powerbi/sdk/2021-01-01/capacities/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/powerbi/sdk/2021-01-01/capacities/id_resourcegroup_test.go b/internal/services/powerbi/sdk/2021-01-01/capacities/id_resourcegroup_test.go index f83fe4665a97..988e78477809 100644 --- a/internal/services/powerbi/sdk/2021-01-01/capacities/id_resourcegroup_test.go +++ b/internal/services/powerbi/sdk/2021-01-01/capacities/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/powerbi/sdk/2021-01-01/capacities/id_subscription.go b/internal/services/powerbi/sdk/2021-01-01/capacities/id_subscription.go index fd8551c377f5..c7798def1118 100644 --- a/internal/services/powerbi/sdk/2021-01-01/capacities/id_subscription.go +++ b/internal/services/powerbi/sdk/2021-01-01/capacities/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/powerbi/sdk/2021-01-01/capacities/id_subscription_test.go b/internal/services/powerbi/sdk/2021-01-01/capacities/id_subscription_test.go index 657d640e764d..5dd88810947b 100644 --- a/internal/services/powerbi/sdk/2021-01-01/capacities/id_subscription_test.go +++ b/internal/services/powerbi/sdk/2021-01-01/capacities/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/powerbi/sdk/2021-01-01/capacities/model_systemdata.go b/internal/services/powerbi/sdk/2021-01-01/capacities/model_systemdata.go index d8b8d1a84afc..f6c63b0abe30 100644 --- a/internal/services/powerbi/sdk/2021-01-01/capacities/model_systemdata.go +++ b/internal/services/powerbi/sdk/2021-01-01/capacities/model_systemdata.go @@ -1,11 +1,5 @@ package capacities -import ( - "time" - - "github.com/hashicorp/go-azure-helpers/lang/dates" -) - type SystemData struct { CreatedAt *string `json:"createdAt,omitempty"` CreatedBy *string `json:"createdBy,omitempty"` @@ -14,21 +8,3 @@ type SystemData struct { LastModifiedBy *string `json:"lastModifiedBy,omitempty"` LastModifiedByType *IdentityType `json:"lastModifiedByType,omitempty"` } - -func (o SystemData) GetCreatedAtAsTime() (*time.Time, error) { - 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) { - 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/powerbi/sdk/2021-01-01/powerbidedicated/client.go b/internal/services/powerbi/sdk/2021-01-01/powerbidedicated/client.go new file mode 100644 index 000000000000..634a13539d50 --- /dev/null +++ b/internal/services/powerbi/sdk/2021-01-01/powerbidedicated/client.go @@ -0,0 +1,15 @@ +package powerbidedicated + +import "github.com/Azure/go-autorest/autorest" + +type PowerBIDedicatedClient struct { + Client autorest.Client + baseUri string +} + +func NewPowerBIDedicatedClientWithBaseURI(endpoint string) PowerBIDedicatedClient { + return PowerBIDedicatedClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/internal/services/powerbi/sdk/2021-01-01/powerbidedicated/constants.go b/internal/services/powerbi/sdk/2021-01-01/powerbidedicated/constants.go new file mode 100644 index 000000000000..fd2ea43d5eb4 --- /dev/null +++ b/internal/services/powerbi/sdk/2021-01-01/powerbidedicated/constants.go @@ -0,0 +1,34 @@ +package powerbidedicated + +import "strings" + +type CapacitySkuTier string + +const ( + CapacitySkuTierAutoPremiumHost CapacitySkuTier = "AutoPremiumHost" + CapacitySkuTierPBIEAzure CapacitySkuTier = "PBIE_Azure" + CapacitySkuTierPremium CapacitySkuTier = "Premium" +) + +func PossibleValuesForCapacitySkuTier() []string { + return []string{ + string(CapacitySkuTierAutoPremiumHost), + string(CapacitySkuTierPBIEAzure), + string(CapacitySkuTierPremium), + } +} + +func parseCapacitySkuTier(input string) (*CapacitySkuTier, error) { + vals := map[string]CapacitySkuTier{ + "autopremiumhost": CapacitySkuTierAutoPremiumHost, + "pbie_azure": CapacitySkuTierPBIEAzure, + "premium": CapacitySkuTierPremium, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CapacitySkuTier(input) + return &out, nil +} diff --git a/internal/services/powerbi/sdk/2021-01-01/powerbidedicated/id_subscription.go b/internal/services/powerbi/sdk/2021-01-01/powerbidedicated/id_subscription.go new file mode 100644 index 000000000000..97a9436f9a7e --- /dev/null +++ b/internal/services/powerbi/sdk/2021-01-01/powerbidedicated/id_subscription.go @@ -0,0 +1,96 @@ +package powerbidedicated + +import ( + "fmt" + "strings" + + "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, + } +} + +// ParseSubscriptionID parses 'input' into a SubscriptionId +func ParseSubscriptionID(input string) (*SubscriptionId, error) { + parser := resourceids.NewParserFromResourceIdType(SubscriptionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + 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) + } + + return &id, nil +} + +// 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) { + parser := resourceids.NewParserFromResourceIdType(SubscriptionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + 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) + } + + 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 := ParseSubscriptionID(v); err != nil { + errors = append(errors, err) + } + + 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/powerbi/sdk/2021-01-01/powerbidedicated/id_subscription_test.go b/internal/services/powerbi/sdk/2021-01-01/powerbidedicated/id_subscription_test.go new file mode 100644 index 000000000000..5cb0fafce41a --- /dev/null +++ b/internal/services/powerbi/sdk/2021-01-01/powerbidedicated/id_subscription_test.go @@ -0,0 +1,144 @@ +package powerbidedicated + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = 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 the Formatted ID to be %q but got %q", actual, expected) + } +} + +func TestParseSubscriptionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SubscriptionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Expected: &SubscriptionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + }, + }, + { + // 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) + + actual, err := ParseSubscriptionID(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) + } + + } +} + +func TestParseSubscriptionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SubscriptionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Expected: &SubscriptionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Expected: &SubscriptionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + }, + }, + { + // 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) + + actual, err := ParseSubscriptionIDInsensitively(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) + } + + } +} diff --git a/internal/services/powerbi/sdk/2021-01-01/powerbidedicated/method_capacitieslistskus_autorest.go b/internal/services/powerbi/sdk/2021-01-01/powerbidedicated/method_capacitieslistskus_autorest.go new file mode 100644 index 000000000000..0554f907df48 --- /dev/null +++ b/internal/services/powerbi/sdk/2021-01-01/powerbidedicated/method_capacitieslistskus_autorest.go @@ -0,0 +1,65 @@ +package powerbidedicated + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +type CapacitiesListSkusResponse struct { + HttpResponse *http.Response + Model *SkuEnumerationForNewResourceResult +} + +// CapacitiesListSkus ... +func (c PowerBIDedicatedClient) CapacitiesListSkus(ctx context.Context, id SubscriptionId) (result CapacitiesListSkusResponse, err error) { + req, err := c.preparerForCapacitiesListSkus(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "powerbidedicated.PowerBIDedicatedClient", "CapacitiesListSkus", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "powerbidedicated.PowerBIDedicatedClient", "CapacitiesListSkus", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForCapacitiesListSkus(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "powerbidedicated.PowerBIDedicatedClient", "CapacitiesListSkus", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForCapacitiesListSkus prepares the CapacitiesListSkus request. +func (c PowerBIDedicatedClient) preparerForCapacitiesListSkus(ctx context.Context, id SubscriptionId) (*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/providers/Microsoft.PowerBIDedicated/skus", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForCapacitiesListSkus handles the response to the CapacitiesListSkus request. The method always +// closes the http.Response Body. +func (c PowerBIDedicatedClient) responderForCapacitiesListSkus(resp *http.Response) (result CapacitiesListSkusResponse, 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/powerbi/sdk/2021-01-01/powerbidedicated/model_capacitysku.go b/internal/services/powerbi/sdk/2021-01-01/powerbidedicated/model_capacitysku.go new file mode 100644 index 000000000000..6995f07253f8 --- /dev/null +++ b/internal/services/powerbi/sdk/2021-01-01/powerbidedicated/model_capacitysku.go @@ -0,0 +1,6 @@ +package powerbidedicated + +type CapacitySku struct { + Name string `json:"name"` + Tier *CapacitySkuTier `json:"tier,omitempty"` +} diff --git a/internal/services/powerbi/sdk/2021-01-01/powerbidedicated/model_skuenumerationfornewresourceresult.go b/internal/services/powerbi/sdk/2021-01-01/powerbidedicated/model_skuenumerationfornewresourceresult.go new file mode 100644 index 000000000000..846266cd7a7b --- /dev/null +++ b/internal/services/powerbi/sdk/2021-01-01/powerbidedicated/model_skuenumerationfornewresourceresult.go @@ -0,0 +1,5 @@ +package powerbidedicated + +type SkuEnumerationForNewResourceResult struct { + Value *[]CapacitySku `json:"value,omitempty"` +} diff --git a/internal/services/powerbi/sdk/2021-01-01/powerbidedicated/version.go b/internal/services/powerbi/sdk/2021-01-01/powerbidedicated/version.go new file mode 100644 index 000000000000..e34e7140761d --- /dev/null +++ b/internal/services/powerbi/sdk/2021-01-01/powerbidedicated/version.go @@ -0,0 +1,9 @@ +package powerbidedicated + +import "fmt" + +const defaultApiVersion = "2021-01-01" + +func userAgent() string { + return fmt.Sprintf("pandora/powerbidedicated/%s", defaultApiVersion) +}