diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/application/client.go b/resource-manager/desktopvirtualization/2021-09-03-preview/application/client.go new file mode 100644 index 00000000000..56913082b95 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/application/client.go @@ -0,0 +1,18 @@ +package application + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApplicationClient struct { + Client autorest.Client + baseUri string +} + +func NewApplicationClientWithBaseURI(endpoint string) ApplicationClient { + return ApplicationClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/application/constants.go b/resource-manager/desktopvirtualization/2021-09-03-preview/application/constants.go new file mode 100644 index 00000000000..5b2bf0a7cd4 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/application/constants.go @@ -0,0 +1,65 @@ +package application + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CommandLineSetting string + +const ( + CommandLineSettingAllow CommandLineSetting = "Allow" + CommandLineSettingDoNotAllow CommandLineSetting = "DoNotAllow" + CommandLineSettingRequire CommandLineSetting = "Require" +) + +func PossibleValuesForCommandLineSetting() []string { + return []string{ + string(CommandLineSettingAllow), + string(CommandLineSettingDoNotAllow), + string(CommandLineSettingRequire), + } +} + +func parseCommandLineSetting(input string) (*CommandLineSetting, error) { + vals := map[string]CommandLineSetting{ + "allow": CommandLineSettingAllow, + "donotallow": CommandLineSettingDoNotAllow, + "require": CommandLineSettingRequire, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CommandLineSetting(input) + return &out, nil +} + +type RemoteApplicationType string + +const ( + RemoteApplicationTypeInBuilt RemoteApplicationType = "InBuilt" + RemoteApplicationTypeMsixApplication RemoteApplicationType = "MsixApplication" +) + +func PossibleValuesForRemoteApplicationType() []string { + return []string{ + string(RemoteApplicationTypeInBuilt), + string(RemoteApplicationTypeMsixApplication), + } +} + +func parseRemoteApplicationType(input string) (*RemoteApplicationType, error) { + vals := map[string]RemoteApplicationType{ + "inbuilt": RemoteApplicationTypeInBuilt, + "msixapplication": RemoteApplicationTypeMsixApplication, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RemoteApplicationType(input) + return &out, nil +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/application/id_application.go b/resource-manager/desktopvirtualization/2021-09-03-preview/application/id_application.go new file mode 100644 index 00000000000..e5609ed2b7f --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/application/id_application.go @@ -0,0 +1,137 @@ +package application + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = ApplicationId{} + +// ApplicationId is a struct representing the Resource ID for a Application +type ApplicationId struct { + SubscriptionId string + ResourceGroupName string + ApplicationGroupName string + ApplicationName string +} + +// NewApplicationID returns a new ApplicationId struct +func NewApplicationID(subscriptionId string, resourceGroupName string, applicationGroupName string, applicationName string) ApplicationId { + return ApplicationId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ApplicationGroupName: applicationGroupName, + ApplicationName: applicationName, + } +} + +// ParseApplicationID parses 'input' into a ApplicationId +func ParseApplicationID(input string) (*ApplicationId, error) { + parser := resourceids.NewParserFromResourceIdType(ApplicationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ApplicationId{} + + 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.ApplicationGroupName, ok = parsed.Parsed["applicationGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'applicationGroupName' was not found in the resource id %q", input) + } + + if id.ApplicationName, ok = parsed.Parsed["applicationName"]; !ok { + return nil, fmt.Errorf("the segment 'applicationName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseApplicationIDInsensitively parses 'input' case-insensitively into a ApplicationId +// note: this method should only be used for API response data and not user input +func ParseApplicationIDInsensitively(input string) (*ApplicationId, error) { + parser := resourceids.NewParserFromResourceIdType(ApplicationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ApplicationId{} + + 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.ApplicationGroupName, ok = parsed.Parsed["applicationGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'applicationGroupName' was not found in the resource id %q", input) + } + + if id.ApplicationName, ok = parsed.Parsed["applicationName"]; !ok { + return nil, fmt.Errorf("the segment 'applicationName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateApplicationID checks that 'input' can be parsed as a Application ID +func ValidateApplicationID(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 := ParseApplicationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Application ID +func (id ApplicationId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DesktopVirtualization/applicationGroups/%s/applications/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ApplicationGroupName, id.ApplicationName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Application ID +func (id ApplicationId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftDesktopVirtualization", "Microsoft.DesktopVirtualization", "Microsoft.DesktopVirtualization"), + resourceids.StaticSegment("staticApplicationGroups", "applicationGroups", "applicationGroups"), + resourceids.UserSpecifiedSegment("applicationGroupName", "applicationGroupValue"), + resourceids.StaticSegment("staticApplications", "applications", "applications"), + resourceids.UserSpecifiedSegment("applicationName", "applicationValue"), + } +} + +// String returns a human-readable description of this Application ID +func (id ApplicationId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Application Group Name: %q", id.ApplicationGroupName), + fmt.Sprintf("Application Name: %q", id.ApplicationName), + } + return fmt.Sprintf("Application (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/application/id_application_test.go b/resource-manager/desktopvirtualization/2021-09-03-preview/application/id_application_test.go new file mode 100644 index 00000000000..255e35ace80 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/application/id_application_test.go @@ -0,0 +1,324 @@ +package application + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = ApplicationId{} + +func TestNewApplicationID(t *testing.T) { + id := NewApplicationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "applicationGroupValue", "applicationValue") + + 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.ApplicationGroupName != "applicationGroupValue" { + t.Fatalf("Expected %q but got %q for Segment 'ApplicationGroupName'", id.ApplicationGroupName, "applicationGroupValue") + } + + if id.ApplicationName != "applicationValue" { + t.Fatalf("Expected %q but got %q for Segment 'ApplicationName'", id.ApplicationName, "applicationValue") + } +} + +func TestFormatApplicationID(t *testing.T) { + actual := NewApplicationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "applicationGroupValue", "applicationValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue/applications/applicationValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseApplicationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApplicationId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue/applications", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue/applications/applicationValue", + Expected: &ApplicationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ApplicationGroupName: "applicationGroupValue", + ApplicationName: "applicationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue/applications/applicationValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApplicationID(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.ApplicationGroupName != v.Expected.ApplicationGroupName { + t.Fatalf("Expected %q but got %q for ApplicationGroupName", v.Expected.ApplicationGroupName, actual.ApplicationGroupName) + } + + if actual.ApplicationName != v.Expected.ApplicationName { + t.Fatalf("Expected %q but got %q for ApplicationName", v.Expected.ApplicationName, actual.ApplicationName) + } + + } +} + +func TestParseApplicationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApplicationId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/aPpLiCaTiOnGrOuPs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/aPpLiCaTiOnGrOuPs/aPpLiCaTiOnGrOuPvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue/applications", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/aPpLiCaTiOnGrOuPs/aPpLiCaTiOnGrOuPvAlUe/aPpLiCaTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue/applications/applicationValue", + Expected: &ApplicationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ApplicationGroupName: "applicationGroupValue", + ApplicationName: "applicationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue/applications/applicationValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/aPpLiCaTiOnGrOuPs/aPpLiCaTiOnGrOuPvAlUe/aPpLiCaTiOnS/aPpLiCaTiOnVaLuE", + Expected: &ApplicationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ApplicationGroupName: "aPpLiCaTiOnGrOuPvAlUe", + ApplicationName: "aPpLiCaTiOnVaLuE", + }, + }, + { + // 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.dEsKtOpViRtUaLiZaTiOn/aPpLiCaTiOnGrOuPs/aPpLiCaTiOnGrOuPvAlUe/aPpLiCaTiOnS/aPpLiCaTiOnVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApplicationIDInsensitively(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.ApplicationGroupName != v.Expected.ApplicationGroupName { + t.Fatalf("Expected %q but got %q for ApplicationGroupName", v.Expected.ApplicationGroupName, actual.ApplicationGroupName) + } + + if actual.ApplicationName != v.Expected.ApplicationName { + t.Fatalf("Expected %q but got %q for ApplicationName", v.Expected.ApplicationName, actual.ApplicationName) + } + + } +} + +func TestSegmentsForApplicationId(t *testing.T) { + segments := ApplicationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ApplicationId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/application/id_applicationgroup.go b/resource-manager/desktopvirtualization/2021-09-03-preview/application/id_applicationgroup.go new file mode 100644 index 00000000000..74e10313b6a --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/application/id_applicationgroup.go @@ -0,0 +1,124 @@ +package application + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = ApplicationGroupId{} + +// ApplicationGroupId is a struct representing the Resource ID for a Application Group +type ApplicationGroupId struct { + SubscriptionId string + ResourceGroupName string + ApplicationGroupName string +} + +// NewApplicationGroupID returns a new ApplicationGroupId struct +func NewApplicationGroupID(subscriptionId string, resourceGroupName string, applicationGroupName string) ApplicationGroupId { + return ApplicationGroupId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ApplicationGroupName: applicationGroupName, + } +} + +// ParseApplicationGroupID parses 'input' into a ApplicationGroupId +func ParseApplicationGroupID(input string) (*ApplicationGroupId, error) { + parser := resourceids.NewParserFromResourceIdType(ApplicationGroupId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ApplicationGroupId{} + + 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.ApplicationGroupName, ok = parsed.Parsed["applicationGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'applicationGroupName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseApplicationGroupIDInsensitively parses 'input' case-insensitively into a ApplicationGroupId +// note: this method should only be used for API response data and not user input +func ParseApplicationGroupIDInsensitively(input string) (*ApplicationGroupId, error) { + parser := resourceids.NewParserFromResourceIdType(ApplicationGroupId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ApplicationGroupId{} + + 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.ApplicationGroupName, ok = parsed.Parsed["applicationGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'applicationGroupName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateApplicationGroupID checks that 'input' can be parsed as a Application Group ID +func ValidateApplicationGroupID(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 := ParseApplicationGroupID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Application Group ID +func (id ApplicationGroupId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DesktopVirtualization/applicationGroups/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ApplicationGroupName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Application Group ID +func (id ApplicationGroupId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftDesktopVirtualization", "Microsoft.DesktopVirtualization", "Microsoft.DesktopVirtualization"), + resourceids.StaticSegment("staticApplicationGroups", "applicationGroups", "applicationGroups"), + resourceids.UserSpecifiedSegment("applicationGroupName", "applicationGroupValue"), + } +} + +// String returns a human-readable description of this Application Group ID +func (id ApplicationGroupId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Application Group Name: %q", id.ApplicationGroupName), + } + return fmt.Sprintf("Application Group (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/application/id_applicationgroup_test.go b/resource-manager/desktopvirtualization/2021-09-03-preview/application/id_applicationgroup_test.go new file mode 100644 index 00000000000..80b402a5a80 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/application/id_applicationgroup_test.go @@ -0,0 +1,279 @@ +package application + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = ApplicationGroupId{} + +func TestNewApplicationGroupID(t *testing.T) { + id := NewApplicationGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "applicationGroupValue") + + 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.ApplicationGroupName != "applicationGroupValue" { + t.Fatalf("Expected %q but got %q for Segment 'ApplicationGroupName'", id.ApplicationGroupName, "applicationGroupValue") + } +} + +func TestFormatApplicationGroupID(t *testing.T) { + actual := NewApplicationGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "applicationGroupValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseApplicationGroupID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApplicationGroupId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue", + Expected: &ApplicationGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ApplicationGroupName: "applicationGroupValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApplicationGroupID(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.ApplicationGroupName != v.Expected.ApplicationGroupName { + t.Fatalf("Expected %q but got %q for ApplicationGroupName", v.Expected.ApplicationGroupName, actual.ApplicationGroupName) + } + + } +} + +func TestParseApplicationGroupIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApplicationGroupId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/aPpLiCaTiOnGrOuPs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue", + Expected: &ApplicationGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ApplicationGroupName: "applicationGroupValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/aPpLiCaTiOnGrOuPs/aPpLiCaTiOnGrOuPvAlUe", + Expected: &ApplicationGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ApplicationGroupName: "aPpLiCaTiOnGrOuPvAlUe", + }, + }, + { + // 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.dEsKtOpViRtUaLiZaTiOn/aPpLiCaTiOnGrOuPs/aPpLiCaTiOnGrOuPvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApplicationGroupIDInsensitively(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.ApplicationGroupName != v.Expected.ApplicationGroupName { + t.Fatalf("Expected %q but got %q for ApplicationGroupName", v.Expected.ApplicationGroupName, actual.ApplicationGroupName) + } + + } +} + +func TestSegmentsForApplicationGroupId(t *testing.T) { + segments := ApplicationGroupId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ApplicationGroupId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/application/method_createorupdate_autorest.go b/resource-manager/desktopvirtualization/2021-09-03-preview/application/method_createorupdate_autorest.go new file mode 100644 index 00000000000..667a27450cc --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/application/method_createorupdate_autorest.go @@ -0,0 +1,68 @@ +package application + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + Model *Application +} + +// CreateOrUpdate ... +func (c ApplicationClient) CreateOrUpdate(ctx context.Context, id ApplicationId, input Application) (result CreateOrUpdateOperationResponse, err error) { + req, err := c.preparerForCreateOrUpdate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "application.ApplicationClient", "CreateOrUpdate", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "application.ApplicationClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForCreateOrUpdate(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "application.ApplicationClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForCreateOrUpdate prepares the CreateOrUpdate request. +func (c ApplicationClient) preparerForCreateOrUpdate(ctx context.Context, id ApplicationId, input Application) (*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)) +} + +// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always +// closes the http.Response Body. +func (c ApplicationClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/application/method_delete_autorest.go b/resource-manager/desktopvirtualization/2021-09-03-preview/application/method_delete_autorest.go new file mode 100644 index 00000000000..0bb3f01ae02 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/application/method_delete_autorest.go @@ -0,0 +1,65 @@ +package application + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response +} + +// Delete ... +func (c ApplicationClient) Delete(ctx context.Context, id ApplicationId) (result DeleteOperationResponse, err error) { + req, err := c.preparerForDelete(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "application.ApplicationClient", "Delete", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "application.ApplicationClient", "Delete", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForDelete(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "application.ApplicationClient", "Delete", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForDelete prepares the Delete request. +func (c ApplicationClient) preparerForDelete(ctx context.Context, id ApplicationId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + 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 ApplicationClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/application/method_get_autorest.go b/resource-manager/desktopvirtualization/2021-09-03-preview/application/method_get_autorest.go new file mode 100644 index 00000000000..7c04468f2c8 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/application/method_get_autorest.go @@ -0,0 +1,67 @@ +package application + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *Application +} + +// Get ... +func (c ApplicationClient) Get(ctx context.Context, id ApplicationId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "application.ApplicationClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "application.ApplicationClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "application.ApplicationClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c ApplicationClient) preparerForGet(ctx context.Context, id ApplicationId) (*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 ApplicationClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/application/method_list_autorest.go b/resource-manager/desktopvirtualization/2021-09-03-preview/application/method_list_autorest.go new file mode 100644 index 00000000000..6810fcb1719 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/application/method_list_autorest.go @@ -0,0 +1,186 @@ +package application + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + Model *[]Application + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) +} + +type ListCompleteResult struct { + Items []Application +} + +func (r ListOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// List ... +func (c ApplicationClient) List(ctx context.Context, id ApplicationGroupId) (resp ListOperationResponse, err error) { + req, err := c.preparerForList(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "application.ApplicationClient", "List", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "application.ApplicationClient", "List", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForList(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "application.ApplicationClient", "List", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// ListComplete retrieves all of the results into a single object +func (c ApplicationClient) ListComplete(ctx context.Context, id ApplicationGroupId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, ApplicationOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c ApplicationClient) ListCompleteMatchingPredicate(ctx context.Context, id ApplicationGroupId, predicate ApplicationOperationPredicate) (resp ListCompleteResult, err error) { + items := make([]Application, 0) + + page, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListCompleteResult{ + Items: items, + } + return out, nil +} + +// preparerForList prepares the List request. +func (c ApplicationClient) preparerForList(ctx context.Context, id ApplicationGroupId) (*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/applications", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListWithNextLink prepares the List request with the given nextLink token. +func (c ApplicationClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForList handles the response to the List request. The method always +// closes the http.Response Body. +func (c ApplicationClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { + type page struct { + Values []Application `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { + req, err := c.preparerForListWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "application.ApplicationClient", "List", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "application.ApplicationClient", "List", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "application.ApplicationClient", "List", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/application/method_update_autorest.go b/resource-manager/desktopvirtualization/2021-09-03-preview/application/method_update_autorest.go new file mode 100644 index 00000000000..ac806964944 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/application/method_update_autorest.go @@ -0,0 +1,68 @@ +package application + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + HttpResponse *http.Response + Model *Application +} + +// Update ... +func (c ApplicationClient) Update(ctx context.Context, id ApplicationId, input ApplicationPatch) (result UpdateOperationResponse, err error) { + req, err := c.preparerForUpdate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "application.ApplicationClient", "Update", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "application.ApplicationClient", "Update", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForUpdate(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "application.ApplicationClient", "Update", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForUpdate prepares the Update request. +func (c ApplicationClient) preparerForUpdate(ctx context.Context, id ApplicationId, input ApplicationPatch) (*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 ApplicationClient) responderForUpdate(resp *http.Response) (result UpdateOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/application/model_application.go b/resource-manager/desktopvirtualization/2021-09-03-preview/application/model_application.go new file mode 100644 index 00000000000..700c972b9de --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/application/model_application.go @@ -0,0 +1,16 @@ +package application + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Application struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties ApplicationProperties `json:"properties"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/application/model_applicationpatch.go b/resource-manager/desktopvirtualization/2021-09-03-preview/application/model_applicationpatch.go new file mode 100644 index 00000000000..5b0e7d1a071 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/application/model_applicationpatch.go @@ -0,0 +1,9 @@ +package application + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApplicationPatch struct { + Properties *ApplicationPatchProperties `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/application/model_applicationpatchproperties.go b/resource-manager/desktopvirtualization/2021-09-03-preview/application/model_applicationpatchproperties.go new file mode 100644 index 00000000000..ada985872c6 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/application/model_applicationpatchproperties.go @@ -0,0 +1,18 @@ +package application + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApplicationPatchProperties struct { + ApplicationType *RemoteApplicationType `json:"applicationType,omitempty"` + CommandLineArguments *string `json:"commandLineArguments,omitempty"` + CommandLineSetting *CommandLineSetting `json:"commandLineSetting,omitempty"` + Description *string `json:"description,omitempty"` + FilePath *string `json:"filePath,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + IconIndex *int64 `json:"iconIndex,omitempty"` + IconPath *string `json:"iconPath,omitempty"` + MsixPackageApplicationId *string `json:"msixPackageApplicationId,omitempty"` + MsixPackageFamilyName *string `json:"msixPackageFamilyName,omitempty"` + ShowInPortal *bool `json:"showInPortal,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/application/model_applicationproperties.go b/resource-manager/desktopvirtualization/2021-09-03-preview/application/model_applicationproperties.go new file mode 100644 index 00000000000..74362ae1d50 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/application/model_applicationproperties.go @@ -0,0 +1,21 @@ +package application + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApplicationProperties struct { + ApplicationType *RemoteApplicationType `json:"applicationType,omitempty"` + CommandLineArguments *string `json:"commandLineArguments,omitempty"` + CommandLineSetting CommandLineSetting `json:"commandLineSetting"` + Description *string `json:"description,omitempty"` + FilePath *string `json:"filePath,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + IconContent *string `json:"iconContent,omitempty"` + IconHash *string `json:"iconHash,omitempty"` + IconIndex *int64 `json:"iconIndex,omitempty"` + IconPath *string `json:"iconPath,omitempty"` + MsixPackageApplicationId *string `json:"msixPackageApplicationId,omitempty"` + MsixPackageFamilyName *string `json:"msixPackageFamilyName,omitempty"` + ObjectId *string `json:"objectId,omitempty"` + ShowInPortal *bool `json:"showInPortal,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/application/predicates.go b/resource-manager/desktopvirtualization/2021-09-03-preview/application/predicates.go new file mode 100644 index 00000000000..82c6b7d376d --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/application/predicates.go @@ -0,0 +1,24 @@ +package application + +type ApplicationOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ApplicationOperationPredicate) Matches(input Application) bool { + + if p.Id != nil && (input.Id == nil && *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil && *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil && *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/application/version.go b/resource-manager/desktopvirtualization/2021-09-03-preview/application/version.go new file mode 100644 index 00000000000..b3bd5a71e05 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/application/version.go @@ -0,0 +1,12 @@ +package application + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2021-09-03-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/application/%s", defaultApiVersion) +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/applicationgroup/client.go b/resource-manager/desktopvirtualization/2021-09-03-preview/applicationgroup/client.go new file mode 100644 index 00000000000..20ca14a850a --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/applicationgroup/client.go @@ -0,0 +1,18 @@ +package applicationgroup + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApplicationGroupClient struct { + Client autorest.Client + baseUri string +} + +func NewApplicationGroupClientWithBaseURI(endpoint string) ApplicationGroupClient { + return ApplicationGroupClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/applicationgroup/constants.go b/resource-manager/desktopvirtualization/2021-09-03-preview/applicationgroup/constants.go new file mode 100644 index 00000000000..a24e7261f53 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/applicationgroup/constants.go @@ -0,0 +1,105 @@ +package applicationgroup + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApplicationGroupType string + +const ( + ApplicationGroupTypeDesktop ApplicationGroupType = "Desktop" + ApplicationGroupTypeRemoteApp ApplicationGroupType = "RemoteApp" +) + +func PossibleValuesForApplicationGroupType() []string { + return []string{ + string(ApplicationGroupTypeDesktop), + string(ApplicationGroupTypeRemoteApp), + } +} + +func parseApplicationGroupType(input string) (*ApplicationGroupType, error) { + vals := map[string]ApplicationGroupType{ + "desktop": ApplicationGroupTypeDesktop, + "remoteapp": ApplicationGroupTypeRemoteApp, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ApplicationGroupType(input) + return &out, nil +} + +type Operation string + +const ( + OperationComplete Operation = "Complete" + OperationHide Operation = "Hide" + OperationRevoke Operation = "Revoke" + OperationStart Operation = "Start" + OperationUnhide Operation = "Unhide" +) + +func PossibleValuesForOperation() []string { + return []string{ + string(OperationComplete), + string(OperationHide), + string(OperationRevoke), + string(OperationStart), + string(OperationUnhide), + } +} + +func parseOperation(input string) (*Operation, error) { + vals := map[string]Operation{ + "complete": OperationComplete, + "hide": OperationHide, + "revoke": OperationRevoke, + "start": OperationStart, + "unhide": OperationUnhide, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Operation(input) + return &out, nil +} + +type SkuTier string + +const ( + SkuTierBasic SkuTier = "Basic" + SkuTierFree SkuTier = "Free" + SkuTierPremium SkuTier = "Premium" + SkuTierStandard SkuTier = "Standard" +) + +func PossibleValuesForSkuTier() []string { + return []string{ + string(SkuTierBasic), + string(SkuTierFree), + string(SkuTierPremium), + string(SkuTierStandard), + } +} + +func parseSkuTier(input string) (*SkuTier, error) { + vals := map[string]SkuTier{ + "basic": SkuTierBasic, + "free": SkuTierFree, + "premium": SkuTierPremium, + "standard": SkuTierStandard, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SkuTier(input) + return &out, nil +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/applicationgroup/id_applicationgroup.go b/resource-manager/desktopvirtualization/2021-09-03-preview/applicationgroup/id_applicationgroup.go new file mode 100644 index 00000000000..6c20bd489e9 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/applicationgroup/id_applicationgroup.go @@ -0,0 +1,124 @@ +package applicationgroup + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = ApplicationGroupId{} + +// ApplicationGroupId is a struct representing the Resource ID for a Application Group +type ApplicationGroupId struct { + SubscriptionId string + ResourceGroupName string + ApplicationGroupName string +} + +// NewApplicationGroupID returns a new ApplicationGroupId struct +func NewApplicationGroupID(subscriptionId string, resourceGroupName string, applicationGroupName string) ApplicationGroupId { + return ApplicationGroupId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ApplicationGroupName: applicationGroupName, + } +} + +// ParseApplicationGroupID parses 'input' into a ApplicationGroupId +func ParseApplicationGroupID(input string) (*ApplicationGroupId, error) { + parser := resourceids.NewParserFromResourceIdType(ApplicationGroupId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ApplicationGroupId{} + + 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.ApplicationGroupName, ok = parsed.Parsed["applicationGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'applicationGroupName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseApplicationGroupIDInsensitively parses 'input' case-insensitively into a ApplicationGroupId +// note: this method should only be used for API response data and not user input +func ParseApplicationGroupIDInsensitively(input string) (*ApplicationGroupId, error) { + parser := resourceids.NewParserFromResourceIdType(ApplicationGroupId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ApplicationGroupId{} + + 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.ApplicationGroupName, ok = parsed.Parsed["applicationGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'applicationGroupName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateApplicationGroupID checks that 'input' can be parsed as a Application Group ID +func ValidateApplicationGroupID(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 := ParseApplicationGroupID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Application Group ID +func (id ApplicationGroupId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DesktopVirtualization/applicationGroups/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ApplicationGroupName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Application Group ID +func (id ApplicationGroupId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftDesktopVirtualization", "Microsoft.DesktopVirtualization", "Microsoft.DesktopVirtualization"), + resourceids.StaticSegment("staticApplicationGroups", "applicationGroups", "applicationGroups"), + resourceids.UserSpecifiedSegment("applicationGroupName", "applicationGroupValue"), + } +} + +// String returns a human-readable description of this Application Group ID +func (id ApplicationGroupId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Application Group Name: %q", id.ApplicationGroupName), + } + return fmt.Sprintf("Application Group (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/applicationgroup/id_applicationgroup_test.go b/resource-manager/desktopvirtualization/2021-09-03-preview/applicationgroup/id_applicationgroup_test.go new file mode 100644 index 00000000000..253650b9f15 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/applicationgroup/id_applicationgroup_test.go @@ -0,0 +1,279 @@ +package applicationgroup + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = ApplicationGroupId{} + +func TestNewApplicationGroupID(t *testing.T) { + id := NewApplicationGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "applicationGroupValue") + + 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.ApplicationGroupName != "applicationGroupValue" { + t.Fatalf("Expected %q but got %q for Segment 'ApplicationGroupName'", id.ApplicationGroupName, "applicationGroupValue") + } +} + +func TestFormatApplicationGroupID(t *testing.T) { + actual := NewApplicationGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "applicationGroupValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseApplicationGroupID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApplicationGroupId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue", + Expected: &ApplicationGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ApplicationGroupName: "applicationGroupValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApplicationGroupID(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.ApplicationGroupName != v.Expected.ApplicationGroupName { + t.Fatalf("Expected %q but got %q for ApplicationGroupName", v.Expected.ApplicationGroupName, actual.ApplicationGroupName) + } + + } +} + +func TestParseApplicationGroupIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApplicationGroupId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/aPpLiCaTiOnGrOuPs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue", + Expected: &ApplicationGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ApplicationGroupName: "applicationGroupValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/aPpLiCaTiOnGrOuPs/aPpLiCaTiOnGrOuPvAlUe", + Expected: &ApplicationGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ApplicationGroupName: "aPpLiCaTiOnGrOuPvAlUe", + }, + }, + { + // 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.dEsKtOpViRtUaLiZaTiOn/aPpLiCaTiOnGrOuPs/aPpLiCaTiOnGrOuPvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApplicationGroupIDInsensitively(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.ApplicationGroupName != v.Expected.ApplicationGroupName { + t.Fatalf("Expected %q but got %q for ApplicationGroupName", v.Expected.ApplicationGroupName, actual.ApplicationGroupName) + } + + } +} + +func TestSegmentsForApplicationGroupId(t *testing.T) { + segments := ApplicationGroupId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ApplicationGroupId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/applicationgroup/method_createorupdate_autorest.go b/resource-manager/desktopvirtualization/2021-09-03-preview/applicationgroup/method_createorupdate_autorest.go new file mode 100644 index 00000000000..268106c8d09 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/applicationgroup/method_createorupdate_autorest.go @@ -0,0 +1,68 @@ +package applicationgroup + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + Model *ApplicationGroup +} + +// CreateOrUpdate ... +func (c ApplicationGroupClient) CreateOrUpdate(ctx context.Context, id ApplicationGroupId, input ApplicationGroup) (result CreateOrUpdateOperationResponse, err error) { + req, err := c.preparerForCreateOrUpdate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "applicationgroup.ApplicationGroupClient", "CreateOrUpdate", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "applicationgroup.ApplicationGroupClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForCreateOrUpdate(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "applicationgroup.ApplicationGroupClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForCreateOrUpdate prepares the CreateOrUpdate request. +func (c ApplicationGroupClient) preparerForCreateOrUpdate(ctx context.Context, id ApplicationGroupId, input ApplicationGroup) (*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)) +} + +// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always +// closes the http.Response Body. +func (c ApplicationGroupClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/applicationgroup/method_delete_autorest.go b/resource-manager/desktopvirtualization/2021-09-03-preview/applicationgroup/method_delete_autorest.go new file mode 100644 index 00000000000..981983b00a9 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/applicationgroup/method_delete_autorest.go @@ -0,0 +1,65 @@ +package applicationgroup + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response +} + +// Delete ... +func (c ApplicationGroupClient) Delete(ctx context.Context, id ApplicationGroupId) (result DeleteOperationResponse, err error) { + req, err := c.preparerForDelete(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "applicationgroup.ApplicationGroupClient", "Delete", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "applicationgroup.ApplicationGroupClient", "Delete", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForDelete(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "applicationgroup.ApplicationGroupClient", "Delete", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForDelete prepares the Delete request. +func (c ApplicationGroupClient) preparerForDelete(ctx context.Context, id ApplicationGroupId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + 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 ApplicationGroupClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/applicationgroup/method_get_autorest.go b/resource-manager/desktopvirtualization/2021-09-03-preview/applicationgroup/method_get_autorest.go new file mode 100644 index 00000000000..77376fc5b5c --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/applicationgroup/method_get_autorest.go @@ -0,0 +1,67 @@ +package applicationgroup + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *ApplicationGroup +} + +// Get ... +func (c ApplicationGroupClient) Get(ctx context.Context, id ApplicationGroupId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "applicationgroup.ApplicationGroupClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "applicationgroup.ApplicationGroupClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "applicationgroup.ApplicationGroupClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c ApplicationGroupClient) preparerForGet(ctx context.Context, id ApplicationGroupId) (*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 ApplicationGroupClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/applicationgroup/method_listbyresourcegroup_autorest.go b/resource-manager/desktopvirtualization/2021-09-03-preview/applicationgroup/method_listbyresourcegroup_autorest.go new file mode 100644 index 00000000000..16186a1f419 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/applicationgroup/method_listbyresourcegroup_autorest.go @@ -0,0 +1,216 @@ +package applicationgroup + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByResourceGroupOperationResponse struct { + HttpResponse *http.Response + Model *[]ApplicationGroup + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListByResourceGroupOperationResponse, error) +} + +type ListByResourceGroupCompleteResult struct { + Items []ApplicationGroup +} + +func (r ListByResourceGroupOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListByResourceGroupOperationResponse) LoadMore(ctx context.Context) (resp ListByResourceGroupOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +type ListByResourceGroupOperationOptions struct { + Filter *string +} + +func DefaultListByResourceGroupOperationOptions() ListByResourceGroupOperationOptions { + return ListByResourceGroupOperationOptions{} +} + +func (o ListByResourceGroupOperationOptions) toHeaders() map[string]interface{} { + out := make(map[string]interface{}) + + return out +} + +func (o ListByResourceGroupOperationOptions) toQueryString() map[string]interface{} { + out := make(map[string]interface{}) + + if o.Filter != nil { + out["$filter"] = *o.Filter + } + + return out +} + +// ListByResourceGroup ... +func (c ApplicationGroupClient) ListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions) (resp ListByResourceGroupOperationResponse, err error) { + req, err := c.preparerForListByResourceGroup(ctx, id, options) + if err != nil { + err = autorest.NewErrorWithError(err, "applicationgroup.ApplicationGroupClient", "ListByResourceGroup", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "applicationgroup.ApplicationGroupClient", "ListByResourceGroup", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForListByResourceGroup(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "applicationgroup.ApplicationGroupClient", "ListByResourceGroup", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// ListByResourceGroupComplete retrieves all of the results into a single object +func (c ApplicationGroupClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions) (ListByResourceGroupCompleteResult, error) { + return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, options, ApplicationGroupOperationPredicate{}) +} + +// ListByResourceGroupCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c ApplicationGroupClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions, predicate ApplicationGroupOperationPredicate) (resp ListByResourceGroupCompleteResult, err error) { + items := make([]ApplicationGroup, 0) + + page, err := c.ListByResourceGroup(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListByResourceGroupCompleteResult{ + Items: items, + } + return out, nil +} + +// preparerForListByResourceGroup prepares the ListByResourceGroup request. +func (c ApplicationGroupClient) preparerForListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + for k, v := range options.toQueryString() { + queryParameters[k] = autorest.Encode("query", v) + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithHeaders(options.toHeaders()), + autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.DesktopVirtualization/applicationGroups", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListByResourceGroupWithNextLink prepares the ListByResourceGroup request with the given nextLink token. +func (c ApplicationGroupClient) preparerForListByResourceGroupWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForListByResourceGroup handles the response to the ListByResourceGroup request. The method always +// closes the http.Response Body. +func (c ApplicationGroupClient) responderForListByResourceGroup(resp *http.Response) (result ListByResourceGroupOperationResponse, err error) { + type page struct { + Values []ApplicationGroup `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListByResourceGroupOperationResponse, err error) { + req, err := c.preparerForListByResourceGroupWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "applicationgroup.ApplicationGroupClient", "ListByResourceGroup", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "applicationgroup.ApplicationGroupClient", "ListByResourceGroup", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForListByResourceGroup(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "applicationgroup.ApplicationGroupClient", "ListByResourceGroup", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/applicationgroup/method_listbysubscription_autorest.go b/resource-manager/desktopvirtualization/2021-09-03-preview/applicationgroup/method_listbysubscription_autorest.go new file mode 100644 index 00000000000..18a438e150d --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/applicationgroup/method_listbysubscription_autorest.go @@ -0,0 +1,216 @@ +package applicationgroup + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListBySubscriptionOperationResponse struct { + HttpResponse *http.Response + Model *[]ApplicationGroup + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListBySubscriptionOperationResponse, error) +} + +type ListBySubscriptionCompleteResult struct { + Items []ApplicationGroup +} + +func (r ListBySubscriptionOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListBySubscriptionOperationResponse) LoadMore(ctx context.Context) (resp ListBySubscriptionOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +type ListBySubscriptionOperationOptions struct { + Filter *string +} + +func DefaultListBySubscriptionOperationOptions() ListBySubscriptionOperationOptions { + return ListBySubscriptionOperationOptions{} +} + +func (o ListBySubscriptionOperationOptions) toHeaders() map[string]interface{} { + out := make(map[string]interface{}) + + return out +} + +func (o ListBySubscriptionOperationOptions) toQueryString() map[string]interface{} { + out := make(map[string]interface{}) + + if o.Filter != nil { + out["$filter"] = *o.Filter + } + + return out +} + +// ListBySubscription ... +func (c ApplicationGroupClient) ListBySubscription(ctx context.Context, id commonids.SubscriptionId, options ListBySubscriptionOperationOptions) (resp ListBySubscriptionOperationResponse, err error) { + req, err := c.preparerForListBySubscription(ctx, id, options) + if err != nil { + err = autorest.NewErrorWithError(err, "applicationgroup.ApplicationGroupClient", "ListBySubscription", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "applicationgroup.ApplicationGroupClient", "ListBySubscription", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForListBySubscription(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "applicationgroup.ApplicationGroupClient", "ListBySubscription", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// ListBySubscriptionComplete retrieves all of the results into a single object +func (c ApplicationGroupClient) ListBySubscriptionComplete(ctx context.Context, id commonids.SubscriptionId, options ListBySubscriptionOperationOptions) (ListBySubscriptionCompleteResult, error) { + return c.ListBySubscriptionCompleteMatchingPredicate(ctx, id, options, ApplicationGroupOperationPredicate{}) +} + +// ListBySubscriptionCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c ApplicationGroupClient) ListBySubscriptionCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, options ListBySubscriptionOperationOptions, predicate ApplicationGroupOperationPredicate) (resp ListBySubscriptionCompleteResult, err error) { + items := make([]ApplicationGroup, 0) + + page, err := c.ListBySubscription(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListBySubscriptionCompleteResult{ + Items: items, + } + return out, nil +} + +// preparerForListBySubscription prepares the ListBySubscription request. +func (c ApplicationGroupClient) preparerForListBySubscription(ctx context.Context, id commonids.SubscriptionId, options ListBySubscriptionOperationOptions) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + for k, v := range options.toQueryString() { + queryParameters[k] = autorest.Encode("query", v) + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithHeaders(options.toHeaders()), + autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.DesktopVirtualization/applicationGroups", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListBySubscriptionWithNextLink prepares the ListBySubscription request with the given nextLink token. +func (c ApplicationGroupClient) preparerForListBySubscriptionWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForListBySubscription handles the response to the ListBySubscription request. The method always +// closes the http.Response Body. +func (c ApplicationGroupClient) responderForListBySubscription(resp *http.Response) (result ListBySubscriptionOperationResponse, err error) { + type page struct { + Values []ApplicationGroup `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListBySubscriptionOperationResponse, err error) { + req, err := c.preparerForListBySubscriptionWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "applicationgroup.ApplicationGroupClient", "ListBySubscription", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "applicationgroup.ApplicationGroupClient", "ListBySubscription", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForListBySubscription(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "applicationgroup.ApplicationGroupClient", "ListBySubscription", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/applicationgroup/method_update_autorest.go b/resource-manager/desktopvirtualization/2021-09-03-preview/applicationgroup/method_update_autorest.go new file mode 100644 index 00000000000..b8b18e55d46 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/applicationgroup/method_update_autorest.go @@ -0,0 +1,68 @@ +package applicationgroup + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + HttpResponse *http.Response + Model *ApplicationGroup +} + +// Update ... +func (c ApplicationGroupClient) Update(ctx context.Context, id ApplicationGroupId, input ApplicationGroupPatch) (result UpdateOperationResponse, err error) { + req, err := c.preparerForUpdate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "applicationgroup.ApplicationGroupClient", "Update", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "applicationgroup.ApplicationGroupClient", "Update", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForUpdate(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "applicationgroup.ApplicationGroupClient", "Update", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForUpdate prepares the Update request. +func (c ApplicationGroupClient) preparerForUpdate(ctx context.Context, id ApplicationGroupId, input ApplicationGroupPatch) (*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 ApplicationGroupClient) responderForUpdate(resp *http.Response) (result UpdateOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/applicationgroup/model_applicationgroup.go b/resource-manager/desktopvirtualization/2021-09-03-preview/applicationgroup/model_applicationgroup.go new file mode 100644 index 00000000000..afb13f5670b --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/applicationgroup/model_applicationgroup.go @@ -0,0 +1,25 @@ +package applicationgroup + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/identity" + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApplicationGroup struct { + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Identity *identity.SystemAssigned `json:"identity,omitempty"` + Kind *string `json:"kind,omitempty"` + Location *string `json:"location,omitempty"` + ManagedBy *string `json:"managedBy,omitempty"` + Name *string `json:"name,omitempty"` + Plan *Plan `json:"plan,omitempty"` + Properties ApplicationGroupProperties `json:"properties"` + Sku *Sku `json:"sku,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/applicationgroup/model_applicationgrouppatch.go b/resource-manager/desktopvirtualization/2021-09-03-preview/applicationgroup/model_applicationgrouppatch.go new file mode 100644 index 00000000000..e5d63002544 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/applicationgroup/model_applicationgrouppatch.go @@ -0,0 +1,12 @@ +package applicationgroup + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApplicationGroupPatch struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ApplicationGroupPatchProperties `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/applicationgroup/model_applicationgrouppatchproperties.go b/resource-manager/desktopvirtualization/2021-09-03-preview/applicationgroup/model_applicationgrouppatchproperties.go new file mode 100644 index 00000000000..2f2f5c20d79 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/applicationgroup/model_applicationgrouppatchproperties.go @@ -0,0 +1,9 @@ +package applicationgroup + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApplicationGroupPatchProperties struct { + Description *string `json:"description,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/applicationgroup/model_applicationgroupproperties.go b/resource-manager/desktopvirtualization/2021-09-03-preview/applicationgroup/model_applicationgroupproperties.go new file mode 100644 index 00000000000..8cc435c3bd9 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/applicationgroup/model_applicationgroupproperties.go @@ -0,0 +1,15 @@ +package applicationgroup + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApplicationGroupProperties struct { + ApplicationGroupType ApplicationGroupType `json:"applicationGroupType"` + CloudPcResource *bool `json:"cloudPcResource,omitempty"` + Description *string `json:"description,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + HostPoolArmPath string `json:"hostPoolArmPath"` + MigrationRequest *MigrationRequestProperties `json:"migrationRequest,omitempty"` + ObjectId *string `json:"objectId,omitempty"` + WorkspaceArmPath *string `json:"workspaceArmPath,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/applicationgroup/model_migrationrequestproperties.go b/resource-manager/desktopvirtualization/2021-09-03-preview/applicationgroup/model_migrationrequestproperties.go new file mode 100644 index 00000000000..238d6d02365 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/applicationgroup/model_migrationrequestproperties.go @@ -0,0 +1,9 @@ +package applicationgroup + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MigrationRequestProperties struct { + MigrationPath *string `json:"migrationPath,omitempty"` + Operation *Operation `json:"operation,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/applicationgroup/model_plan.go b/resource-manager/desktopvirtualization/2021-09-03-preview/applicationgroup/model_plan.go new file mode 100644 index 00000000000..865073b6a3e --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/applicationgroup/model_plan.go @@ -0,0 +1,12 @@ +package applicationgroup + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Plan struct { + Name string `json:"name"` + Product string `json:"product"` + PromotionCode *string `json:"promotionCode,omitempty"` + Publisher string `json:"publisher"` + Version *string `json:"version,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/applicationgroup/model_sku.go b/resource-manager/desktopvirtualization/2021-09-03-preview/applicationgroup/model_sku.go new file mode 100644 index 00000000000..57066762740 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/applicationgroup/model_sku.go @@ -0,0 +1,12 @@ +package applicationgroup + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Sku struct { + Capacity *int64 `json:"capacity,omitempty"` + Family *string `json:"family,omitempty"` + Name string `json:"name"` + Size *string `json:"size,omitempty"` + Tier *SkuTier `json:"tier,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/applicationgroup/predicates.go b/resource-manager/desktopvirtualization/2021-09-03-preview/applicationgroup/predicates.go new file mode 100644 index 00000000000..f0e69f1abd2 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/applicationgroup/predicates.go @@ -0,0 +1,44 @@ +package applicationgroup + +type ApplicationGroupOperationPredicate struct { + Etag *string + Id *string + Kind *string + Location *string + ManagedBy *string + Name *string + Type *string +} + +func (p ApplicationGroupOperationPredicate) Matches(input ApplicationGroup) bool { + + if p.Etag != nil && (input.Etag == nil && *p.Etag != *input.Etag) { + return false + } + + if p.Id != nil && (input.Id == nil && *p.Id != *input.Id) { + return false + } + + if p.Kind != nil && (input.Kind == nil && *p.Kind != *input.Kind) { + return false + } + + if p.Location != nil && (input.Location == nil && *p.Location != *input.Location) { + return false + } + + if p.ManagedBy != nil && (input.ManagedBy == nil && *p.ManagedBy != *input.ManagedBy) { + return false + } + + if p.Name != nil && (input.Name == nil && *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil && *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/applicationgroup/version.go b/resource-manager/desktopvirtualization/2021-09-03-preview/applicationgroup/version.go new file mode 100644 index 00000000000..abe65319f8b --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/applicationgroup/version.go @@ -0,0 +1,12 @@ +package applicationgroup + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2021-09-03-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/applicationgroup/%s", defaultApiVersion) +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/desktop/client.go b/resource-manager/desktopvirtualization/2021-09-03-preview/desktop/client.go new file mode 100644 index 00000000000..cc153930daa --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/desktop/client.go @@ -0,0 +1,18 @@ +package desktop + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DesktopClient struct { + Client autorest.Client + baseUri string +} + +func NewDesktopClientWithBaseURI(endpoint string) DesktopClient { + return DesktopClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/desktop/id_applicationgroup.go b/resource-manager/desktopvirtualization/2021-09-03-preview/desktop/id_applicationgroup.go new file mode 100644 index 00000000000..fe30e445a4f --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/desktop/id_applicationgroup.go @@ -0,0 +1,124 @@ +package desktop + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = ApplicationGroupId{} + +// ApplicationGroupId is a struct representing the Resource ID for a Application Group +type ApplicationGroupId struct { + SubscriptionId string + ResourceGroupName string + ApplicationGroupName string +} + +// NewApplicationGroupID returns a new ApplicationGroupId struct +func NewApplicationGroupID(subscriptionId string, resourceGroupName string, applicationGroupName string) ApplicationGroupId { + return ApplicationGroupId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ApplicationGroupName: applicationGroupName, + } +} + +// ParseApplicationGroupID parses 'input' into a ApplicationGroupId +func ParseApplicationGroupID(input string) (*ApplicationGroupId, error) { + parser := resourceids.NewParserFromResourceIdType(ApplicationGroupId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ApplicationGroupId{} + + 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.ApplicationGroupName, ok = parsed.Parsed["applicationGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'applicationGroupName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseApplicationGroupIDInsensitively parses 'input' case-insensitively into a ApplicationGroupId +// note: this method should only be used for API response data and not user input +func ParseApplicationGroupIDInsensitively(input string) (*ApplicationGroupId, error) { + parser := resourceids.NewParserFromResourceIdType(ApplicationGroupId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ApplicationGroupId{} + + 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.ApplicationGroupName, ok = parsed.Parsed["applicationGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'applicationGroupName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateApplicationGroupID checks that 'input' can be parsed as a Application Group ID +func ValidateApplicationGroupID(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 := ParseApplicationGroupID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Application Group ID +func (id ApplicationGroupId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DesktopVirtualization/applicationGroups/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ApplicationGroupName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Application Group ID +func (id ApplicationGroupId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftDesktopVirtualization", "Microsoft.DesktopVirtualization", "Microsoft.DesktopVirtualization"), + resourceids.StaticSegment("staticApplicationGroups", "applicationGroups", "applicationGroups"), + resourceids.UserSpecifiedSegment("applicationGroupName", "applicationGroupValue"), + } +} + +// String returns a human-readable description of this Application Group ID +func (id ApplicationGroupId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Application Group Name: %q", id.ApplicationGroupName), + } + return fmt.Sprintf("Application Group (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/desktop/id_applicationgroup_test.go b/resource-manager/desktopvirtualization/2021-09-03-preview/desktop/id_applicationgroup_test.go new file mode 100644 index 00000000000..0a3348e4c4c --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/desktop/id_applicationgroup_test.go @@ -0,0 +1,279 @@ +package desktop + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = ApplicationGroupId{} + +func TestNewApplicationGroupID(t *testing.T) { + id := NewApplicationGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "applicationGroupValue") + + 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.ApplicationGroupName != "applicationGroupValue" { + t.Fatalf("Expected %q but got %q for Segment 'ApplicationGroupName'", id.ApplicationGroupName, "applicationGroupValue") + } +} + +func TestFormatApplicationGroupID(t *testing.T) { + actual := NewApplicationGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "applicationGroupValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseApplicationGroupID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApplicationGroupId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue", + Expected: &ApplicationGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ApplicationGroupName: "applicationGroupValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApplicationGroupID(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.ApplicationGroupName != v.Expected.ApplicationGroupName { + t.Fatalf("Expected %q but got %q for ApplicationGroupName", v.Expected.ApplicationGroupName, actual.ApplicationGroupName) + } + + } +} + +func TestParseApplicationGroupIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApplicationGroupId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/aPpLiCaTiOnGrOuPs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue", + Expected: &ApplicationGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ApplicationGroupName: "applicationGroupValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/aPpLiCaTiOnGrOuPs/aPpLiCaTiOnGrOuPvAlUe", + Expected: &ApplicationGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ApplicationGroupName: "aPpLiCaTiOnGrOuPvAlUe", + }, + }, + { + // 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.dEsKtOpViRtUaLiZaTiOn/aPpLiCaTiOnGrOuPs/aPpLiCaTiOnGrOuPvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApplicationGroupIDInsensitively(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.ApplicationGroupName != v.Expected.ApplicationGroupName { + t.Fatalf("Expected %q but got %q for ApplicationGroupName", v.Expected.ApplicationGroupName, actual.ApplicationGroupName) + } + + } +} + +func TestSegmentsForApplicationGroupId(t *testing.T) { + segments := ApplicationGroupId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ApplicationGroupId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/desktop/id_desktop.go b/resource-manager/desktopvirtualization/2021-09-03-preview/desktop/id_desktop.go new file mode 100644 index 00000000000..1b44ed2f282 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/desktop/id_desktop.go @@ -0,0 +1,137 @@ +package desktop + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = DesktopId{} + +// DesktopId is a struct representing the Resource ID for a Desktop +type DesktopId struct { + SubscriptionId string + ResourceGroupName string + ApplicationGroupName string + DesktopName string +} + +// NewDesktopID returns a new DesktopId struct +func NewDesktopID(subscriptionId string, resourceGroupName string, applicationGroupName string, desktopName string) DesktopId { + return DesktopId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ApplicationGroupName: applicationGroupName, + DesktopName: desktopName, + } +} + +// ParseDesktopID parses 'input' into a DesktopId +func ParseDesktopID(input string) (*DesktopId, error) { + parser := resourceids.NewParserFromResourceIdType(DesktopId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := DesktopId{} + + 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.ApplicationGroupName, ok = parsed.Parsed["applicationGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'applicationGroupName' was not found in the resource id %q", input) + } + + if id.DesktopName, ok = parsed.Parsed["desktopName"]; !ok { + return nil, fmt.Errorf("the segment 'desktopName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseDesktopIDInsensitively parses 'input' case-insensitively into a DesktopId +// note: this method should only be used for API response data and not user input +func ParseDesktopIDInsensitively(input string) (*DesktopId, error) { + parser := resourceids.NewParserFromResourceIdType(DesktopId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := DesktopId{} + + 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.ApplicationGroupName, ok = parsed.Parsed["applicationGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'applicationGroupName' was not found in the resource id %q", input) + } + + if id.DesktopName, ok = parsed.Parsed["desktopName"]; !ok { + return nil, fmt.Errorf("the segment 'desktopName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateDesktopID checks that 'input' can be parsed as a Desktop ID +func ValidateDesktopID(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 := ParseDesktopID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Desktop ID +func (id DesktopId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DesktopVirtualization/applicationGroups/%s/desktops/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ApplicationGroupName, id.DesktopName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Desktop ID +func (id DesktopId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftDesktopVirtualization", "Microsoft.DesktopVirtualization", "Microsoft.DesktopVirtualization"), + resourceids.StaticSegment("staticApplicationGroups", "applicationGroups", "applicationGroups"), + resourceids.UserSpecifiedSegment("applicationGroupName", "applicationGroupValue"), + resourceids.StaticSegment("staticDesktops", "desktops", "desktops"), + resourceids.UserSpecifiedSegment("desktopName", "desktopValue"), + } +} + +// String returns a human-readable description of this Desktop ID +func (id DesktopId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Application Group Name: %q", id.ApplicationGroupName), + fmt.Sprintf("Desktop Name: %q", id.DesktopName), + } + return fmt.Sprintf("Desktop (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/desktop/id_desktop_test.go b/resource-manager/desktopvirtualization/2021-09-03-preview/desktop/id_desktop_test.go new file mode 100644 index 00000000000..e5b24fb5f69 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/desktop/id_desktop_test.go @@ -0,0 +1,324 @@ +package desktop + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = DesktopId{} + +func TestNewDesktopID(t *testing.T) { + id := NewDesktopID("12345678-1234-9876-4563-123456789012", "example-resource-group", "applicationGroupValue", "desktopValue") + + 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.ApplicationGroupName != "applicationGroupValue" { + t.Fatalf("Expected %q but got %q for Segment 'ApplicationGroupName'", id.ApplicationGroupName, "applicationGroupValue") + } + + if id.DesktopName != "desktopValue" { + t.Fatalf("Expected %q but got %q for Segment 'DesktopName'", id.DesktopName, "desktopValue") + } +} + +func TestFormatDesktopID(t *testing.T) { + actual := NewDesktopID("12345678-1234-9876-4563-123456789012", "example-resource-group", "applicationGroupValue", "desktopValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue/desktops/desktopValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseDesktopID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DesktopId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue/desktops", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue/desktops/desktopValue", + Expected: &DesktopId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ApplicationGroupName: "applicationGroupValue", + DesktopName: "desktopValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue/desktops/desktopValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDesktopID(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.ApplicationGroupName != v.Expected.ApplicationGroupName { + t.Fatalf("Expected %q but got %q for ApplicationGroupName", v.Expected.ApplicationGroupName, actual.ApplicationGroupName) + } + + if actual.DesktopName != v.Expected.DesktopName { + t.Fatalf("Expected %q but got %q for DesktopName", v.Expected.DesktopName, actual.DesktopName) + } + + } +} + +func TestParseDesktopIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DesktopId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/aPpLiCaTiOnGrOuPs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/aPpLiCaTiOnGrOuPs/aPpLiCaTiOnGrOuPvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue/desktops", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/aPpLiCaTiOnGrOuPs/aPpLiCaTiOnGrOuPvAlUe/dEsKtOpS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue/desktops/desktopValue", + Expected: &DesktopId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ApplicationGroupName: "applicationGroupValue", + DesktopName: "desktopValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue/desktops/desktopValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/aPpLiCaTiOnGrOuPs/aPpLiCaTiOnGrOuPvAlUe/dEsKtOpS/dEsKtOpVaLuE", + Expected: &DesktopId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ApplicationGroupName: "aPpLiCaTiOnGrOuPvAlUe", + DesktopName: "dEsKtOpVaLuE", + }, + }, + { + // 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.dEsKtOpViRtUaLiZaTiOn/aPpLiCaTiOnGrOuPs/aPpLiCaTiOnGrOuPvAlUe/dEsKtOpS/dEsKtOpVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDesktopIDInsensitively(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.ApplicationGroupName != v.Expected.ApplicationGroupName { + t.Fatalf("Expected %q but got %q for ApplicationGroupName", v.Expected.ApplicationGroupName, actual.ApplicationGroupName) + } + + if actual.DesktopName != v.Expected.DesktopName { + t.Fatalf("Expected %q but got %q for DesktopName", v.Expected.DesktopName, actual.DesktopName) + } + + } +} + +func TestSegmentsForDesktopId(t *testing.T) { + segments := DesktopId{}.Segments() + if len(segments) == 0 { + t.Fatalf("DesktopId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/desktop/method_get_autorest.go b/resource-manager/desktopvirtualization/2021-09-03-preview/desktop/method_get_autorest.go new file mode 100644 index 00000000000..23658f0ebe2 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/desktop/method_get_autorest.go @@ -0,0 +1,67 @@ +package desktop + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *Desktop +} + +// Get ... +func (c DesktopClient) Get(ctx context.Context, id DesktopId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "desktop.DesktopClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "desktop.DesktopClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "desktop.DesktopClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c DesktopClient) preparerForGet(ctx context.Context, id DesktopId) (*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 DesktopClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/desktop/method_list_autorest.go b/resource-manager/desktopvirtualization/2021-09-03-preview/desktop/method_list_autorest.go new file mode 100644 index 00000000000..145ff8981dd --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/desktop/method_list_autorest.go @@ -0,0 +1,186 @@ +package desktop + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + Model *[]Desktop + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) +} + +type ListCompleteResult struct { + Items []Desktop +} + +func (r ListOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// List ... +func (c DesktopClient) List(ctx context.Context, id ApplicationGroupId) (resp ListOperationResponse, err error) { + req, err := c.preparerForList(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "desktop.DesktopClient", "List", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "desktop.DesktopClient", "List", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForList(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "desktop.DesktopClient", "List", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// ListComplete retrieves all of the results into a single object +func (c DesktopClient) ListComplete(ctx context.Context, id ApplicationGroupId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, DesktopOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c DesktopClient) ListCompleteMatchingPredicate(ctx context.Context, id ApplicationGroupId, predicate DesktopOperationPredicate) (resp ListCompleteResult, err error) { + items := make([]Desktop, 0) + + page, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListCompleteResult{ + Items: items, + } + return out, nil +} + +// preparerForList prepares the List request. +func (c DesktopClient) preparerForList(ctx context.Context, id ApplicationGroupId) (*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/desktops", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListWithNextLink prepares the List request with the given nextLink token. +func (c DesktopClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForList handles the response to the List request. The method always +// closes the http.Response Body. +func (c DesktopClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { + type page struct { + Values []Desktop `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { + req, err := c.preparerForListWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "desktop.DesktopClient", "List", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "desktop.DesktopClient", "List", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "desktop.DesktopClient", "List", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/desktop/method_update_autorest.go b/resource-manager/desktopvirtualization/2021-09-03-preview/desktop/method_update_autorest.go new file mode 100644 index 00000000000..60d6fece536 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/desktop/method_update_autorest.go @@ -0,0 +1,68 @@ +package desktop + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + HttpResponse *http.Response + Model *Desktop +} + +// Update ... +func (c DesktopClient) Update(ctx context.Context, id DesktopId, input DesktopPatch) (result UpdateOperationResponse, err error) { + req, err := c.preparerForUpdate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "desktop.DesktopClient", "Update", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "desktop.DesktopClient", "Update", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForUpdate(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "desktop.DesktopClient", "Update", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForUpdate prepares the Update request. +func (c DesktopClient) preparerForUpdate(ctx context.Context, id DesktopId, input DesktopPatch) (*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 DesktopClient) responderForUpdate(resp *http.Response) (result UpdateOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/desktop/model_desktop.go b/resource-manager/desktopvirtualization/2021-09-03-preview/desktop/model_desktop.go new file mode 100644 index 00000000000..6d41ecc215e --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/desktop/model_desktop.go @@ -0,0 +1,16 @@ +package desktop + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Desktop struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *DesktopProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/desktop/model_desktoppatch.go b/resource-manager/desktopvirtualization/2021-09-03-preview/desktop/model_desktoppatch.go new file mode 100644 index 00000000000..1d7d1672159 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/desktop/model_desktoppatch.go @@ -0,0 +1,9 @@ +package desktop + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DesktopPatch struct { + Properties *DesktopPatchProperties `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/desktop/model_desktoppatchproperties.go b/resource-manager/desktopvirtualization/2021-09-03-preview/desktop/model_desktoppatchproperties.go new file mode 100644 index 00000000000..40b1a4577e1 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/desktop/model_desktoppatchproperties.go @@ -0,0 +1,9 @@ +package desktop + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DesktopPatchProperties struct { + Description *string `json:"description,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/desktop/model_desktopproperties.go b/resource-manager/desktopvirtualization/2021-09-03-preview/desktop/model_desktopproperties.go new file mode 100644 index 00000000000..2d961ead46c --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/desktop/model_desktopproperties.go @@ -0,0 +1,12 @@ +package desktop + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DesktopProperties struct { + Description *string `json:"description,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + IconContent *string `json:"iconContent,omitempty"` + IconHash *string `json:"iconHash,omitempty"` + ObjectId *string `json:"objectId,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/desktop/predicates.go b/resource-manager/desktopvirtualization/2021-09-03-preview/desktop/predicates.go new file mode 100644 index 00000000000..f8bbb1e357f --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/desktop/predicates.go @@ -0,0 +1,24 @@ +package desktop + +type DesktopOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p DesktopOperationPredicate) Matches(input Desktop) bool { + + if p.Id != nil && (input.Id == nil && *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil && *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil && *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/desktop/version.go b/resource-manager/desktopvirtualization/2021-09-03-preview/desktop/version.go new file mode 100644 index 00000000000..82f4c83323b --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/desktop/version.go @@ -0,0 +1,12 @@ +package desktop + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2021-09-03-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/desktop/%s", defaultApiVersion) +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/hostpool/client.go b/resource-manager/desktopvirtualization/2021-09-03-preview/hostpool/client.go new file mode 100644 index 00000000000..adce757bb86 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/hostpool/client.go @@ -0,0 +1,18 @@ +package hostpool + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type HostPoolClient struct { + Client autorest.Client + baseUri string +} + +func NewHostPoolClientWithBaseURI(endpoint string) HostPoolClient { + return HostPoolClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/hostpool/constants.go b/resource-manager/desktopvirtualization/2021-09-03-preview/hostpool/constants.go new file mode 100644 index 00000000000..2566a6adc1f --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/hostpool/constants.go @@ -0,0 +1,291 @@ +package hostpool + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type HostPoolType string + +const ( + HostPoolTypeBYODesktop HostPoolType = "BYODesktop" + HostPoolTypePersonal HostPoolType = "Personal" + HostPoolTypePooled HostPoolType = "Pooled" +) + +func PossibleValuesForHostPoolType() []string { + return []string{ + string(HostPoolTypeBYODesktop), + string(HostPoolTypePersonal), + string(HostPoolTypePooled), + } +} + +func parseHostPoolType(input string) (*HostPoolType, error) { + vals := map[string]HostPoolType{ + "byodesktop": HostPoolTypeBYODesktop, + "personal": HostPoolTypePersonal, + "pooled": HostPoolTypePooled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := HostPoolType(input) + return &out, nil +} + +type LoadBalancerType string + +const ( + LoadBalancerTypeBreadthFirst LoadBalancerType = "BreadthFirst" + LoadBalancerTypeDepthFirst LoadBalancerType = "DepthFirst" + LoadBalancerTypePersistent LoadBalancerType = "Persistent" +) + +func PossibleValuesForLoadBalancerType() []string { + return []string{ + string(LoadBalancerTypeBreadthFirst), + string(LoadBalancerTypeDepthFirst), + string(LoadBalancerTypePersistent), + } +} + +func parseLoadBalancerType(input string) (*LoadBalancerType, error) { + vals := map[string]LoadBalancerType{ + "breadthfirst": LoadBalancerTypeBreadthFirst, + "depthfirst": LoadBalancerTypeDepthFirst, + "persistent": LoadBalancerTypePersistent, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := LoadBalancerType(input) + return &out, nil +} + +type Operation string + +const ( + OperationComplete Operation = "Complete" + OperationHide Operation = "Hide" + OperationRevoke Operation = "Revoke" + OperationStart Operation = "Start" + OperationUnhide Operation = "Unhide" +) + +func PossibleValuesForOperation() []string { + return []string{ + string(OperationComplete), + string(OperationHide), + string(OperationRevoke), + string(OperationStart), + string(OperationUnhide), + } +} + +func parseOperation(input string) (*Operation, error) { + vals := map[string]Operation{ + "complete": OperationComplete, + "hide": OperationHide, + "revoke": OperationRevoke, + "start": OperationStart, + "unhide": OperationUnhide, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Operation(input) + return &out, nil +} + +type PersonalDesktopAssignmentType string + +const ( + PersonalDesktopAssignmentTypeAutomatic PersonalDesktopAssignmentType = "Automatic" + PersonalDesktopAssignmentTypeDirect PersonalDesktopAssignmentType = "Direct" +) + +func PossibleValuesForPersonalDesktopAssignmentType() []string { + return []string{ + string(PersonalDesktopAssignmentTypeAutomatic), + string(PersonalDesktopAssignmentTypeDirect), + } +} + +func parsePersonalDesktopAssignmentType(input string) (*PersonalDesktopAssignmentType, error) { + vals := map[string]PersonalDesktopAssignmentType{ + "automatic": PersonalDesktopAssignmentTypeAutomatic, + "direct": PersonalDesktopAssignmentTypeDirect, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PersonalDesktopAssignmentType(input) + return &out, nil +} + +type PreferredAppGroupType string + +const ( + PreferredAppGroupTypeDesktop PreferredAppGroupType = "Desktop" + PreferredAppGroupTypeNone PreferredAppGroupType = "None" + PreferredAppGroupTypeRailApplications PreferredAppGroupType = "RailApplications" +) + +func PossibleValuesForPreferredAppGroupType() []string { + return []string{ + string(PreferredAppGroupTypeDesktop), + string(PreferredAppGroupTypeNone), + string(PreferredAppGroupTypeRailApplications), + } +} + +func parsePreferredAppGroupType(input string) (*PreferredAppGroupType, error) { + vals := map[string]PreferredAppGroupType{ + "desktop": PreferredAppGroupTypeDesktop, + "none": PreferredAppGroupTypeNone, + "railapplications": PreferredAppGroupTypeRailApplications, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PreferredAppGroupType(input) + return &out, nil +} + +type PublicNetworkAccess string + +const ( + PublicNetworkAccessDisabled PublicNetworkAccess = "Disabled" + PublicNetworkAccessEnabled PublicNetworkAccess = "Enabled" +) + +func PossibleValuesForPublicNetworkAccess() []string { + return []string{ + string(PublicNetworkAccessDisabled), + string(PublicNetworkAccessEnabled), + } +} + +func parsePublicNetworkAccess(input string) (*PublicNetworkAccess, error) { + vals := map[string]PublicNetworkAccess{ + "disabled": PublicNetworkAccessDisabled, + "enabled": PublicNetworkAccessEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PublicNetworkAccess(input) + return &out, nil +} + +type RegistrationTokenOperation string + +const ( + RegistrationTokenOperationDelete RegistrationTokenOperation = "Delete" + RegistrationTokenOperationNone RegistrationTokenOperation = "None" + RegistrationTokenOperationUpdate RegistrationTokenOperation = "Update" +) + +func PossibleValuesForRegistrationTokenOperation() []string { + return []string{ + string(RegistrationTokenOperationDelete), + string(RegistrationTokenOperationNone), + string(RegistrationTokenOperationUpdate), + } +} + +func parseRegistrationTokenOperation(input string) (*RegistrationTokenOperation, error) { + vals := map[string]RegistrationTokenOperation{ + "delete": RegistrationTokenOperationDelete, + "none": RegistrationTokenOperationNone, + "update": RegistrationTokenOperationUpdate, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RegistrationTokenOperation(input) + return &out, nil +} + +type SSOSecretType string + +const ( + SSOSecretTypeCertificate SSOSecretType = "Certificate" + SSOSecretTypeCertificateInKeyVault SSOSecretType = "CertificateInKeyVault" + SSOSecretTypeSharedKey SSOSecretType = "SharedKey" + SSOSecretTypeSharedKeyInKeyVault SSOSecretType = "SharedKeyInKeyVault" +) + +func PossibleValuesForSSOSecretType() []string { + return []string{ + string(SSOSecretTypeCertificate), + string(SSOSecretTypeCertificateInKeyVault), + string(SSOSecretTypeSharedKey), + string(SSOSecretTypeSharedKeyInKeyVault), + } +} + +func parseSSOSecretType(input string) (*SSOSecretType, error) { + vals := map[string]SSOSecretType{ + "certificate": SSOSecretTypeCertificate, + "certificateinkeyvault": SSOSecretTypeCertificateInKeyVault, + "sharedkey": SSOSecretTypeSharedKey, + "sharedkeyinkeyvault": SSOSecretTypeSharedKeyInKeyVault, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SSOSecretType(input) + return &out, nil +} + +type SkuTier string + +const ( + SkuTierBasic SkuTier = "Basic" + SkuTierFree SkuTier = "Free" + SkuTierPremium SkuTier = "Premium" + SkuTierStandard SkuTier = "Standard" +) + +func PossibleValuesForSkuTier() []string { + return []string{ + string(SkuTierBasic), + string(SkuTierFree), + string(SkuTierPremium), + string(SkuTierStandard), + } +} + +func parseSkuTier(input string) (*SkuTier, error) { + vals := map[string]SkuTier{ + "basic": SkuTierBasic, + "free": SkuTierFree, + "premium": SkuTierPremium, + "standard": SkuTierStandard, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SkuTier(input) + return &out, nil +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/hostpool/id_hostpool.go b/resource-manager/desktopvirtualization/2021-09-03-preview/hostpool/id_hostpool.go new file mode 100644 index 00000000000..61c82943024 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/hostpool/id_hostpool.go @@ -0,0 +1,124 @@ +package hostpool + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = HostPoolId{} + +// HostPoolId is a struct representing the Resource ID for a Host Pool +type HostPoolId struct { + SubscriptionId string + ResourceGroupName string + HostPoolName string +} + +// NewHostPoolID returns a new HostPoolId struct +func NewHostPoolID(subscriptionId string, resourceGroupName string, hostPoolName string) HostPoolId { + return HostPoolId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + HostPoolName: hostPoolName, + } +} + +// ParseHostPoolID parses 'input' into a HostPoolId +func ParseHostPoolID(input string) (*HostPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(HostPoolId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := HostPoolId{} + + 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.HostPoolName, ok = parsed.Parsed["hostPoolName"]; !ok { + return nil, fmt.Errorf("the segment 'hostPoolName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseHostPoolIDInsensitively parses 'input' case-insensitively into a HostPoolId +// note: this method should only be used for API response data and not user input +func ParseHostPoolIDInsensitively(input string) (*HostPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(HostPoolId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := HostPoolId{} + + 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.HostPoolName, ok = parsed.Parsed["hostPoolName"]; !ok { + return nil, fmt.Errorf("the segment 'hostPoolName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateHostPoolID checks that 'input' can be parsed as a Host Pool ID +func ValidateHostPoolID(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 := ParseHostPoolID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Host Pool ID +func (id HostPoolId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DesktopVirtualization/hostPools/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.HostPoolName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Host Pool ID +func (id HostPoolId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftDesktopVirtualization", "Microsoft.DesktopVirtualization", "Microsoft.DesktopVirtualization"), + resourceids.StaticSegment("staticHostPools", "hostPools", "hostPools"), + resourceids.UserSpecifiedSegment("hostPoolName", "hostPoolValue"), + } +} + +// String returns a human-readable description of this Host Pool ID +func (id HostPoolId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Host Pool Name: %q", id.HostPoolName), + } + return fmt.Sprintf("Host Pool (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/hostpool/id_hostpool_test.go b/resource-manager/desktopvirtualization/2021-09-03-preview/hostpool/id_hostpool_test.go new file mode 100644 index 00000000000..fb6c4a509c4 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/hostpool/id_hostpool_test.go @@ -0,0 +1,279 @@ +package hostpool + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = HostPoolId{} + +func TestNewHostPoolID(t *testing.T) { + id := NewHostPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "hostPoolValue") + + 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.HostPoolName != "hostPoolValue" { + t.Fatalf("Expected %q but got %q for Segment 'HostPoolName'", id.HostPoolName, "hostPoolValue") + } +} + +func TestFormatHostPoolID(t *testing.T) { + actual := NewHostPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "hostPoolValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseHostPoolID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *HostPoolId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue", + Expected: &HostPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + HostPoolName: "hostPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseHostPoolID(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.HostPoolName != v.Expected.HostPoolName { + t.Fatalf("Expected %q but got %q for HostPoolName", v.Expected.HostPoolName, actual.HostPoolName) + } + + } +} + +func TestParseHostPoolIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *HostPoolId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue", + Expected: &HostPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + HostPoolName: "hostPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe", + Expected: &HostPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + HostPoolName: "hOsTpOoLvAlUe", + }, + }, + { + // 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.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseHostPoolIDInsensitively(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.HostPoolName != v.Expected.HostPoolName { + t.Fatalf("Expected %q but got %q for HostPoolName", v.Expected.HostPoolName, actual.HostPoolName) + } + + } +} + +func TestSegmentsForHostPoolId(t *testing.T) { + segments := HostPoolId{}.Segments() + if len(segments) == 0 { + t.Fatalf("HostPoolId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/hostpool/method_createorupdate_autorest.go b/resource-manager/desktopvirtualization/2021-09-03-preview/hostpool/method_createorupdate_autorest.go new file mode 100644 index 00000000000..6ba8c24c258 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/hostpool/method_createorupdate_autorest.go @@ -0,0 +1,68 @@ +package hostpool + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + Model *HostPool +} + +// CreateOrUpdate ... +func (c HostPoolClient) CreateOrUpdate(ctx context.Context, id HostPoolId, input HostPool) (result CreateOrUpdateOperationResponse, err error) { + req, err := c.preparerForCreateOrUpdate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "hostpool.HostPoolClient", "CreateOrUpdate", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "hostpool.HostPoolClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForCreateOrUpdate(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "hostpool.HostPoolClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForCreateOrUpdate prepares the CreateOrUpdate request. +func (c HostPoolClient) preparerForCreateOrUpdate(ctx context.Context, id HostPoolId, input HostPool) (*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)) +} + +// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always +// closes the http.Response Body. +func (c HostPoolClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/hostpool/method_delete_autorest.go b/resource-manager/desktopvirtualization/2021-09-03-preview/hostpool/method_delete_autorest.go new file mode 100644 index 00000000000..4483478b8e4 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/hostpool/method_delete_autorest.go @@ -0,0 +1,94 @@ +package hostpool + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response +} + +type DeleteOperationOptions struct { + Force *bool +} + +func DefaultDeleteOperationOptions() DeleteOperationOptions { + return DeleteOperationOptions{} +} + +func (o DeleteOperationOptions) toHeaders() map[string]interface{} { + out := make(map[string]interface{}) + + return out +} + +func (o DeleteOperationOptions) toQueryString() map[string]interface{} { + out := make(map[string]interface{}) + + if o.Force != nil { + out["force"] = *o.Force + } + + return out +} + +// Delete ... +func (c HostPoolClient) Delete(ctx context.Context, id HostPoolId, options DeleteOperationOptions) (result DeleteOperationResponse, err error) { + req, err := c.preparerForDelete(ctx, id, options) + if err != nil { + err = autorest.NewErrorWithError(err, "hostpool.HostPoolClient", "Delete", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "hostpool.HostPoolClient", "Delete", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForDelete(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "hostpool.HostPoolClient", "Delete", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForDelete prepares the Delete request. +func (c HostPoolClient) preparerForDelete(ctx context.Context, id HostPoolId, options DeleteOperationOptions) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + for k, v := range options.toQueryString() { + queryParameters[k] = autorest.Encode("query", v) + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsDelete(), + autorest.WithBaseURL(c.baseUri), + autorest.WithHeaders(options.toHeaders()), + 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 HostPoolClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/hostpool/method_get_autorest.go b/resource-manager/desktopvirtualization/2021-09-03-preview/hostpool/method_get_autorest.go new file mode 100644 index 00000000000..c442f70a286 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/hostpool/method_get_autorest.go @@ -0,0 +1,67 @@ +package hostpool + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *HostPool +} + +// Get ... +func (c HostPoolClient) Get(ctx context.Context, id HostPoolId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "hostpool.HostPoolClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "hostpool.HostPoolClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "hostpool.HostPoolClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c HostPoolClient) preparerForGet(ctx context.Context, id HostPoolId) (*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 HostPoolClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/hostpool/method_list_autorest.go b/resource-manager/desktopvirtualization/2021-09-03-preview/hostpool/method_list_autorest.go new file mode 100644 index 00000000000..d776af10f11 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/hostpool/method_list_autorest.go @@ -0,0 +1,187 @@ +package hostpool + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + Model *[]HostPool + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) +} + +type ListCompleteResult struct { + Items []HostPool +} + +func (r ListOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// List ... +func (c HostPoolClient) List(ctx context.Context, id commonids.SubscriptionId) (resp ListOperationResponse, err error) { + req, err := c.preparerForList(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "hostpool.HostPoolClient", "List", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "hostpool.HostPoolClient", "List", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForList(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "hostpool.HostPoolClient", "List", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// ListComplete retrieves all of the results into a single object +func (c HostPoolClient) ListComplete(ctx context.Context, id commonids.SubscriptionId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, HostPoolOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c HostPoolClient) ListCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate HostPoolOperationPredicate) (resp ListCompleteResult, err error) { + items := make([]HostPool, 0) + + page, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListCompleteResult{ + Items: items, + } + return out, nil +} + +// preparerForList prepares the List request. +func (c HostPoolClient) preparerForList(ctx context.Context, id commonids.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.DesktopVirtualization/hostPools", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListWithNextLink prepares the List request with the given nextLink token. +func (c HostPoolClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForList handles the response to the List request. The method always +// closes the http.Response Body. +func (c HostPoolClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { + type page struct { + Values []HostPool `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { + req, err := c.preparerForListWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "hostpool.HostPoolClient", "List", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "hostpool.HostPoolClient", "List", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "hostpool.HostPoolClient", "List", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/hostpool/method_listbyresourcegroup_autorest.go b/resource-manager/desktopvirtualization/2021-09-03-preview/hostpool/method_listbyresourcegroup_autorest.go new file mode 100644 index 00000000000..10e2fdbcb63 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/hostpool/method_listbyresourcegroup_autorest.go @@ -0,0 +1,187 @@ +package hostpool + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByResourceGroupOperationResponse struct { + HttpResponse *http.Response + Model *[]HostPool + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListByResourceGroupOperationResponse, error) +} + +type ListByResourceGroupCompleteResult struct { + Items []HostPool +} + +func (r ListByResourceGroupOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListByResourceGroupOperationResponse) LoadMore(ctx context.Context) (resp ListByResourceGroupOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// ListByResourceGroup ... +func (c HostPoolClient) ListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (resp ListByResourceGroupOperationResponse, err error) { + req, err := c.preparerForListByResourceGroup(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "hostpool.HostPoolClient", "ListByResourceGroup", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "hostpool.HostPoolClient", "ListByResourceGroup", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForListByResourceGroup(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "hostpool.HostPoolClient", "ListByResourceGroup", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// ListByResourceGroupComplete retrieves all of the results into a single object +func (c HostPoolClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (ListByResourceGroupCompleteResult, error) { + return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, HostPoolOperationPredicate{}) +} + +// ListByResourceGroupCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c HostPoolClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate HostPoolOperationPredicate) (resp ListByResourceGroupCompleteResult, err error) { + items := make([]HostPool, 0) + + page, err := c.ListByResourceGroup(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListByResourceGroupCompleteResult{ + Items: items, + } + return out, nil +} + +// preparerForListByResourceGroup prepares the ListByResourceGroup request. +func (c HostPoolClient) preparerForListByResourceGroup(ctx context.Context, id commonids.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.DesktopVirtualization/hostPools", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListByResourceGroupWithNextLink prepares the ListByResourceGroup request with the given nextLink token. +func (c HostPoolClient) preparerForListByResourceGroupWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForListByResourceGroup handles the response to the ListByResourceGroup request. The method always +// closes the http.Response Body. +func (c HostPoolClient) responderForListByResourceGroup(resp *http.Response) (result ListByResourceGroupOperationResponse, err error) { + type page struct { + Values []HostPool `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListByResourceGroupOperationResponse, err error) { + req, err := c.preparerForListByResourceGroupWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "hostpool.HostPoolClient", "ListByResourceGroup", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "hostpool.HostPoolClient", "ListByResourceGroup", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForListByResourceGroup(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "hostpool.HostPoolClient", "ListByResourceGroup", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/hostpool/method_retrieveregistrationtoken_autorest.go b/resource-manager/desktopvirtualization/2021-09-03-preview/hostpool/method_retrieveregistrationtoken_autorest.go new file mode 100644 index 00000000000..9e3317f1807 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/hostpool/method_retrieveregistrationtoken_autorest.go @@ -0,0 +1,68 @@ +package hostpool + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RetrieveRegistrationTokenOperationResponse struct { + HttpResponse *http.Response + Model *RegistrationInfo +} + +// RetrieveRegistrationToken ... +func (c HostPoolClient) RetrieveRegistrationToken(ctx context.Context, id HostPoolId) (result RetrieveRegistrationTokenOperationResponse, err error) { + req, err := c.preparerForRetrieveRegistrationToken(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "hostpool.HostPoolClient", "RetrieveRegistrationToken", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "hostpool.HostPoolClient", "RetrieveRegistrationToken", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForRetrieveRegistrationToken(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "hostpool.HostPoolClient", "RetrieveRegistrationToken", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForRetrieveRegistrationToken prepares the RetrieveRegistrationToken request. +func (c HostPoolClient) preparerForRetrieveRegistrationToken(ctx context.Context, id HostPoolId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/retrieveRegistrationToken", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForRetrieveRegistrationToken handles the response to the RetrieveRegistrationToken request. The method always +// closes the http.Response Body. +func (c HostPoolClient) responderForRetrieveRegistrationToken(resp *http.Response) (result RetrieveRegistrationTokenOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/hostpool/method_update_autorest.go b/resource-manager/desktopvirtualization/2021-09-03-preview/hostpool/method_update_autorest.go new file mode 100644 index 00000000000..9de04a30cfc --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/hostpool/method_update_autorest.go @@ -0,0 +1,68 @@ +package hostpool + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + HttpResponse *http.Response + Model *HostPool +} + +// Update ... +func (c HostPoolClient) Update(ctx context.Context, id HostPoolId, input HostPoolPatch) (result UpdateOperationResponse, err error) { + req, err := c.preparerForUpdate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "hostpool.HostPoolClient", "Update", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "hostpool.HostPoolClient", "Update", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForUpdate(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "hostpool.HostPoolClient", "Update", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForUpdate prepares the Update request. +func (c HostPoolClient) preparerForUpdate(ctx context.Context, id HostPoolId, input HostPoolPatch) (*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 HostPoolClient) responderForUpdate(resp *http.Response) (result UpdateOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/hostpool/model_hostpool.go b/resource-manager/desktopvirtualization/2021-09-03-preview/hostpool/model_hostpool.go new file mode 100644 index 00000000000..e3d98e6ba0c --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/hostpool/model_hostpool.go @@ -0,0 +1,25 @@ +package hostpool + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/identity" + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type HostPool struct { + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Identity *identity.SystemAssigned `json:"identity,omitempty"` + Kind *string `json:"kind,omitempty"` + Location *string `json:"location,omitempty"` + ManagedBy *string `json:"managedBy,omitempty"` + Name *string `json:"name,omitempty"` + Plan *Plan `json:"plan,omitempty"` + Properties HostPoolProperties `json:"properties"` + Sku *Sku `json:"sku,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/hostpool/model_hostpoolpatch.go b/resource-manager/desktopvirtualization/2021-09-03-preview/hostpool/model_hostpoolpatch.go new file mode 100644 index 00000000000..6895ce28a7d --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/hostpool/model_hostpoolpatch.go @@ -0,0 +1,12 @@ +package hostpool + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type HostPoolPatch struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *HostPoolPatchProperties `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/hostpool/model_hostpoolpatchproperties.go b/resource-manager/desktopvirtualization/2021-09-03-preview/hostpool/model_hostpoolpatchproperties.go new file mode 100644 index 00000000000..00cd5a49544 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/hostpool/model_hostpoolpatchproperties.go @@ -0,0 +1,24 @@ +package hostpool + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type HostPoolPatchProperties struct { + CustomRdpProperty *string `json:"customRdpProperty,omitempty"` + Description *string `json:"description,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + LoadBalancerType *LoadBalancerType `json:"loadBalancerType,omitempty"` + MaxSessionLimit *int64 `json:"maxSessionLimit,omitempty"` + PersonalDesktopAssignmentType *PersonalDesktopAssignmentType `json:"personalDesktopAssignmentType,omitempty"` + PreferredAppGroupType *PreferredAppGroupType `json:"preferredAppGroupType,omitempty"` + PublicNetworkAccess *PublicNetworkAccess `json:"publicNetworkAccess,omitempty"` + RegistrationInfo *RegistrationInfoPatch `json:"registrationInfo,omitempty"` + Ring *int64 `json:"ring,omitempty"` + SsoClientId *string `json:"ssoClientId,omitempty"` + SsoClientSecretKeyVaultPath *string `json:"ssoClientSecretKeyVaultPath,omitempty"` + SsoSecretType *SSOSecretType `json:"ssoSecretType,omitempty"` + SsoadfsAuthority *string `json:"ssoadfsAuthority,omitempty"` + StartVMOnConnect *bool `json:"startVMOnConnect,omitempty"` + ValidationEnvironment *bool `json:"validationEnvironment,omitempty"` + VmTemplate *string `json:"vmTemplate,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/hostpool/model_hostpoolproperties.go b/resource-manager/desktopvirtualization/2021-09-03-preview/hostpool/model_hostpoolproperties.go new file mode 100644 index 00000000000..065010f580c --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/hostpool/model_hostpoolproperties.go @@ -0,0 +1,29 @@ +package hostpool + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type HostPoolProperties struct { + ApplicationGroupReferences *[]string `json:"applicationGroupReferences,omitempty"` + CloudPcResource *bool `json:"cloudPcResource,omitempty"` + CustomRdpProperty *string `json:"customRdpProperty,omitempty"` + Description *string `json:"description,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + HostPoolType HostPoolType `json:"hostPoolType"` + LoadBalancerType LoadBalancerType `json:"loadBalancerType"` + MaxSessionLimit *int64 `json:"maxSessionLimit,omitempty"` + MigrationRequest *MigrationRequestProperties `json:"migrationRequest,omitempty"` + ObjectId *string `json:"objectId,omitempty"` + PersonalDesktopAssignmentType *PersonalDesktopAssignmentType `json:"personalDesktopAssignmentType,omitempty"` + PreferredAppGroupType PreferredAppGroupType `json:"preferredAppGroupType"` + PublicNetworkAccess *PublicNetworkAccess `json:"publicNetworkAccess,omitempty"` + RegistrationInfo *RegistrationInfo `json:"registrationInfo,omitempty"` + Ring *int64 `json:"ring,omitempty"` + SsoClientId *string `json:"ssoClientId,omitempty"` + SsoClientSecretKeyVaultPath *string `json:"ssoClientSecretKeyVaultPath,omitempty"` + SsoSecretType *SSOSecretType `json:"ssoSecretType,omitempty"` + SsoadfsAuthority *string `json:"ssoadfsAuthority,omitempty"` + StartVMOnConnect *bool `json:"startVMOnConnect,omitempty"` + ValidationEnvironment *bool `json:"validationEnvironment,omitempty"` + VmTemplate *string `json:"vmTemplate,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/hostpool/model_migrationrequestproperties.go b/resource-manager/desktopvirtualization/2021-09-03-preview/hostpool/model_migrationrequestproperties.go new file mode 100644 index 00000000000..2f6b968453d --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/hostpool/model_migrationrequestproperties.go @@ -0,0 +1,9 @@ +package hostpool + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MigrationRequestProperties struct { + MigrationPath *string `json:"migrationPath,omitempty"` + Operation *Operation `json:"operation,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/hostpool/model_plan.go b/resource-manager/desktopvirtualization/2021-09-03-preview/hostpool/model_plan.go new file mode 100644 index 00000000000..f81691c1b9a --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/hostpool/model_plan.go @@ -0,0 +1,12 @@ +package hostpool + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Plan struct { + Name string `json:"name"` + Product string `json:"product"` + PromotionCode *string `json:"promotionCode,omitempty"` + Publisher string `json:"publisher"` + Version *string `json:"version,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/hostpool/model_registrationinfo.go b/resource-manager/desktopvirtualization/2021-09-03-preview/hostpool/model_registrationinfo.go new file mode 100644 index 00000000000..ed356c7e596 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/hostpool/model_registrationinfo.go @@ -0,0 +1,28 @@ +package hostpool + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RegistrationInfo struct { + ExpirationTime *string `json:"expirationTime,omitempty"` + RegistrationTokenOperation *RegistrationTokenOperation `json:"registrationTokenOperation,omitempty"` + Token *string `json:"token,omitempty"` +} + +func (o *RegistrationInfo) GetExpirationTimeAsTime() (*time.Time, error) { + if o.ExpirationTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ExpirationTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *RegistrationInfo) SetExpirationTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ExpirationTime = &formatted +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/hostpool/model_registrationinfopatch.go b/resource-manager/desktopvirtualization/2021-09-03-preview/hostpool/model_registrationinfopatch.go new file mode 100644 index 00000000000..7340343045e --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/hostpool/model_registrationinfopatch.go @@ -0,0 +1,27 @@ +package hostpool + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RegistrationInfoPatch struct { + ExpirationTime *string `json:"expirationTime,omitempty"` + RegistrationTokenOperation *RegistrationTokenOperation `json:"registrationTokenOperation,omitempty"` +} + +func (o *RegistrationInfoPatch) GetExpirationTimeAsTime() (*time.Time, error) { + if o.ExpirationTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ExpirationTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *RegistrationInfoPatch) SetExpirationTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ExpirationTime = &formatted +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/hostpool/model_sku.go b/resource-manager/desktopvirtualization/2021-09-03-preview/hostpool/model_sku.go new file mode 100644 index 00000000000..26583f4fcea --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/hostpool/model_sku.go @@ -0,0 +1,12 @@ +package hostpool + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Sku struct { + Capacity *int64 `json:"capacity,omitempty"` + Family *string `json:"family,omitempty"` + Name string `json:"name"` + Size *string `json:"size,omitempty"` + Tier *SkuTier `json:"tier,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/hostpool/predicates.go b/resource-manager/desktopvirtualization/2021-09-03-preview/hostpool/predicates.go new file mode 100644 index 00000000000..27e04add212 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/hostpool/predicates.go @@ -0,0 +1,44 @@ +package hostpool + +type HostPoolOperationPredicate struct { + Etag *string + Id *string + Kind *string + Location *string + ManagedBy *string + Name *string + Type *string +} + +func (p HostPoolOperationPredicate) Matches(input HostPool) bool { + + if p.Etag != nil && (input.Etag == nil && *p.Etag != *input.Etag) { + return false + } + + if p.Id != nil && (input.Id == nil && *p.Id != *input.Id) { + return false + } + + if p.Kind != nil && (input.Kind == nil && *p.Kind != *input.Kind) { + return false + } + + if p.Location != nil && (input.Location == nil && *p.Location != *input.Location) { + return false + } + + if p.ManagedBy != nil && (input.ManagedBy == nil && *p.ManagedBy != *input.ManagedBy) { + return false + } + + if p.Name != nil && (input.Name == nil && *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil && *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/hostpool/version.go b/resource-manager/desktopvirtualization/2021-09-03-preview/hostpool/version.go new file mode 100644 index 00000000000..3601ff52ba2 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/hostpool/version.go @@ -0,0 +1,12 @@ +package hostpool + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2021-09-03-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/hostpool/%s", defaultApiVersion) +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/msiximage/client.go b/resource-manager/desktopvirtualization/2021-09-03-preview/msiximage/client.go new file mode 100644 index 00000000000..58c630f191a --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/msiximage/client.go @@ -0,0 +1,18 @@ +package msiximage + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MsixImageClient struct { + Client autorest.Client + baseUri string +} + +func NewMsixImageClientWithBaseURI(endpoint string) MsixImageClient { + return MsixImageClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/msiximage/id_hostpool.go b/resource-manager/desktopvirtualization/2021-09-03-preview/msiximage/id_hostpool.go new file mode 100644 index 00000000000..f1e2177bd07 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/msiximage/id_hostpool.go @@ -0,0 +1,124 @@ +package msiximage + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = HostPoolId{} + +// HostPoolId is a struct representing the Resource ID for a Host Pool +type HostPoolId struct { + SubscriptionId string + ResourceGroupName string + HostPoolName string +} + +// NewHostPoolID returns a new HostPoolId struct +func NewHostPoolID(subscriptionId string, resourceGroupName string, hostPoolName string) HostPoolId { + return HostPoolId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + HostPoolName: hostPoolName, + } +} + +// ParseHostPoolID parses 'input' into a HostPoolId +func ParseHostPoolID(input string) (*HostPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(HostPoolId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := HostPoolId{} + + 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.HostPoolName, ok = parsed.Parsed["hostPoolName"]; !ok { + return nil, fmt.Errorf("the segment 'hostPoolName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseHostPoolIDInsensitively parses 'input' case-insensitively into a HostPoolId +// note: this method should only be used for API response data and not user input +func ParseHostPoolIDInsensitively(input string) (*HostPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(HostPoolId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := HostPoolId{} + + 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.HostPoolName, ok = parsed.Parsed["hostPoolName"]; !ok { + return nil, fmt.Errorf("the segment 'hostPoolName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateHostPoolID checks that 'input' can be parsed as a Host Pool ID +func ValidateHostPoolID(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 := ParseHostPoolID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Host Pool ID +func (id HostPoolId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DesktopVirtualization/hostPools/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.HostPoolName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Host Pool ID +func (id HostPoolId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftDesktopVirtualization", "Microsoft.DesktopVirtualization", "Microsoft.DesktopVirtualization"), + resourceids.StaticSegment("staticHostPools", "hostPools", "hostPools"), + resourceids.UserSpecifiedSegment("hostPoolName", "hostPoolValue"), + } +} + +// String returns a human-readable description of this Host Pool ID +func (id HostPoolId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Host Pool Name: %q", id.HostPoolName), + } + return fmt.Sprintf("Host Pool (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/msiximage/id_hostpool_test.go b/resource-manager/desktopvirtualization/2021-09-03-preview/msiximage/id_hostpool_test.go new file mode 100644 index 00000000000..15fa27cd2cd --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/msiximage/id_hostpool_test.go @@ -0,0 +1,279 @@ +package msiximage + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = HostPoolId{} + +func TestNewHostPoolID(t *testing.T) { + id := NewHostPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "hostPoolValue") + + 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.HostPoolName != "hostPoolValue" { + t.Fatalf("Expected %q but got %q for Segment 'HostPoolName'", id.HostPoolName, "hostPoolValue") + } +} + +func TestFormatHostPoolID(t *testing.T) { + actual := NewHostPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "hostPoolValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseHostPoolID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *HostPoolId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue", + Expected: &HostPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + HostPoolName: "hostPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseHostPoolID(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.HostPoolName != v.Expected.HostPoolName { + t.Fatalf("Expected %q but got %q for HostPoolName", v.Expected.HostPoolName, actual.HostPoolName) + } + + } +} + +func TestParseHostPoolIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *HostPoolId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue", + Expected: &HostPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + HostPoolName: "hostPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe", + Expected: &HostPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + HostPoolName: "hOsTpOoLvAlUe", + }, + }, + { + // 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.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseHostPoolIDInsensitively(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.HostPoolName != v.Expected.HostPoolName { + t.Fatalf("Expected %q but got %q for HostPoolName", v.Expected.HostPoolName, actual.HostPoolName) + } + + } +} + +func TestSegmentsForHostPoolId(t *testing.T) { + segments := HostPoolId{}.Segments() + if len(segments) == 0 { + t.Fatalf("HostPoolId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/msiximage/method_expand_autorest.go b/resource-manager/desktopvirtualization/2021-09-03-preview/msiximage/method_expand_autorest.go new file mode 100644 index 00000000000..a5ed05244d3 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/msiximage/method_expand_autorest.go @@ -0,0 +1,187 @@ +package msiximage + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExpandOperationResponse struct { + HttpResponse *http.Response + Model *[]ExpandMsixImage + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ExpandOperationResponse, error) +} + +type ExpandCompleteResult struct { + Items []ExpandMsixImage +} + +func (r ExpandOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ExpandOperationResponse) LoadMore(ctx context.Context) (resp ExpandOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// Expand ... +func (c MsixImageClient) Expand(ctx context.Context, id HostPoolId, input MSIXImageURI) (resp ExpandOperationResponse, err error) { + req, err := c.preparerForExpand(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "msiximage.MsixImageClient", "Expand", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "msiximage.MsixImageClient", "Expand", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForExpand(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "msiximage.MsixImageClient", "Expand", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// ExpandComplete retrieves all of the results into a single object +func (c MsixImageClient) ExpandComplete(ctx context.Context, id HostPoolId, input MSIXImageURI) (ExpandCompleteResult, error) { + return c.ExpandCompleteMatchingPredicate(ctx, id, input, ExpandMsixImageOperationPredicate{}) +} + +// ExpandCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c MsixImageClient) ExpandCompleteMatchingPredicate(ctx context.Context, id HostPoolId, input MSIXImageURI, predicate ExpandMsixImageOperationPredicate) (resp ExpandCompleteResult, err error) { + items := make([]ExpandMsixImage, 0) + + page, err := c.Expand(ctx, id, input) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ExpandCompleteResult{ + Items: items, + } + return out, nil +} + +// preparerForExpand prepares the Expand request. +func (c MsixImageClient) preparerForExpand(ctx context.Context, id HostPoolId, input MSIXImageURI) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/expandMsixImage", id.ID())), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForExpandWithNextLink prepares the Expand request with the given nextLink token. +func (c MsixImageClient) preparerForExpandWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForExpand handles the response to the Expand request. The method always +// closes the http.Response Body. +func (c MsixImageClient) responderForExpand(resp *http.Response) (result ExpandOperationResponse, err error) { + type page struct { + Values []ExpandMsixImage `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ExpandOperationResponse, err error) { + req, err := c.preparerForExpandWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "msiximage.MsixImageClient", "Expand", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "msiximage.MsixImageClient", "Expand", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForExpand(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "msiximage.MsixImageClient", "Expand", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/msiximage/model_expandmsiximage.go b/resource-manager/desktopvirtualization/2021-09-03-preview/msiximage/model_expandmsiximage.go new file mode 100644 index 00000000000..8f231e46ec4 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/msiximage/model_expandmsiximage.go @@ -0,0 +1,11 @@ +package msiximage + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExpandMsixImage struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ExpandMsixImageProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/msiximage/model_expandmsiximageproperties.go b/resource-manager/desktopvirtualization/2021-09-03-preview/msiximage/model_expandmsiximageproperties.go new file mode 100644 index 00000000000..cc2cc78fdb2 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/msiximage/model_expandmsiximageproperties.go @@ -0,0 +1,38 @@ +package msiximage + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExpandMsixImageProperties struct { + DisplayName *string `json:"displayName,omitempty"` + ImagePath *string `json:"imagePath,omitempty"` + IsActive *bool `json:"isActive,omitempty"` + IsRegularRegistration *bool `json:"isRegularRegistration,omitempty"` + LastUpdated *string `json:"lastUpdated,omitempty"` + PackageAlias *string `json:"packageAlias,omitempty"` + PackageApplications *[]MsixPackageApplications `json:"packageApplications,omitempty"` + PackageDependencies *[]MsixPackageDependencies `json:"packageDependencies,omitempty"` + PackageFamilyName *string `json:"packageFamilyName,omitempty"` + PackageFullName *string `json:"packageFullName,omitempty"` + PackageName *string `json:"packageName,omitempty"` + PackageRelativePath *string `json:"packageRelativePath,omitempty"` + Version *string `json:"version,omitempty"` +} + +func (o *ExpandMsixImageProperties) GetLastUpdatedAsTime() (*time.Time, error) { + if o.LastUpdated == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastUpdated, "2006-01-02T15:04:05Z07:00") +} + +func (o *ExpandMsixImageProperties) SetLastUpdatedAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastUpdated = &formatted +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/msiximage/model_msiximageuri.go b/resource-manager/desktopvirtualization/2021-09-03-preview/msiximage/model_msiximageuri.go new file mode 100644 index 00000000000..d7ac653b01b --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/msiximage/model_msiximageuri.go @@ -0,0 +1,8 @@ +package msiximage + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MSIXImageURI struct { + Uri *string `json:"uri,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/msiximage/model_msixpackageapplications.go b/resource-manager/desktopvirtualization/2021-09-03-preview/msiximage/model_msixpackageapplications.go new file mode 100644 index 00000000000..372e033f8bb --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/msiximage/model_msixpackageapplications.go @@ -0,0 +1,14 @@ +package msiximage + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MsixPackageApplications struct { + AppId *string `json:"appId,omitempty"` + AppUserModelID *string `json:"appUserModelID,omitempty"` + Description *string `json:"description,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + IconImageName *string `json:"iconImageName,omitempty"` + RawIcon *string `json:"rawIcon,omitempty"` + RawPng *string `json:"rawPng,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/msiximage/model_msixpackagedependencies.go b/resource-manager/desktopvirtualization/2021-09-03-preview/msiximage/model_msixpackagedependencies.go new file mode 100644 index 00000000000..28c81df069c --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/msiximage/model_msixpackagedependencies.go @@ -0,0 +1,10 @@ +package msiximage + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MsixPackageDependencies struct { + DependencyName *string `json:"dependencyName,omitempty"` + MinVersion *string `json:"minVersion,omitempty"` + Publisher *string `json:"publisher,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/msiximage/predicates.go b/resource-manager/desktopvirtualization/2021-09-03-preview/msiximage/predicates.go new file mode 100644 index 00000000000..b281dec62eb --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/msiximage/predicates.go @@ -0,0 +1,24 @@ +package msiximage + +type ExpandMsixImageOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ExpandMsixImageOperationPredicate) Matches(input ExpandMsixImage) bool { + + if p.Id != nil && (input.Id == nil && *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil && *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil && *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/msiximage/version.go b/resource-manager/desktopvirtualization/2021-09-03-preview/msiximage/version.go new file mode 100644 index 00000000000..80c9552da98 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/msiximage/version.go @@ -0,0 +1,12 @@ +package msiximage + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2021-09-03-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/msiximage/%s", defaultApiVersion) +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/msixpackage/client.go b/resource-manager/desktopvirtualization/2021-09-03-preview/msixpackage/client.go new file mode 100644 index 00000000000..03a3db16d83 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/msixpackage/client.go @@ -0,0 +1,18 @@ +package msixpackage + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MSIXPackageClient struct { + Client autorest.Client + baseUri string +} + +func NewMSIXPackageClientWithBaseURI(endpoint string) MSIXPackageClient { + return MSIXPackageClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/msixpackage/id_hostpool.go b/resource-manager/desktopvirtualization/2021-09-03-preview/msixpackage/id_hostpool.go new file mode 100644 index 00000000000..459763c2c4b --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/msixpackage/id_hostpool.go @@ -0,0 +1,124 @@ +package msixpackage + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = HostPoolId{} + +// HostPoolId is a struct representing the Resource ID for a Host Pool +type HostPoolId struct { + SubscriptionId string + ResourceGroupName string + HostPoolName string +} + +// NewHostPoolID returns a new HostPoolId struct +func NewHostPoolID(subscriptionId string, resourceGroupName string, hostPoolName string) HostPoolId { + return HostPoolId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + HostPoolName: hostPoolName, + } +} + +// ParseHostPoolID parses 'input' into a HostPoolId +func ParseHostPoolID(input string) (*HostPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(HostPoolId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := HostPoolId{} + + 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.HostPoolName, ok = parsed.Parsed["hostPoolName"]; !ok { + return nil, fmt.Errorf("the segment 'hostPoolName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseHostPoolIDInsensitively parses 'input' case-insensitively into a HostPoolId +// note: this method should only be used for API response data and not user input +func ParseHostPoolIDInsensitively(input string) (*HostPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(HostPoolId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := HostPoolId{} + + 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.HostPoolName, ok = parsed.Parsed["hostPoolName"]; !ok { + return nil, fmt.Errorf("the segment 'hostPoolName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateHostPoolID checks that 'input' can be parsed as a Host Pool ID +func ValidateHostPoolID(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 := ParseHostPoolID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Host Pool ID +func (id HostPoolId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DesktopVirtualization/hostPools/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.HostPoolName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Host Pool ID +func (id HostPoolId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftDesktopVirtualization", "Microsoft.DesktopVirtualization", "Microsoft.DesktopVirtualization"), + resourceids.StaticSegment("staticHostPools", "hostPools", "hostPools"), + resourceids.UserSpecifiedSegment("hostPoolName", "hostPoolValue"), + } +} + +// String returns a human-readable description of this Host Pool ID +func (id HostPoolId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Host Pool Name: %q", id.HostPoolName), + } + return fmt.Sprintf("Host Pool (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/msixpackage/id_hostpool_test.go b/resource-manager/desktopvirtualization/2021-09-03-preview/msixpackage/id_hostpool_test.go new file mode 100644 index 00000000000..4ce0847bd3e --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/msixpackage/id_hostpool_test.go @@ -0,0 +1,279 @@ +package msixpackage + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = HostPoolId{} + +func TestNewHostPoolID(t *testing.T) { + id := NewHostPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "hostPoolValue") + + 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.HostPoolName != "hostPoolValue" { + t.Fatalf("Expected %q but got %q for Segment 'HostPoolName'", id.HostPoolName, "hostPoolValue") + } +} + +func TestFormatHostPoolID(t *testing.T) { + actual := NewHostPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "hostPoolValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseHostPoolID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *HostPoolId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue", + Expected: &HostPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + HostPoolName: "hostPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseHostPoolID(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.HostPoolName != v.Expected.HostPoolName { + t.Fatalf("Expected %q but got %q for HostPoolName", v.Expected.HostPoolName, actual.HostPoolName) + } + + } +} + +func TestParseHostPoolIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *HostPoolId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue", + Expected: &HostPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + HostPoolName: "hostPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe", + Expected: &HostPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + HostPoolName: "hOsTpOoLvAlUe", + }, + }, + { + // 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.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseHostPoolIDInsensitively(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.HostPoolName != v.Expected.HostPoolName { + t.Fatalf("Expected %q but got %q for HostPoolName", v.Expected.HostPoolName, actual.HostPoolName) + } + + } +} + +func TestSegmentsForHostPoolId(t *testing.T) { + segments := HostPoolId{}.Segments() + if len(segments) == 0 { + t.Fatalf("HostPoolId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/msixpackage/id_msixpackage.go b/resource-manager/desktopvirtualization/2021-09-03-preview/msixpackage/id_msixpackage.go new file mode 100644 index 00000000000..77408093011 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/msixpackage/id_msixpackage.go @@ -0,0 +1,137 @@ +package msixpackage + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = MsixPackageId{} + +// MsixPackageId is a struct representing the Resource ID for a Msix Package +type MsixPackageId struct { + SubscriptionId string + ResourceGroupName string + HostPoolName string + MsixPackageFullName string +} + +// NewMsixPackageID returns a new MsixPackageId struct +func NewMsixPackageID(subscriptionId string, resourceGroupName string, hostPoolName string, msixPackageFullName string) MsixPackageId { + return MsixPackageId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + HostPoolName: hostPoolName, + MsixPackageFullName: msixPackageFullName, + } +} + +// ParseMsixPackageID parses 'input' into a MsixPackageId +func ParseMsixPackageID(input string) (*MsixPackageId, error) { + parser := resourceids.NewParserFromResourceIdType(MsixPackageId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := MsixPackageId{} + + 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.HostPoolName, ok = parsed.Parsed["hostPoolName"]; !ok { + return nil, fmt.Errorf("the segment 'hostPoolName' was not found in the resource id %q", input) + } + + if id.MsixPackageFullName, ok = parsed.Parsed["msixPackageFullName"]; !ok { + return nil, fmt.Errorf("the segment 'msixPackageFullName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseMsixPackageIDInsensitively parses 'input' case-insensitively into a MsixPackageId +// note: this method should only be used for API response data and not user input +func ParseMsixPackageIDInsensitively(input string) (*MsixPackageId, error) { + parser := resourceids.NewParserFromResourceIdType(MsixPackageId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := MsixPackageId{} + + 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.HostPoolName, ok = parsed.Parsed["hostPoolName"]; !ok { + return nil, fmt.Errorf("the segment 'hostPoolName' was not found in the resource id %q", input) + } + + if id.MsixPackageFullName, ok = parsed.Parsed["msixPackageFullName"]; !ok { + return nil, fmt.Errorf("the segment 'msixPackageFullName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateMsixPackageID checks that 'input' can be parsed as a Msix Package ID +func ValidateMsixPackageID(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 := ParseMsixPackageID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Msix Package ID +func (id MsixPackageId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DesktopVirtualization/hostPools/%s/msixPackages/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.HostPoolName, id.MsixPackageFullName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Msix Package ID +func (id MsixPackageId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftDesktopVirtualization", "Microsoft.DesktopVirtualization", "Microsoft.DesktopVirtualization"), + resourceids.StaticSegment("staticHostPools", "hostPools", "hostPools"), + resourceids.UserSpecifiedSegment("hostPoolName", "hostPoolValue"), + resourceids.StaticSegment("staticMsixPackages", "msixPackages", "msixPackages"), + resourceids.UserSpecifiedSegment("msixPackageFullName", "msixPackageFullValue"), + } +} + +// String returns a human-readable description of this Msix Package ID +func (id MsixPackageId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Host Pool Name: %q", id.HostPoolName), + fmt.Sprintf("Msix Package Full Name: %q", id.MsixPackageFullName), + } + return fmt.Sprintf("Msix Package (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/msixpackage/id_msixpackage_test.go b/resource-manager/desktopvirtualization/2021-09-03-preview/msixpackage/id_msixpackage_test.go new file mode 100644 index 00000000000..e4060fd76cd --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/msixpackage/id_msixpackage_test.go @@ -0,0 +1,324 @@ +package msixpackage + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = MsixPackageId{} + +func TestNewMsixPackageID(t *testing.T) { + id := NewMsixPackageID("12345678-1234-9876-4563-123456789012", "example-resource-group", "hostPoolValue", "msixPackageFullValue") + + 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.HostPoolName != "hostPoolValue" { + t.Fatalf("Expected %q but got %q for Segment 'HostPoolName'", id.HostPoolName, "hostPoolValue") + } + + if id.MsixPackageFullName != "msixPackageFullValue" { + t.Fatalf("Expected %q but got %q for Segment 'MsixPackageFullName'", id.MsixPackageFullName, "msixPackageFullValue") + } +} + +func TestFormatMsixPackageID(t *testing.T) { + actual := NewMsixPackageID("12345678-1234-9876-4563-123456789012", "example-resource-group", "hostPoolValue", "msixPackageFullValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/msixPackages/msixPackageFullValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseMsixPackageID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *MsixPackageId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/msixPackages", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/msixPackages/msixPackageFullValue", + Expected: &MsixPackageId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + HostPoolName: "hostPoolValue", + MsixPackageFullName: "msixPackageFullValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/msixPackages/msixPackageFullValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseMsixPackageID(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.HostPoolName != v.Expected.HostPoolName { + t.Fatalf("Expected %q but got %q for HostPoolName", v.Expected.HostPoolName, actual.HostPoolName) + } + + if actual.MsixPackageFullName != v.Expected.MsixPackageFullName { + t.Fatalf("Expected %q but got %q for MsixPackageFullName", v.Expected.MsixPackageFullName, actual.MsixPackageFullName) + } + + } +} + +func TestParseMsixPackageIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *MsixPackageId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/msixPackages", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe/mSiXpAcKaGeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/msixPackages/msixPackageFullValue", + Expected: &MsixPackageId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + HostPoolName: "hostPoolValue", + MsixPackageFullName: "msixPackageFullValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/msixPackages/msixPackageFullValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe/mSiXpAcKaGeS/mSiXpAcKaGeFuLlVaLuE", + Expected: &MsixPackageId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + HostPoolName: "hOsTpOoLvAlUe", + MsixPackageFullName: "mSiXpAcKaGeFuLlVaLuE", + }, + }, + { + // 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.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe/mSiXpAcKaGeS/mSiXpAcKaGeFuLlVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseMsixPackageIDInsensitively(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.HostPoolName != v.Expected.HostPoolName { + t.Fatalf("Expected %q but got %q for HostPoolName", v.Expected.HostPoolName, actual.HostPoolName) + } + + if actual.MsixPackageFullName != v.Expected.MsixPackageFullName { + t.Fatalf("Expected %q but got %q for MsixPackageFullName", v.Expected.MsixPackageFullName, actual.MsixPackageFullName) + } + + } +} + +func TestSegmentsForMsixPackageId(t *testing.T) { + segments := MsixPackageId{}.Segments() + if len(segments) == 0 { + t.Fatalf("MsixPackageId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/msixpackage/method_createorupdate_autorest.go b/resource-manager/desktopvirtualization/2021-09-03-preview/msixpackage/method_createorupdate_autorest.go new file mode 100644 index 00000000000..86e8751d5a6 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/msixpackage/method_createorupdate_autorest.go @@ -0,0 +1,68 @@ +package msixpackage + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + Model *MSIXPackage +} + +// CreateOrUpdate ... +func (c MSIXPackageClient) CreateOrUpdate(ctx context.Context, id MsixPackageId, input MSIXPackage) (result CreateOrUpdateOperationResponse, err error) { + req, err := c.preparerForCreateOrUpdate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "msixpackage.MSIXPackageClient", "CreateOrUpdate", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "msixpackage.MSIXPackageClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForCreateOrUpdate(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "msixpackage.MSIXPackageClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForCreateOrUpdate prepares the CreateOrUpdate request. +func (c MSIXPackageClient) preparerForCreateOrUpdate(ctx context.Context, id MsixPackageId, input MSIXPackage) (*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)) +} + +// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always +// closes the http.Response Body. +func (c MSIXPackageClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/msixpackage/method_delete_autorest.go b/resource-manager/desktopvirtualization/2021-09-03-preview/msixpackage/method_delete_autorest.go new file mode 100644 index 00000000000..9441b3f334c --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/msixpackage/method_delete_autorest.go @@ -0,0 +1,65 @@ +package msixpackage + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response +} + +// Delete ... +func (c MSIXPackageClient) Delete(ctx context.Context, id MsixPackageId) (result DeleteOperationResponse, err error) { + req, err := c.preparerForDelete(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "msixpackage.MSIXPackageClient", "Delete", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "msixpackage.MSIXPackageClient", "Delete", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForDelete(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "msixpackage.MSIXPackageClient", "Delete", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForDelete prepares the Delete request. +func (c MSIXPackageClient) preparerForDelete(ctx context.Context, id MsixPackageId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + 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 MSIXPackageClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/msixpackage/method_get_autorest.go b/resource-manager/desktopvirtualization/2021-09-03-preview/msixpackage/method_get_autorest.go new file mode 100644 index 00000000000..7efbe5a56a1 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/msixpackage/method_get_autorest.go @@ -0,0 +1,67 @@ +package msixpackage + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *MSIXPackage +} + +// Get ... +func (c MSIXPackageClient) Get(ctx context.Context, id MsixPackageId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "msixpackage.MSIXPackageClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "msixpackage.MSIXPackageClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "msixpackage.MSIXPackageClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c MSIXPackageClient) preparerForGet(ctx context.Context, id MsixPackageId) (*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 MSIXPackageClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/msixpackage/method_list_autorest.go b/resource-manager/desktopvirtualization/2021-09-03-preview/msixpackage/method_list_autorest.go new file mode 100644 index 00000000000..7968f46e6cc --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/msixpackage/method_list_autorest.go @@ -0,0 +1,186 @@ +package msixpackage + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + Model *[]MSIXPackage + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) +} + +type ListCompleteResult struct { + Items []MSIXPackage +} + +func (r ListOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// List ... +func (c MSIXPackageClient) List(ctx context.Context, id HostPoolId) (resp ListOperationResponse, err error) { + req, err := c.preparerForList(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "msixpackage.MSIXPackageClient", "List", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "msixpackage.MSIXPackageClient", "List", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForList(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "msixpackage.MSIXPackageClient", "List", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// ListComplete retrieves all of the results into a single object +func (c MSIXPackageClient) ListComplete(ctx context.Context, id HostPoolId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, MSIXPackageOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c MSIXPackageClient) ListCompleteMatchingPredicate(ctx context.Context, id HostPoolId, predicate MSIXPackageOperationPredicate) (resp ListCompleteResult, err error) { + items := make([]MSIXPackage, 0) + + page, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListCompleteResult{ + Items: items, + } + return out, nil +} + +// preparerForList prepares the List request. +func (c MSIXPackageClient) preparerForList(ctx context.Context, id HostPoolId) (*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/msixPackages", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListWithNextLink prepares the List request with the given nextLink token. +func (c MSIXPackageClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForList handles the response to the List request. The method always +// closes the http.Response Body. +func (c MSIXPackageClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { + type page struct { + Values []MSIXPackage `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { + req, err := c.preparerForListWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "msixpackage.MSIXPackageClient", "List", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "msixpackage.MSIXPackageClient", "List", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "msixpackage.MSIXPackageClient", "List", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/msixpackage/method_update_autorest.go b/resource-manager/desktopvirtualization/2021-09-03-preview/msixpackage/method_update_autorest.go new file mode 100644 index 00000000000..21ac45d7460 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/msixpackage/method_update_autorest.go @@ -0,0 +1,68 @@ +package msixpackage + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + HttpResponse *http.Response + Model *MSIXPackage +} + +// Update ... +func (c MSIXPackageClient) Update(ctx context.Context, id MsixPackageId, input MSIXPackagePatch) (result UpdateOperationResponse, err error) { + req, err := c.preparerForUpdate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "msixpackage.MSIXPackageClient", "Update", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "msixpackage.MSIXPackageClient", "Update", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForUpdate(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "msixpackage.MSIXPackageClient", "Update", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForUpdate prepares the Update request. +func (c MSIXPackageClient) preparerForUpdate(ctx context.Context, id MsixPackageId, input MSIXPackagePatch) (*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 MSIXPackageClient) responderForUpdate(resp *http.Response) (result UpdateOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/msixpackage/model_msixpackage.go b/resource-manager/desktopvirtualization/2021-09-03-preview/msixpackage/model_msixpackage.go new file mode 100644 index 00000000000..a7059e786c9 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/msixpackage/model_msixpackage.go @@ -0,0 +1,16 @@ +package msixpackage + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MSIXPackage struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties MSIXPackageProperties `json:"properties"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/msixpackage/model_msixpackageapplications.go b/resource-manager/desktopvirtualization/2021-09-03-preview/msixpackage/model_msixpackageapplications.go new file mode 100644 index 00000000000..0496360e8a7 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/msixpackage/model_msixpackageapplications.go @@ -0,0 +1,14 @@ +package msixpackage + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MsixPackageApplications struct { + AppId *string `json:"appId,omitempty"` + AppUserModelID *string `json:"appUserModelID,omitempty"` + Description *string `json:"description,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + IconImageName *string `json:"iconImageName,omitempty"` + RawIcon *string `json:"rawIcon,omitempty"` + RawPng *string `json:"rawPng,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/msixpackage/model_msixpackagedependencies.go b/resource-manager/desktopvirtualization/2021-09-03-preview/msixpackage/model_msixpackagedependencies.go new file mode 100644 index 00000000000..c61fd291e93 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/msixpackage/model_msixpackagedependencies.go @@ -0,0 +1,10 @@ +package msixpackage + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MsixPackageDependencies struct { + DependencyName *string `json:"dependencyName,omitempty"` + MinVersion *string `json:"minVersion,omitempty"` + Publisher *string `json:"publisher,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/msixpackage/model_msixpackagepatch.go b/resource-manager/desktopvirtualization/2021-09-03-preview/msixpackage/model_msixpackagepatch.go new file mode 100644 index 00000000000..c2289a672ea --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/msixpackage/model_msixpackagepatch.go @@ -0,0 +1,11 @@ +package msixpackage + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MSIXPackagePatch struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *MSIXPackagePatchProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/msixpackage/model_msixpackagepatchproperties.go b/resource-manager/desktopvirtualization/2021-09-03-preview/msixpackage/model_msixpackagepatchproperties.go new file mode 100644 index 00000000000..3cef321c214 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/msixpackage/model_msixpackagepatchproperties.go @@ -0,0 +1,10 @@ +package msixpackage + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MSIXPackagePatchProperties struct { + DisplayName *string `json:"displayName,omitempty"` + IsActive *bool `json:"isActive,omitempty"` + IsRegularRegistration *bool `json:"isRegularRegistration,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/msixpackage/model_msixpackageproperties.go b/resource-manager/desktopvirtualization/2021-09-03-preview/msixpackage/model_msixpackageproperties.go new file mode 100644 index 00000000000..92b3d2ccd51 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/msixpackage/model_msixpackageproperties.go @@ -0,0 +1,36 @@ +package msixpackage + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MSIXPackageProperties struct { + DisplayName *string `json:"displayName,omitempty"` + ImagePath *string `json:"imagePath,omitempty"` + IsActive *bool `json:"isActive,omitempty"` + IsRegularRegistration *bool `json:"isRegularRegistration,omitempty"` + LastUpdated *string `json:"lastUpdated,omitempty"` + PackageApplications *[]MsixPackageApplications `json:"packageApplications,omitempty"` + PackageDependencies *[]MsixPackageDependencies `json:"packageDependencies,omitempty"` + PackageFamilyName *string `json:"packageFamilyName,omitempty"` + PackageName *string `json:"packageName,omitempty"` + PackageRelativePath *string `json:"packageRelativePath,omitempty"` + Version *string `json:"version,omitempty"` +} + +func (o *MSIXPackageProperties) GetLastUpdatedAsTime() (*time.Time, error) { + if o.LastUpdated == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastUpdated, "2006-01-02T15:04:05Z07:00") +} + +func (o *MSIXPackageProperties) SetLastUpdatedAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastUpdated = &formatted +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/msixpackage/predicates.go b/resource-manager/desktopvirtualization/2021-09-03-preview/msixpackage/predicates.go new file mode 100644 index 00000000000..881b67fa98b --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/msixpackage/predicates.go @@ -0,0 +1,24 @@ +package msixpackage + +type MSIXPackageOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p MSIXPackageOperationPredicate) Matches(input MSIXPackage) bool { + + if p.Id != nil && (input.Id == nil && *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil && *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil && *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/msixpackage/version.go b/resource-manager/desktopvirtualization/2021-09-03-preview/msixpackage/version.go new file mode 100644 index 00000000000..5909acdbdbd --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/msixpackage/version.go @@ -0,0 +1,12 @@ +package msixpackage + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2021-09-03-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/msixpackage/%s", defaultApiVersion) +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/client.go b/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/client.go new file mode 100644 index 00000000000..709f051f3c9 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/client.go @@ -0,0 +1,18 @@ +package privatelink + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkClient struct { + Client autorest.Client + baseUri string +} + +func NewPrivateLinkClientWithBaseURI(endpoint string) PrivateLinkClient { + return PrivateLinkClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/constants.go b/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/constants.go new file mode 100644 index 00000000000..4f84c23f74f --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/constants.go @@ -0,0 +1,71 @@ +package privatelink + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionProvisioningState string + +const ( + PrivateEndpointConnectionProvisioningStateCreating PrivateEndpointConnectionProvisioningState = "Creating" + PrivateEndpointConnectionProvisioningStateDeleting PrivateEndpointConnectionProvisioningState = "Deleting" + PrivateEndpointConnectionProvisioningStateFailed PrivateEndpointConnectionProvisioningState = "Failed" + PrivateEndpointConnectionProvisioningStateSucceeded PrivateEndpointConnectionProvisioningState = "Succeeded" +) + +func PossibleValuesForPrivateEndpointConnectionProvisioningState() []string { + return []string{ + string(PrivateEndpointConnectionProvisioningStateCreating), + string(PrivateEndpointConnectionProvisioningStateDeleting), + string(PrivateEndpointConnectionProvisioningStateFailed), + string(PrivateEndpointConnectionProvisioningStateSucceeded), + } +} + +func parsePrivateEndpointConnectionProvisioningState(input string) (*PrivateEndpointConnectionProvisioningState, error) { + vals := map[string]PrivateEndpointConnectionProvisioningState{ + "creating": PrivateEndpointConnectionProvisioningStateCreating, + "deleting": PrivateEndpointConnectionProvisioningStateDeleting, + "failed": PrivateEndpointConnectionProvisioningStateFailed, + "succeeded": PrivateEndpointConnectionProvisioningStateSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PrivateEndpointConnectionProvisioningState(input) + return &out, nil +} + +type PrivateEndpointServiceConnectionStatus string + +const ( + PrivateEndpointServiceConnectionStatusApproved PrivateEndpointServiceConnectionStatus = "Approved" + PrivateEndpointServiceConnectionStatusPending PrivateEndpointServiceConnectionStatus = "Pending" + PrivateEndpointServiceConnectionStatusRejected PrivateEndpointServiceConnectionStatus = "Rejected" +) + +func PossibleValuesForPrivateEndpointServiceConnectionStatus() []string { + return []string{ + string(PrivateEndpointServiceConnectionStatusApproved), + string(PrivateEndpointServiceConnectionStatusPending), + string(PrivateEndpointServiceConnectionStatusRejected), + } +} + +func parsePrivateEndpointServiceConnectionStatus(input string) (*PrivateEndpointServiceConnectionStatus, error) { + vals := map[string]PrivateEndpointServiceConnectionStatus{ + "approved": PrivateEndpointServiceConnectionStatusApproved, + "pending": PrivateEndpointServiceConnectionStatusPending, + "rejected": PrivateEndpointServiceConnectionStatusRejected, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PrivateEndpointServiceConnectionStatus(input) + return &out, nil +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/id_hostpool.go b/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/id_hostpool.go new file mode 100644 index 00000000000..a61d2058e8d --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/id_hostpool.go @@ -0,0 +1,124 @@ +package privatelink + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = HostPoolId{} + +// HostPoolId is a struct representing the Resource ID for a Host Pool +type HostPoolId struct { + SubscriptionId string + ResourceGroupName string + HostPoolName string +} + +// NewHostPoolID returns a new HostPoolId struct +func NewHostPoolID(subscriptionId string, resourceGroupName string, hostPoolName string) HostPoolId { + return HostPoolId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + HostPoolName: hostPoolName, + } +} + +// ParseHostPoolID parses 'input' into a HostPoolId +func ParseHostPoolID(input string) (*HostPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(HostPoolId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := HostPoolId{} + + 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.HostPoolName, ok = parsed.Parsed["hostPoolName"]; !ok { + return nil, fmt.Errorf("the segment 'hostPoolName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseHostPoolIDInsensitively parses 'input' case-insensitively into a HostPoolId +// note: this method should only be used for API response data and not user input +func ParseHostPoolIDInsensitively(input string) (*HostPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(HostPoolId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := HostPoolId{} + + 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.HostPoolName, ok = parsed.Parsed["hostPoolName"]; !ok { + return nil, fmt.Errorf("the segment 'hostPoolName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateHostPoolID checks that 'input' can be parsed as a Host Pool ID +func ValidateHostPoolID(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 := ParseHostPoolID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Host Pool ID +func (id HostPoolId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DesktopVirtualization/hostPools/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.HostPoolName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Host Pool ID +func (id HostPoolId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftDesktopVirtualization", "Microsoft.DesktopVirtualization", "Microsoft.DesktopVirtualization"), + resourceids.StaticSegment("staticHostPools", "hostPools", "hostPools"), + resourceids.UserSpecifiedSegment("hostPoolName", "hostPoolValue"), + } +} + +// String returns a human-readable description of this Host Pool ID +func (id HostPoolId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Host Pool Name: %q", id.HostPoolName), + } + return fmt.Sprintf("Host Pool (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/id_hostpool_test.go b/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/id_hostpool_test.go new file mode 100644 index 00000000000..826d59362f5 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/id_hostpool_test.go @@ -0,0 +1,279 @@ +package privatelink + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = HostPoolId{} + +func TestNewHostPoolID(t *testing.T) { + id := NewHostPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "hostPoolValue") + + 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.HostPoolName != "hostPoolValue" { + t.Fatalf("Expected %q but got %q for Segment 'HostPoolName'", id.HostPoolName, "hostPoolValue") + } +} + +func TestFormatHostPoolID(t *testing.T) { + actual := NewHostPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "hostPoolValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseHostPoolID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *HostPoolId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue", + Expected: &HostPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + HostPoolName: "hostPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseHostPoolID(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.HostPoolName != v.Expected.HostPoolName { + t.Fatalf("Expected %q but got %q for HostPoolName", v.Expected.HostPoolName, actual.HostPoolName) + } + + } +} + +func TestParseHostPoolIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *HostPoolId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue", + Expected: &HostPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + HostPoolName: "hostPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe", + Expected: &HostPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + HostPoolName: "hOsTpOoLvAlUe", + }, + }, + { + // 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.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseHostPoolIDInsensitively(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.HostPoolName != v.Expected.HostPoolName { + t.Fatalf("Expected %q but got %q for HostPoolName", v.Expected.HostPoolName, actual.HostPoolName) + } + + } +} + +func TestSegmentsForHostPoolId(t *testing.T) { + segments := HostPoolId{}.Segments() + if len(segments) == 0 { + t.Fatalf("HostPoolId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/id_privateendpointconnection.go b/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/id_privateendpointconnection.go new file mode 100644 index 00000000000..276becf2ed0 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/id_privateendpointconnection.go @@ -0,0 +1,137 @@ +package privatelink + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = PrivateEndpointConnectionId{} + +// PrivateEndpointConnectionId is a struct representing the Resource ID for a Private Endpoint Connection +type PrivateEndpointConnectionId struct { + SubscriptionId string + ResourceGroupName string + HostPoolName string + PrivateEndpointConnectionName string +} + +// NewPrivateEndpointConnectionID returns a new PrivateEndpointConnectionId struct +func NewPrivateEndpointConnectionID(subscriptionId string, resourceGroupName string, hostPoolName string, privateEndpointConnectionName string) PrivateEndpointConnectionId { + return PrivateEndpointConnectionId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + HostPoolName: hostPoolName, + PrivateEndpointConnectionName: privateEndpointConnectionName, + } +} + +// ParsePrivateEndpointConnectionID parses 'input' into a PrivateEndpointConnectionId +func ParsePrivateEndpointConnectionID(input string) (*PrivateEndpointConnectionId, error) { + parser := resourceids.NewParserFromResourceIdType(PrivateEndpointConnectionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := PrivateEndpointConnectionId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.HostPoolName, ok = parsed.Parsed["hostPoolName"]; !ok { + return nil, fmt.Errorf("the segment 'hostPoolName' was not found in the resource id %q", input) + } + + if id.PrivateEndpointConnectionName, ok = parsed.Parsed["privateEndpointConnectionName"]; !ok { + return nil, fmt.Errorf("the segment 'privateEndpointConnectionName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParsePrivateEndpointConnectionIDInsensitively parses 'input' case-insensitively into a PrivateEndpointConnectionId +// note: this method should only be used for API response data and not user input +func ParsePrivateEndpointConnectionIDInsensitively(input string) (*PrivateEndpointConnectionId, error) { + parser := resourceids.NewParserFromResourceIdType(PrivateEndpointConnectionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := PrivateEndpointConnectionId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.HostPoolName, ok = parsed.Parsed["hostPoolName"]; !ok { + return nil, fmt.Errorf("the segment 'hostPoolName' was not found in the resource id %q", input) + } + + if id.PrivateEndpointConnectionName, ok = parsed.Parsed["privateEndpointConnectionName"]; !ok { + return nil, fmt.Errorf("the segment 'privateEndpointConnectionName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidatePrivateEndpointConnectionID checks that 'input' can be parsed as a Private Endpoint Connection ID +func ValidatePrivateEndpointConnectionID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParsePrivateEndpointConnectionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Private Endpoint Connection ID +func (id PrivateEndpointConnectionId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DesktopVirtualization/hostPools/%s/privateEndpointConnections/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.HostPoolName, id.PrivateEndpointConnectionName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Private Endpoint Connection ID +func (id PrivateEndpointConnectionId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftDesktopVirtualization", "Microsoft.DesktopVirtualization", "Microsoft.DesktopVirtualization"), + resourceids.StaticSegment("staticHostPools", "hostPools", "hostPools"), + resourceids.UserSpecifiedSegment("hostPoolName", "hostPoolValue"), + resourceids.StaticSegment("staticPrivateEndpointConnections", "privateEndpointConnections", "privateEndpointConnections"), + resourceids.UserSpecifiedSegment("privateEndpointConnectionName", "privateEndpointConnectionValue"), + } +} + +// String returns a human-readable description of this Private Endpoint Connection ID +func (id PrivateEndpointConnectionId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Host Pool Name: %q", id.HostPoolName), + fmt.Sprintf("Private Endpoint Connection Name: %q", id.PrivateEndpointConnectionName), + } + return fmt.Sprintf("Private Endpoint Connection (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/id_privateendpointconnection_test.go b/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/id_privateendpointconnection_test.go new file mode 100644 index 00000000000..4a1968bb5cc --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/id_privateendpointconnection_test.go @@ -0,0 +1,324 @@ +package privatelink + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = PrivateEndpointConnectionId{} + +func TestNewPrivateEndpointConnectionID(t *testing.T) { + id := NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "hostPoolValue", "privateEndpointConnectionValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.HostPoolName != "hostPoolValue" { + t.Fatalf("Expected %q but got %q for Segment 'HostPoolName'", id.HostPoolName, "hostPoolValue") + } + + if id.PrivateEndpointConnectionName != "privateEndpointConnectionValue" { + t.Fatalf("Expected %q but got %q for Segment 'PrivateEndpointConnectionName'", id.PrivateEndpointConnectionName, "privateEndpointConnectionValue") + } +} + +func TestFormatPrivateEndpointConnectionID(t *testing.T) { + actual := NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "hostPoolValue", "privateEndpointConnectionValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/privateEndpointConnections/privateEndpointConnectionValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParsePrivateEndpointConnectionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateEndpointConnectionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/privateEndpointConnections", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/privateEndpointConnections/privateEndpointConnectionValue", + Expected: &PrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + HostPoolName: "hostPoolValue", + PrivateEndpointConnectionName: "privateEndpointConnectionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/privateEndpointConnections/privateEndpointConnectionValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateEndpointConnectionID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.HostPoolName != v.Expected.HostPoolName { + t.Fatalf("Expected %q but got %q for HostPoolName", v.Expected.HostPoolName, actual.HostPoolName) + } + + if actual.PrivateEndpointConnectionName != v.Expected.PrivateEndpointConnectionName { + t.Fatalf("Expected %q but got %q for PrivateEndpointConnectionName", v.Expected.PrivateEndpointConnectionName, actual.PrivateEndpointConnectionName) + } + + } +} + +func TestParsePrivateEndpointConnectionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateEndpointConnectionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/privateEndpointConnections", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe/pRiVaTeEnDpOiNtCoNnEcTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/privateEndpointConnections/privateEndpointConnectionValue", + Expected: &PrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + HostPoolName: "hostPoolValue", + PrivateEndpointConnectionName: "privateEndpointConnectionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/privateEndpointConnections/privateEndpointConnectionValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe/pRiVaTeEnDpOiNtCoNnEcTiOnS/pRiVaTeEnDpOiNtCoNnEcTiOnVaLuE", + Expected: &PrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + HostPoolName: "hOsTpOoLvAlUe", + PrivateEndpointConnectionName: "pRiVaTeEnDpOiNtCoNnEcTiOnVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe/pRiVaTeEnDpOiNtCoNnEcTiOnS/pRiVaTeEnDpOiNtCoNnEcTiOnVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateEndpointConnectionIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.HostPoolName != v.Expected.HostPoolName { + t.Fatalf("Expected %q but got %q for HostPoolName", v.Expected.HostPoolName, actual.HostPoolName) + } + + if actual.PrivateEndpointConnectionName != v.Expected.PrivateEndpointConnectionName { + t.Fatalf("Expected %q but got %q for PrivateEndpointConnectionName", v.Expected.PrivateEndpointConnectionName, actual.PrivateEndpointConnectionName) + } + + } +} + +func TestSegmentsForPrivateEndpointConnectionId(t *testing.T) { + segments := PrivateEndpointConnectionId{}.Segments() + if len(segments) == 0 { + t.Fatalf("PrivateEndpointConnectionId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/id_workspace.go b/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/id_workspace.go new file mode 100644 index 00000000000..ff0c3caccb3 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/id_workspace.go @@ -0,0 +1,124 @@ +package privatelink + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace +type WorkspaceId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string +} + +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, workspaceName string) WorkspaceId { + return WorkspaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + } +} + +// ParseWorkspaceID parses 'input' into a WorkspaceId +func ParseWorkspaceID(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(WorkspaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := WorkspaceId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.WorkspaceName, ok = parsed.Parsed["workspaceName"]; !ok { + return nil, fmt.Errorf("the segment 'workspaceName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(WorkspaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := WorkspaceId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.WorkspaceName, ok = parsed.Parsed["workspaceName"]; !ok { + return nil, fmt.Errorf("the segment 'workspaceName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DesktopVirtualization/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftDesktopVirtualization", "Microsoft.DesktopVirtualization", "Microsoft.DesktopVirtualization"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + } +} + +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/id_workspace_test.go b/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/id_workspace_test.go new file mode 100644 index 00000000000..b28649b2b1b --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/id_workspace_test.go @@ -0,0 +1,279 @@ +package privatelink + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = WorkspaceId{} + +func TestNewWorkspaceID(t *testing.T) { + id := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } +} + +func TestFormatWorkspaceID(t *testing.T) { + actual := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/workspaces/workspaceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/workspaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/workspaces/workspaceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestParseWorkspaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/wOrKsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/workspaces/workspaceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/wOrKsPaCeS/wOrKsPaCeVaLuE", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/wOrKsPaCeS/wOrKsPaCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestSegmentsForWorkspaceId(t *testing.T) { + segments := WorkspaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/id_workspaceprivateendpointconnection.go b/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/id_workspaceprivateendpointconnection.go new file mode 100644 index 00000000000..34bc71af20a --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/id_workspaceprivateendpointconnection.go @@ -0,0 +1,137 @@ +package privatelink + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = WorkspacePrivateEndpointConnectionId{} + +// WorkspacePrivateEndpointConnectionId is a struct representing the Resource ID for a Workspace Private Endpoint Connection +type WorkspacePrivateEndpointConnectionId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + PrivateEndpointConnectionName string +} + +// NewWorkspacePrivateEndpointConnectionID returns a new WorkspacePrivateEndpointConnectionId struct +func NewWorkspacePrivateEndpointConnectionID(subscriptionId string, resourceGroupName string, workspaceName string, privateEndpointConnectionName string) WorkspacePrivateEndpointConnectionId { + return WorkspacePrivateEndpointConnectionId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + PrivateEndpointConnectionName: privateEndpointConnectionName, + } +} + +// ParseWorkspacePrivateEndpointConnectionID parses 'input' into a WorkspacePrivateEndpointConnectionId +func ParseWorkspacePrivateEndpointConnectionID(input string) (*WorkspacePrivateEndpointConnectionId, error) { + parser := resourceids.NewParserFromResourceIdType(WorkspacePrivateEndpointConnectionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := WorkspacePrivateEndpointConnectionId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.WorkspaceName, ok = parsed.Parsed["workspaceName"]; !ok { + return nil, fmt.Errorf("the segment 'workspaceName' was not found in the resource id %q", input) + } + + if id.PrivateEndpointConnectionName, ok = parsed.Parsed["privateEndpointConnectionName"]; !ok { + return nil, fmt.Errorf("the segment 'privateEndpointConnectionName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseWorkspacePrivateEndpointConnectionIDInsensitively parses 'input' case-insensitively into a WorkspacePrivateEndpointConnectionId +// note: this method should only be used for API response data and not user input +func ParseWorkspacePrivateEndpointConnectionIDInsensitively(input string) (*WorkspacePrivateEndpointConnectionId, error) { + parser := resourceids.NewParserFromResourceIdType(WorkspacePrivateEndpointConnectionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := WorkspacePrivateEndpointConnectionId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.WorkspaceName, ok = parsed.Parsed["workspaceName"]; !ok { + return nil, fmt.Errorf("the segment 'workspaceName' was not found in the resource id %q", input) + } + + if id.PrivateEndpointConnectionName, ok = parsed.Parsed["privateEndpointConnectionName"]; !ok { + return nil, fmt.Errorf("the segment 'privateEndpointConnectionName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateWorkspacePrivateEndpointConnectionID checks that 'input' can be parsed as a Workspace Private Endpoint Connection ID +func ValidateWorkspacePrivateEndpointConnectionID(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 := ParseWorkspacePrivateEndpointConnectionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace Private Endpoint Connection ID +func (id WorkspacePrivateEndpointConnectionId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DesktopVirtualization/workspaces/%s/privateEndpointConnections/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.PrivateEndpointConnectionName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace Private Endpoint Connection ID +func (id WorkspacePrivateEndpointConnectionId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftDesktopVirtualization", "Microsoft.DesktopVirtualization", "Microsoft.DesktopVirtualization"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticPrivateEndpointConnections", "privateEndpointConnections", "privateEndpointConnections"), + resourceids.UserSpecifiedSegment("privateEndpointConnectionName", "privateEndpointConnectionValue"), + } +} + +// String returns a human-readable description of this Workspace Private Endpoint Connection ID +func (id WorkspacePrivateEndpointConnectionId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Private Endpoint Connection Name: %q", id.PrivateEndpointConnectionName), + } + return fmt.Sprintf("Workspace Private Endpoint Connection (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/id_workspaceprivateendpointconnection_test.go b/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/id_workspaceprivateendpointconnection_test.go new file mode 100644 index 00000000000..6de0e50b635 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/id_workspaceprivateendpointconnection_test.go @@ -0,0 +1,324 @@ +package privatelink + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = WorkspacePrivateEndpointConnectionId{} + +func TestNewWorkspacePrivateEndpointConnectionID(t *testing.T) { + id := NewWorkspacePrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "privateEndpointConnectionValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.PrivateEndpointConnectionName != "privateEndpointConnectionValue" { + t.Fatalf("Expected %q but got %q for Segment 'PrivateEndpointConnectionName'", id.PrivateEndpointConnectionName, "privateEndpointConnectionValue") + } +} + +func TestFormatWorkspacePrivateEndpointConnectionID(t *testing.T) { + actual := NewWorkspacePrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "privateEndpointConnectionValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/workspaces/workspaceValue/privateEndpointConnections/privateEndpointConnectionValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspacePrivateEndpointConnectionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspacePrivateEndpointConnectionId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/workspaces/workspaceValue/privateEndpointConnections", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/workspaces/workspaceValue/privateEndpointConnections/privateEndpointConnectionValue", + Expected: &WorkspacePrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + PrivateEndpointConnectionName: "privateEndpointConnectionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/workspaces/workspaceValue/privateEndpointConnections/privateEndpointConnectionValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspacePrivateEndpointConnectionID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.PrivateEndpointConnectionName != v.Expected.PrivateEndpointConnectionName { + t.Fatalf("Expected %q but got %q for PrivateEndpointConnectionName", v.Expected.PrivateEndpointConnectionName, actual.PrivateEndpointConnectionName) + } + + } +} + +func TestParseWorkspacePrivateEndpointConnectionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspacePrivateEndpointConnectionId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/workspaces/workspaceValue/privateEndpointConnections", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/wOrKsPaCeS/wOrKsPaCeVaLuE/pRiVaTeEnDpOiNtCoNnEcTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/workspaces/workspaceValue/privateEndpointConnections/privateEndpointConnectionValue", + Expected: &WorkspacePrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + PrivateEndpointConnectionName: "privateEndpointConnectionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/workspaces/workspaceValue/privateEndpointConnections/privateEndpointConnectionValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/wOrKsPaCeS/wOrKsPaCeVaLuE/pRiVaTeEnDpOiNtCoNnEcTiOnS/pRiVaTeEnDpOiNtCoNnEcTiOnVaLuE", + Expected: &WorkspacePrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + PrivateEndpointConnectionName: "pRiVaTeEnDpOiNtCoNnEcTiOnVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/wOrKsPaCeS/wOrKsPaCeVaLuE/pRiVaTeEnDpOiNtCoNnEcTiOnS/pRiVaTeEnDpOiNtCoNnEcTiOnVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspacePrivateEndpointConnectionIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.PrivateEndpointConnectionName != v.Expected.PrivateEndpointConnectionName { + t.Fatalf("Expected %q but got %q for PrivateEndpointConnectionName", v.Expected.PrivateEndpointConnectionName, actual.PrivateEndpointConnectionName) + } + + } +} + +func TestSegmentsForWorkspacePrivateEndpointConnectionId(t *testing.T) { + segments := WorkspacePrivateEndpointConnectionId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspacePrivateEndpointConnectionId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/method_privateendpointconnectionsdeletebyhostpool_autorest.go b/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/method_privateendpointconnectionsdeletebyhostpool_autorest.go new file mode 100644 index 00000000000..6e6d1f8b6fc --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/method_privateendpointconnectionsdeletebyhostpool_autorest.go @@ -0,0 +1,65 @@ +package privatelink + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionsDeleteByHostPoolOperationResponse struct { + HttpResponse *http.Response +} + +// PrivateEndpointConnectionsDeleteByHostPool ... +func (c PrivateLinkClient) PrivateEndpointConnectionsDeleteByHostPool(ctx context.Context, id PrivateEndpointConnectionId) (result PrivateEndpointConnectionsDeleteByHostPoolOperationResponse, err error) { + req, err := c.preparerForPrivateEndpointConnectionsDeleteByHostPool(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "PrivateEndpointConnectionsDeleteByHostPool", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "PrivateEndpointConnectionsDeleteByHostPool", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForPrivateEndpointConnectionsDeleteByHostPool(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "PrivateEndpointConnectionsDeleteByHostPool", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForPrivateEndpointConnectionsDeleteByHostPool prepares the PrivateEndpointConnectionsDeleteByHostPool request. +func (c PrivateLinkClient) preparerForPrivateEndpointConnectionsDeleteByHostPool(ctx context.Context, id PrivateEndpointConnectionId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsDelete(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForPrivateEndpointConnectionsDeleteByHostPool handles the response to the PrivateEndpointConnectionsDeleteByHostPool request. The method always +// closes the http.Response Body. +func (c PrivateLinkClient) responderForPrivateEndpointConnectionsDeleteByHostPool(resp *http.Response) (result PrivateEndpointConnectionsDeleteByHostPoolOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/method_privateendpointconnectionsdeletebyworkspace_autorest.go b/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/method_privateendpointconnectionsdeletebyworkspace_autorest.go new file mode 100644 index 00000000000..65890775649 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/method_privateendpointconnectionsdeletebyworkspace_autorest.go @@ -0,0 +1,65 @@ +package privatelink + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionsDeleteByWorkspaceOperationResponse struct { + HttpResponse *http.Response +} + +// PrivateEndpointConnectionsDeleteByWorkspace ... +func (c PrivateLinkClient) PrivateEndpointConnectionsDeleteByWorkspace(ctx context.Context, id WorkspacePrivateEndpointConnectionId) (result PrivateEndpointConnectionsDeleteByWorkspaceOperationResponse, err error) { + req, err := c.preparerForPrivateEndpointConnectionsDeleteByWorkspace(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "PrivateEndpointConnectionsDeleteByWorkspace", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "PrivateEndpointConnectionsDeleteByWorkspace", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForPrivateEndpointConnectionsDeleteByWorkspace(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "PrivateEndpointConnectionsDeleteByWorkspace", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForPrivateEndpointConnectionsDeleteByWorkspace prepares the PrivateEndpointConnectionsDeleteByWorkspace request. +func (c PrivateLinkClient) preparerForPrivateEndpointConnectionsDeleteByWorkspace(ctx context.Context, id WorkspacePrivateEndpointConnectionId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsDelete(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForPrivateEndpointConnectionsDeleteByWorkspace handles the response to the PrivateEndpointConnectionsDeleteByWorkspace request. The method always +// closes the http.Response Body. +func (c PrivateLinkClient) responderForPrivateEndpointConnectionsDeleteByWorkspace(resp *http.Response) (result PrivateEndpointConnectionsDeleteByWorkspaceOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/method_privateendpointconnectionsgetbyhostpool_autorest.go b/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/method_privateendpointconnectionsgetbyhostpool_autorest.go new file mode 100644 index 00000000000..b01928bc7c4 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/method_privateendpointconnectionsgetbyhostpool_autorest.go @@ -0,0 +1,67 @@ +package privatelink + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionsGetByHostPoolOperationResponse struct { + HttpResponse *http.Response + Model *PrivateEndpointConnectionWithSystemData +} + +// PrivateEndpointConnectionsGetByHostPool ... +func (c PrivateLinkClient) PrivateEndpointConnectionsGetByHostPool(ctx context.Context, id PrivateEndpointConnectionId) (result PrivateEndpointConnectionsGetByHostPoolOperationResponse, err error) { + req, err := c.preparerForPrivateEndpointConnectionsGetByHostPool(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "PrivateEndpointConnectionsGetByHostPool", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "PrivateEndpointConnectionsGetByHostPool", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForPrivateEndpointConnectionsGetByHostPool(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "PrivateEndpointConnectionsGetByHostPool", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForPrivateEndpointConnectionsGetByHostPool prepares the PrivateEndpointConnectionsGetByHostPool request. +func (c PrivateLinkClient) preparerForPrivateEndpointConnectionsGetByHostPool(ctx context.Context, id PrivateEndpointConnectionId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForPrivateEndpointConnectionsGetByHostPool handles the response to the PrivateEndpointConnectionsGetByHostPool request. The method always +// closes the http.Response Body. +func (c PrivateLinkClient) responderForPrivateEndpointConnectionsGetByHostPool(resp *http.Response) (result PrivateEndpointConnectionsGetByHostPoolOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/method_privateendpointconnectionsgetbyworkspace_autorest.go b/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/method_privateendpointconnectionsgetbyworkspace_autorest.go new file mode 100644 index 00000000000..7b551f8c1d3 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/method_privateendpointconnectionsgetbyworkspace_autorest.go @@ -0,0 +1,67 @@ +package privatelink + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionsGetByWorkspaceOperationResponse struct { + HttpResponse *http.Response + Model *PrivateEndpointConnectionWithSystemData +} + +// PrivateEndpointConnectionsGetByWorkspace ... +func (c PrivateLinkClient) PrivateEndpointConnectionsGetByWorkspace(ctx context.Context, id WorkspacePrivateEndpointConnectionId) (result PrivateEndpointConnectionsGetByWorkspaceOperationResponse, err error) { + req, err := c.preparerForPrivateEndpointConnectionsGetByWorkspace(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "PrivateEndpointConnectionsGetByWorkspace", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "PrivateEndpointConnectionsGetByWorkspace", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForPrivateEndpointConnectionsGetByWorkspace(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "PrivateEndpointConnectionsGetByWorkspace", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForPrivateEndpointConnectionsGetByWorkspace prepares the PrivateEndpointConnectionsGetByWorkspace request. +func (c PrivateLinkClient) preparerForPrivateEndpointConnectionsGetByWorkspace(ctx context.Context, id WorkspacePrivateEndpointConnectionId) (*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)) +} + +// responderForPrivateEndpointConnectionsGetByWorkspace handles the response to the PrivateEndpointConnectionsGetByWorkspace request. The method always +// closes the http.Response Body. +func (c PrivateLinkClient) responderForPrivateEndpointConnectionsGetByWorkspace(resp *http.Response) (result PrivateEndpointConnectionsGetByWorkspaceOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/method_privateendpointconnectionslistbyhostpool_autorest.go b/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/method_privateendpointconnectionslistbyhostpool_autorest.go new file mode 100644 index 00000000000..9e9856caea7 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/method_privateendpointconnectionslistbyhostpool_autorest.go @@ -0,0 +1,186 @@ +package privatelink + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionsListByHostPoolOperationResponse struct { + HttpResponse *http.Response + Model *[]PrivateEndpointConnectionWithSystemData + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (PrivateEndpointConnectionsListByHostPoolOperationResponse, error) +} + +type PrivateEndpointConnectionsListByHostPoolCompleteResult struct { + Items []PrivateEndpointConnectionWithSystemData +} + +func (r PrivateEndpointConnectionsListByHostPoolOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r PrivateEndpointConnectionsListByHostPoolOperationResponse) LoadMore(ctx context.Context) (resp PrivateEndpointConnectionsListByHostPoolOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// PrivateEndpointConnectionsListByHostPool ... +func (c PrivateLinkClient) PrivateEndpointConnectionsListByHostPool(ctx context.Context, id HostPoolId) (resp PrivateEndpointConnectionsListByHostPoolOperationResponse, err error) { + req, err := c.preparerForPrivateEndpointConnectionsListByHostPool(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "PrivateEndpointConnectionsListByHostPool", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "PrivateEndpointConnectionsListByHostPool", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForPrivateEndpointConnectionsListByHostPool(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "PrivateEndpointConnectionsListByHostPool", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// PrivateEndpointConnectionsListByHostPoolComplete retrieves all of the results into a single object +func (c PrivateLinkClient) PrivateEndpointConnectionsListByHostPoolComplete(ctx context.Context, id HostPoolId) (PrivateEndpointConnectionsListByHostPoolCompleteResult, error) { + return c.PrivateEndpointConnectionsListByHostPoolCompleteMatchingPredicate(ctx, id, PrivateEndpointConnectionWithSystemDataOperationPredicate{}) +} + +// PrivateEndpointConnectionsListByHostPoolCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c PrivateLinkClient) PrivateEndpointConnectionsListByHostPoolCompleteMatchingPredicate(ctx context.Context, id HostPoolId, predicate PrivateEndpointConnectionWithSystemDataOperationPredicate) (resp PrivateEndpointConnectionsListByHostPoolCompleteResult, err error) { + items := make([]PrivateEndpointConnectionWithSystemData, 0) + + page, err := c.PrivateEndpointConnectionsListByHostPool(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := PrivateEndpointConnectionsListByHostPoolCompleteResult{ + Items: items, + } + return out, nil +} + +// preparerForPrivateEndpointConnectionsListByHostPool prepares the PrivateEndpointConnectionsListByHostPool request. +func (c PrivateLinkClient) preparerForPrivateEndpointConnectionsListByHostPool(ctx context.Context, id HostPoolId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/privateEndpointConnections", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForPrivateEndpointConnectionsListByHostPoolWithNextLink prepares the PrivateEndpointConnectionsListByHostPool request with the given nextLink token. +func (c PrivateLinkClient) preparerForPrivateEndpointConnectionsListByHostPoolWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForPrivateEndpointConnectionsListByHostPool handles the response to the PrivateEndpointConnectionsListByHostPool request. The method always +// closes the http.Response Body. +func (c PrivateLinkClient) responderForPrivateEndpointConnectionsListByHostPool(resp *http.Response) (result PrivateEndpointConnectionsListByHostPoolOperationResponse, err error) { + type page struct { + Values []PrivateEndpointConnectionWithSystemData `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result PrivateEndpointConnectionsListByHostPoolOperationResponse, err error) { + req, err := c.preparerForPrivateEndpointConnectionsListByHostPoolWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "PrivateEndpointConnectionsListByHostPool", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "PrivateEndpointConnectionsListByHostPool", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForPrivateEndpointConnectionsListByHostPool(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "PrivateEndpointConnectionsListByHostPool", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/method_privateendpointconnectionslistbyworkspace_autorest.go b/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/method_privateendpointconnectionslistbyworkspace_autorest.go new file mode 100644 index 00000000000..15c4ed3e145 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/method_privateendpointconnectionslistbyworkspace_autorest.go @@ -0,0 +1,186 @@ +package privatelink + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionsListByWorkspaceOperationResponse struct { + HttpResponse *http.Response + Model *[]PrivateEndpointConnectionWithSystemData + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (PrivateEndpointConnectionsListByWorkspaceOperationResponse, error) +} + +type PrivateEndpointConnectionsListByWorkspaceCompleteResult struct { + Items []PrivateEndpointConnectionWithSystemData +} + +func (r PrivateEndpointConnectionsListByWorkspaceOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r PrivateEndpointConnectionsListByWorkspaceOperationResponse) LoadMore(ctx context.Context) (resp PrivateEndpointConnectionsListByWorkspaceOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// PrivateEndpointConnectionsListByWorkspace ... +func (c PrivateLinkClient) PrivateEndpointConnectionsListByWorkspace(ctx context.Context, id WorkspaceId) (resp PrivateEndpointConnectionsListByWorkspaceOperationResponse, err error) { + req, err := c.preparerForPrivateEndpointConnectionsListByWorkspace(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "PrivateEndpointConnectionsListByWorkspace", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "PrivateEndpointConnectionsListByWorkspace", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForPrivateEndpointConnectionsListByWorkspace(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "PrivateEndpointConnectionsListByWorkspace", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// PrivateEndpointConnectionsListByWorkspaceComplete retrieves all of the results into a single object +func (c PrivateLinkClient) PrivateEndpointConnectionsListByWorkspaceComplete(ctx context.Context, id WorkspaceId) (PrivateEndpointConnectionsListByWorkspaceCompleteResult, error) { + return c.PrivateEndpointConnectionsListByWorkspaceCompleteMatchingPredicate(ctx, id, PrivateEndpointConnectionWithSystemDataOperationPredicate{}) +} + +// PrivateEndpointConnectionsListByWorkspaceCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c PrivateLinkClient) PrivateEndpointConnectionsListByWorkspaceCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate PrivateEndpointConnectionWithSystemDataOperationPredicate) (resp PrivateEndpointConnectionsListByWorkspaceCompleteResult, err error) { + items := make([]PrivateEndpointConnectionWithSystemData, 0) + + page, err := c.PrivateEndpointConnectionsListByWorkspace(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := PrivateEndpointConnectionsListByWorkspaceCompleteResult{ + Items: items, + } + return out, nil +} + +// preparerForPrivateEndpointConnectionsListByWorkspace prepares the PrivateEndpointConnectionsListByWorkspace request. +func (c PrivateLinkClient) preparerForPrivateEndpointConnectionsListByWorkspace(ctx context.Context, id WorkspaceId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/privateEndpointConnections", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForPrivateEndpointConnectionsListByWorkspaceWithNextLink prepares the PrivateEndpointConnectionsListByWorkspace request with the given nextLink token. +func (c PrivateLinkClient) preparerForPrivateEndpointConnectionsListByWorkspaceWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForPrivateEndpointConnectionsListByWorkspace handles the response to the PrivateEndpointConnectionsListByWorkspace request. The method always +// closes the http.Response Body. +func (c PrivateLinkClient) responderForPrivateEndpointConnectionsListByWorkspace(resp *http.Response) (result PrivateEndpointConnectionsListByWorkspaceOperationResponse, err error) { + type page struct { + Values []PrivateEndpointConnectionWithSystemData `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result PrivateEndpointConnectionsListByWorkspaceOperationResponse, err error) { + req, err := c.preparerForPrivateEndpointConnectionsListByWorkspaceWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "PrivateEndpointConnectionsListByWorkspace", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "PrivateEndpointConnectionsListByWorkspace", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForPrivateEndpointConnectionsListByWorkspace(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "PrivateEndpointConnectionsListByWorkspace", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/method_privateendpointconnectionsupdatebyhostpool_autorest.go b/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/method_privateendpointconnectionsupdatebyhostpool_autorest.go new file mode 100644 index 00000000000..80b60d57329 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/method_privateendpointconnectionsupdatebyhostpool_autorest.go @@ -0,0 +1,68 @@ +package privatelink + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionsUpdateByHostPoolOperationResponse struct { + HttpResponse *http.Response + Model *PrivateEndpointConnectionWithSystemData +} + +// PrivateEndpointConnectionsUpdateByHostPool ... +func (c PrivateLinkClient) PrivateEndpointConnectionsUpdateByHostPool(ctx context.Context, id PrivateEndpointConnectionId, input PrivateEndpointConnection) (result PrivateEndpointConnectionsUpdateByHostPoolOperationResponse, err error) { + req, err := c.preparerForPrivateEndpointConnectionsUpdateByHostPool(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "PrivateEndpointConnectionsUpdateByHostPool", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "PrivateEndpointConnectionsUpdateByHostPool", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForPrivateEndpointConnectionsUpdateByHostPool(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "PrivateEndpointConnectionsUpdateByHostPool", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForPrivateEndpointConnectionsUpdateByHostPool prepares the PrivateEndpointConnectionsUpdateByHostPool request. +func (c PrivateLinkClient) preparerForPrivateEndpointConnectionsUpdateByHostPool(ctx context.Context, id PrivateEndpointConnectionId, input PrivateEndpointConnection) (*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)) +} + +// responderForPrivateEndpointConnectionsUpdateByHostPool handles the response to the PrivateEndpointConnectionsUpdateByHostPool request. The method always +// closes the http.Response Body. +func (c PrivateLinkClient) responderForPrivateEndpointConnectionsUpdateByHostPool(resp *http.Response) (result PrivateEndpointConnectionsUpdateByHostPoolOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/method_privateendpointconnectionsupdatebyworkspace_autorest.go b/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/method_privateendpointconnectionsupdatebyworkspace_autorest.go new file mode 100644 index 00000000000..dbb9c1b196c --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/method_privateendpointconnectionsupdatebyworkspace_autorest.go @@ -0,0 +1,68 @@ +package privatelink + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionsUpdateByWorkspaceOperationResponse struct { + HttpResponse *http.Response + Model *PrivateEndpointConnectionWithSystemData +} + +// PrivateEndpointConnectionsUpdateByWorkspace ... +func (c PrivateLinkClient) PrivateEndpointConnectionsUpdateByWorkspace(ctx context.Context, id WorkspacePrivateEndpointConnectionId, input PrivateEndpointConnection) (result PrivateEndpointConnectionsUpdateByWorkspaceOperationResponse, err error) { + req, err := c.preparerForPrivateEndpointConnectionsUpdateByWorkspace(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "PrivateEndpointConnectionsUpdateByWorkspace", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "PrivateEndpointConnectionsUpdateByWorkspace", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForPrivateEndpointConnectionsUpdateByWorkspace(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "PrivateEndpointConnectionsUpdateByWorkspace", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForPrivateEndpointConnectionsUpdateByWorkspace prepares the PrivateEndpointConnectionsUpdateByWorkspace request. +func (c PrivateLinkClient) preparerForPrivateEndpointConnectionsUpdateByWorkspace(ctx context.Context, id WorkspacePrivateEndpointConnectionId, input PrivateEndpointConnection) (*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)) +} + +// responderForPrivateEndpointConnectionsUpdateByWorkspace handles the response to the PrivateEndpointConnectionsUpdateByWorkspace request. The method always +// closes the http.Response Body. +func (c PrivateLinkClient) responderForPrivateEndpointConnectionsUpdateByWorkspace(resp *http.Response) (result PrivateEndpointConnectionsUpdateByWorkspaceOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/method_resourceslistbyhostpool_autorest.go b/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/method_resourceslistbyhostpool_autorest.go new file mode 100644 index 00000000000..bc69c62e590 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/method_resourceslistbyhostpool_autorest.go @@ -0,0 +1,186 @@ +package privatelink + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourcesListByHostPoolOperationResponse struct { + HttpResponse *http.Response + Model *[]PrivateLinkResource + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ResourcesListByHostPoolOperationResponse, error) +} + +type ResourcesListByHostPoolCompleteResult struct { + Items []PrivateLinkResource +} + +func (r ResourcesListByHostPoolOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ResourcesListByHostPoolOperationResponse) LoadMore(ctx context.Context) (resp ResourcesListByHostPoolOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// ResourcesListByHostPool ... +func (c PrivateLinkClient) ResourcesListByHostPool(ctx context.Context, id HostPoolId) (resp ResourcesListByHostPoolOperationResponse, err error) { + req, err := c.preparerForResourcesListByHostPool(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "ResourcesListByHostPool", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "ResourcesListByHostPool", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForResourcesListByHostPool(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "ResourcesListByHostPool", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// ResourcesListByHostPoolComplete retrieves all of the results into a single object +func (c PrivateLinkClient) ResourcesListByHostPoolComplete(ctx context.Context, id HostPoolId) (ResourcesListByHostPoolCompleteResult, error) { + return c.ResourcesListByHostPoolCompleteMatchingPredicate(ctx, id, PrivateLinkResourceOperationPredicate{}) +} + +// ResourcesListByHostPoolCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c PrivateLinkClient) ResourcesListByHostPoolCompleteMatchingPredicate(ctx context.Context, id HostPoolId, predicate PrivateLinkResourceOperationPredicate) (resp ResourcesListByHostPoolCompleteResult, err error) { + items := make([]PrivateLinkResource, 0) + + page, err := c.ResourcesListByHostPool(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ResourcesListByHostPoolCompleteResult{ + Items: items, + } + return out, nil +} + +// preparerForResourcesListByHostPool prepares the ResourcesListByHostPool request. +func (c PrivateLinkClient) preparerForResourcesListByHostPool(ctx context.Context, id HostPoolId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/privateLinkResources", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForResourcesListByHostPoolWithNextLink prepares the ResourcesListByHostPool request with the given nextLink token. +func (c PrivateLinkClient) preparerForResourcesListByHostPoolWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForResourcesListByHostPool handles the response to the ResourcesListByHostPool request. The method always +// closes the http.Response Body. +func (c PrivateLinkClient) responderForResourcesListByHostPool(resp *http.Response) (result ResourcesListByHostPoolOperationResponse, err error) { + type page struct { + Values []PrivateLinkResource `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ResourcesListByHostPoolOperationResponse, err error) { + req, err := c.preparerForResourcesListByHostPoolWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "ResourcesListByHostPool", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "ResourcesListByHostPool", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForResourcesListByHostPool(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "ResourcesListByHostPool", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/method_resourceslistbyworkspace_autorest.go b/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/method_resourceslistbyworkspace_autorest.go new file mode 100644 index 00000000000..4a18343954d --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/method_resourceslistbyworkspace_autorest.go @@ -0,0 +1,186 @@ +package privatelink + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourcesListByWorkspaceOperationResponse struct { + HttpResponse *http.Response + Model *[]PrivateLinkResource + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ResourcesListByWorkspaceOperationResponse, error) +} + +type ResourcesListByWorkspaceCompleteResult struct { + Items []PrivateLinkResource +} + +func (r ResourcesListByWorkspaceOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ResourcesListByWorkspaceOperationResponse) LoadMore(ctx context.Context) (resp ResourcesListByWorkspaceOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// ResourcesListByWorkspace ... +func (c PrivateLinkClient) ResourcesListByWorkspace(ctx context.Context, id WorkspaceId) (resp ResourcesListByWorkspaceOperationResponse, err error) { + req, err := c.preparerForResourcesListByWorkspace(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "ResourcesListByWorkspace", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "ResourcesListByWorkspace", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForResourcesListByWorkspace(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "ResourcesListByWorkspace", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// ResourcesListByWorkspaceComplete retrieves all of the results into a single object +func (c PrivateLinkClient) ResourcesListByWorkspaceComplete(ctx context.Context, id WorkspaceId) (ResourcesListByWorkspaceCompleteResult, error) { + return c.ResourcesListByWorkspaceCompleteMatchingPredicate(ctx, id, PrivateLinkResourceOperationPredicate{}) +} + +// ResourcesListByWorkspaceCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c PrivateLinkClient) ResourcesListByWorkspaceCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate PrivateLinkResourceOperationPredicate) (resp ResourcesListByWorkspaceCompleteResult, err error) { + items := make([]PrivateLinkResource, 0) + + page, err := c.ResourcesListByWorkspace(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ResourcesListByWorkspaceCompleteResult{ + Items: items, + } + return out, nil +} + +// preparerForResourcesListByWorkspace prepares the ResourcesListByWorkspace request. +func (c PrivateLinkClient) preparerForResourcesListByWorkspace(ctx context.Context, id WorkspaceId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/privateLinkResources", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForResourcesListByWorkspaceWithNextLink prepares the ResourcesListByWorkspace request with the given nextLink token. +func (c PrivateLinkClient) preparerForResourcesListByWorkspaceWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForResourcesListByWorkspace handles the response to the ResourcesListByWorkspace request. The method always +// closes the http.Response Body. +func (c PrivateLinkClient) responderForResourcesListByWorkspace(resp *http.Response) (result ResourcesListByWorkspaceOperationResponse, err error) { + type page struct { + Values []PrivateLinkResource `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ResourcesListByWorkspaceOperationResponse, err error) { + req, err := c.preparerForResourcesListByWorkspaceWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "ResourcesListByWorkspace", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "ResourcesListByWorkspace", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForResourcesListByWorkspace(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "ResourcesListByWorkspace", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/model_privateendpoint.go b/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/model_privateendpoint.go new file mode 100644 index 00000000000..774ed3c3a08 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/model_privateendpoint.go @@ -0,0 +1,8 @@ +package privatelink + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpoint struct { + Id *string `json:"id,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/model_privateendpointconnection.go b/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/model_privateendpointconnection.go new file mode 100644 index 00000000000..3989160769c --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/model_privateendpointconnection.go @@ -0,0 +1,11 @@ +package privatelink + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnection struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PrivateEndpointConnectionProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/model_privateendpointconnectionproperties.go b/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/model_privateendpointconnectionproperties.go new file mode 100644 index 00000000000..5ee2038e7a0 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/model_privateendpointconnectionproperties.go @@ -0,0 +1,10 @@ +package privatelink + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionProperties struct { + PrivateEndpoint *PrivateEndpoint `json:"privateEndpoint,omitempty"` + PrivateLinkServiceConnectionState PrivateLinkServiceConnectionState `json:"privateLinkServiceConnectionState"` + ProvisioningState *PrivateEndpointConnectionProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/model_privateendpointconnectionwithsystemdata.go b/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/model_privateendpointconnectionwithsystemdata.go new file mode 100644 index 00000000000..3d794ce90fc --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/model_privateendpointconnectionwithsystemdata.go @@ -0,0 +1,16 @@ +package privatelink + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionWithSystemData struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PrivateEndpointConnectionProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/model_privatelinkresource.go b/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/model_privatelinkresource.go new file mode 100644 index 00000000000..fea04be7686 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/model_privatelinkresource.go @@ -0,0 +1,11 @@ +package privatelink + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkResource struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PrivateLinkResourceProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/model_privatelinkresourceproperties.go b/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/model_privatelinkresourceproperties.go new file mode 100644 index 00000000000..36abe10fd9a --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/model_privatelinkresourceproperties.go @@ -0,0 +1,10 @@ +package privatelink + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkResourceProperties struct { + GroupId *string `json:"groupId,omitempty"` + RequiredMembers *[]string `json:"requiredMembers,omitempty"` + RequiredZoneNames *[]string `json:"requiredZoneNames,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/model_privatelinkserviceconnectionstate.go b/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/model_privatelinkserviceconnectionstate.go new file mode 100644 index 00000000000..774b4fe4675 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/model_privatelinkserviceconnectionstate.go @@ -0,0 +1,10 @@ +package privatelink + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkServiceConnectionState struct { + ActionsRequired *string `json:"actionsRequired,omitempty"` + Description *string `json:"description,omitempty"` + Status *PrivateEndpointServiceConnectionStatus `json:"status,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/predicates.go b/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/predicates.go new file mode 100644 index 00000000000..571dd914686 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/predicates.go @@ -0,0 +1,47 @@ +package privatelink + +type PrivateEndpointConnectionWithSystemDataOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p PrivateEndpointConnectionWithSystemDataOperationPredicate) Matches(input PrivateEndpointConnectionWithSystemData) bool { + + if p.Id != nil && (input.Id == nil && *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil && *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil && *p.Type != *input.Type) { + return false + } + + return true +} + +type PrivateLinkResourceOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p PrivateLinkResourceOperationPredicate) Matches(input PrivateLinkResource) bool { + + if p.Id != nil && (input.Id == nil && *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil && *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil && *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/version.go b/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/version.go new file mode 100644 index 00000000000..58fd62fd5b3 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/privatelink/version.go @@ -0,0 +1,12 @@ +package privatelink + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2021-09-03-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/privatelink/%s", defaultApiVersion) +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/client.go b/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/client.go new file mode 100644 index 00000000000..eaee7bdef15 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/client.go @@ -0,0 +1,18 @@ +package scalingplan + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ScalingPlanClient struct { + Client autorest.Client + baseUri string +} + +func NewScalingPlanClientWithBaseURI(endpoint string) ScalingPlanClient { + return ScalingPlanClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/constants.go b/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/constants.go new file mode 100644 index 00000000000..9a7fcbb8a5e --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/constants.go @@ -0,0 +1,164 @@ +package scalingplan + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DaysOfWeek string + +const ( + DaysOfWeekFriday DaysOfWeek = "Friday" + DaysOfWeekMonday DaysOfWeek = "Monday" + DaysOfWeekSaturday DaysOfWeek = "Saturday" + DaysOfWeekSunday DaysOfWeek = "Sunday" + DaysOfWeekThursday DaysOfWeek = "Thursday" + DaysOfWeekTuesday DaysOfWeek = "Tuesday" + DaysOfWeekWednesday DaysOfWeek = "Wednesday" +) + +func PossibleValuesForDaysOfWeek() []string { + return []string{ + string(DaysOfWeekFriday), + string(DaysOfWeekMonday), + string(DaysOfWeekSaturday), + string(DaysOfWeekSunday), + string(DaysOfWeekThursday), + string(DaysOfWeekTuesday), + string(DaysOfWeekWednesday), + } +} + +func parseDaysOfWeek(input string) (*DaysOfWeek, error) { + vals := map[string]DaysOfWeek{ + "friday": DaysOfWeekFriday, + "monday": DaysOfWeekMonday, + "saturday": DaysOfWeekSaturday, + "sunday": DaysOfWeekSunday, + "thursday": DaysOfWeekThursday, + "tuesday": DaysOfWeekTuesday, + "wednesday": DaysOfWeekWednesday, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DaysOfWeek(input) + return &out, nil +} + +type ScalingHostPoolType string + +const ( + ScalingHostPoolTypePooled ScalingHostPoolType = "Pooled" +) + +func PossibleValuesForScalingHostPoolType() []string { + return []string{ + string(ScalingHostPoolTypePooled), + } +} + +func parseScalingHostPoolType(input string) (*ScalingHostPoolType, error) { + vals := map[string]ScalingHostPoolType{ + "pooled": ScalingHostPoolTypePooled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ScalingHostPoolType(input) + return &out, nil +} + +type SessionHostLoadBalancingAlgorithm string + +const ( + SessionHostLoadBalancingAlgorithmBreadthFirst SessionHostLoadBalancingAlgorithm = "BreadthFirst" + SessionHostLoadBalancingAlgorithmDepthFirst SessionHostLoadBalancingAlgorithm = "DepthFirst" +) + +func PossibleValuesForSessionHostLoadBalancingAlgorithm() []string { + return []string{ + string(SessionHostLoadBalancingAlgorithmBreadthFirst), + string(SessionHostLoadBalancingAlgorithmDepthFirst), + } +} + +func parseSessionHostLoadBalancingAlgorithm(input string) (*SessionHostLoadBalancingAlgorithm, error) { + vals := map[string]SessionHostLoadBalancingAlgorithm{ + "breadthfirst": SessionHostLoadBalancingAlgorithmBreadthFirst, + "depthfirst": SessionHostLoadBalancingAlgorithmDepthFirst, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SessionHostLoadBalancingAlgorithm(input) + return &out, nil +} + +type SkuTier string + +const ( + SkuTierBasic SkuTier = "Basic" + SkuTierFree SkuTier = "Free" + SkuTierPremium SkuTier = "Premium" + SkuTierStandard SkuTier = "Standard" +) + +func PossibleValuesForSkuTier() []string { + return []string{ + string(SkuTierBasic), + string(SkuTierFree), + string(SkuTierPremium), + string(SkuTierStandard), + } +} + +func parseSkuTier(input string) (*SkuTier, error) { + vals := map[string]SkuTier{ + "basic": SkuTierBasic, + "free": SkuTierFree, + "premium": SkuTierPremium, + "standard": SkuTierStandard, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SkuTier(input) + return &out, nil +} + +type StopHostsWhen string + +const ( + StopHostsWhenZeroActiveSessions StopHostsWhen = "ZeroActiveSessions" + StopHostsWhenZeroSessions StopHostsWhen = "ZeroSessions" +) + +func PossibleValuesForStopHostsWhen() []string { + return []string{ + string(StopHostsWhenZeroActiveSessions), + string(StopHostsWhenZeroSessions), + } +} + +func parseStopHostsWhen(input string) (*StopHostsWhen, error) { + vals := map[string]StopHostsWhen{ + "zeroactivesessions": StopHostsWhenZeroActiveSessions, + "zerosessions": StopHostsWhenZeroSessions, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := StopHostsWhen(input) + return &out, nil +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/id_hostpool.go b/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/id_hostpool.go new file mode 100644 index 00000000000..403b28434e0 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/id_hostpool.go @@ -0,0 +1,124 @@ +package scalingplan + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = HostPoolId{} + +// HostPoolId is a struct representing the Resource ID for a Host Pool +type HostPoolId struct { + SubscriptionId string + ResourceGroupName string + HostPoolName string +} + +// NewHostPoolID returns a new HostPoolId struct +func NewHostPoolID(subscriptionId string, resourceGroupName string, hostPoolName string) HostPoolId { + return HostPoolId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + HostPoolName: hostPoolName, + } +} + +// ParseHostPoolID parses 'input' into a HostPoolId +func ParseHostPoolID(input string) (*HostPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(HostPoolId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := HostPoolId{} + + 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.HostPoolName, ok = parsed.Parsed["hostPoolName"]; !ok { + return nil, fmt.Errorf("the segment 'hostPoolName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseHostPoolIDInsensitively parses 'input' case-insensitively into a HostPoolId +// note: this method should only be used for API response data and not user input +func ParseHostPoolIDInsensitively(input string) (*HostPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(HostPoolId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := HostPoolId{} + + 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.HostPoolName, ok = parsed.Parsed["hostPoolName"]; !ok { + return nil, fmt.Errorf("the segment 'hostPoolName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateHostPoolID checks that 'input' can be parsed as a Host Pool ID +func ValidateHostPoolID(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 := ParseHostPoolID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Host Pool ID +func (id HostPoolId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DesktopVirtualization/hostPools/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.HostPoolName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Host Pool ID +func (id HostPoolId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftDesktopVirtualization", "Microsoft.DesktopVirtualization", "Microsoft.DesktopVirtualization"), + resourceids.StaticSegment("staticHostPools", "hostPools", "hostPools"), + resourceids.UserSpecifiedSegment("hostPoolName", "hostPoolValue"), + } +} + +// String returns a human-readable description of this Host Pool ID +func (id HostPoolId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Host Pool Name: %q", id.HostPoolName), + } + return fmt.Sprintf("Host Pool (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/id_hostpool_test.go b/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/id_hostpool_test.go new file mode 100644 index 00000000000..dbb4a3bfecd --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/id_hostpool_test.go @@ -0,0 +1,279 @@ +package scalingplan + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = HostPoolId{} + +func TestNewHostPoolID(t *testing.T) { + id := NewHostPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "hostPoolValue") + + 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.HostPoolName != "hostPoolValue" { + t.Fatalf("Expected %q but got %q for Segment 'HostPoolName'", id.HostPoolName, "hostPoolValue") + } +} + +func TestFormatHostPoolID(t *testing.T) { + actual := NewHostPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "hostPoolValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseHostPoolID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *HostPoolId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue", + Expected: &HostPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + HostPoolName: "hostPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseHostPoolID(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.HostPoolName != v.Expected.HostPoolName { + t.Fatalf("Expected %q but got %q for HostPoolName", v.Expected.HostPoolName, actual.HostPoolName) + } + + } +} + +func TestParseHostPoolIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *HostPoolId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue", + Expected: &HostPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + HostPoolName: "hostPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe", + Expected: &HostPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + HostPoolName: "hOsTpOoLvAlUe", + }, + }, + { + // 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.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseHostPoolIDInsensitively(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.HostPoolName != v.Expected.HostPoolName { + t.Fatalf("Expected %q but got %q for HostPoolName", v.Expected.HostPoolName, actual.HostPoolName) + } + + } +} + +func TestSegmentsForHostPoolId(t *testing.T) { + segments := HostPoolId{}.Segments() + if len(segments) == 0 { + t.Fatalf("HostPoolId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/id_scalingplan.go b/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/id_scalingplan.go new file mode 100644 index 00000000000..7ab8c80a40c --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/id_scalingplan.go @@ -0,0 +1,124 @@ +package scalingplan + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = ScalingPlanId{} + +// ScalingPlanId is a struct representing the Resource ID for a Scaling Plan +type ScalingPlanId struct { + SubscriptionId string + ResourceGroupName string + ScalingPlanName string +} + +// NewScalingPlanID returns a new ScalingPlanId struct +func NewScalingPlanID(subscriptionId string, resourceGroupName string, scalingPlanName string) ScalingPlanId { + return ScalingPlanId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ScalingPlanName: scalingPlanName, + } +} + +// ParseScalingPlanID parses 'input' into a ScalingPlanId +func ParseScalingPlanID(input string) (*ScalingPlanId, error) { + parser := resourceids.NewParserFromResourceIdType(ScalingPlanId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ScalingPlanId{} + + 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.ScalingPlanName, ok = parsed.Parsed["scalingPlanName"]; !ok { + return nil, fmt.Errorf("the segment 'scalingPlanName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseScalingPlanIDInsensitively parses 'input' case-insensitively into a ScalingPlanId +// note: this method should only be used for API response data and not user input +func ParseScalingPlanIDInsensitively(input string) (*ScalingPlanId, error) { + parser := resourceids.NewParserFromResourceIdType(ScalingPlanId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ScalingPlanId{} + + 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.ScalingPlanName, ok = parsed.Parsed["scalingPlanName"]; !ok { + return nil, fmt.Errorf("the segment 'scalingPlanName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateScalingPlanID checks that 'input' can be parsed as a Scaling Plan ID +func ValidateScalingPlanID(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 := ParseScalingPlanID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Scaling Plan ID +func (id ScalingPlanId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DesktopVirtualization/scalingPlans/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ScalingPlanName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Scaling Plan ID +func (id ScalingPlanId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftDesktopVirtualization", "Microsoft.DesktopVirtualization", "Microsoft.DesktopVirtualization"), + resourceids.StaticSegment("staticScalingPlans", "scalingPlans", "scalingPlans"), + resourceids.UserSpecifiedSegment("scalingPlanName", "scalingPlanValue"), + } +} + +// String returns a human-readable description of this Scaling Plan ID +func (id ScalingPlanId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Scaling Plan Name: %q", id.ScalingPlanName), + } + return fmt.Sprintf("Scaling Plan (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/id_scalingplan_test.go b/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/id_scalingplan_test.go new file mode 100644 index 00000000000..c0b5504527d --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/id_scalingplan_test.go @@ -0,0 +1,279 @@ +package scalingplan + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = ScalingPlanId{} + +func TestNewScalingPlanID(t *testing.T) { + id := NewScalingPlanID("12345678-1234-9876-4563-123456789012", "example-resource-group", "scalingPlanValue") + + 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.ScalingPlanName != "scalingPlanValue" { + t.Fatalf("Expected %q but got %q for Segment 'ScalingPlanName'", id.ScalingPlanName, "scalingPlanValue") + } +} + +func TestFormatScalingPlanID(t *testing.T) { + actual := NewScalingPlanID("12345678-1234-9876-4563-123456789012", "example-resource-group", "scalingPlanValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/scalingPlans/scalingPlanValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseScalingPlanID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ScalingPlanId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/scalingPlans", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/scalingPlans/scalingPlanValue", + Expected: &ScalingPlanId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ScalingPlanName: "scalingPlanValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/scalingPlans/scalingPlanValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseScalingPlanID(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.ScalingPlanName != v.Expected.ScalingPlanName { + t.Fatalf("Expected %q but got %q for ScalingPlanName", v.Expected.ScalingPlanName, actual.ScalingPlanName) + } + + } +} + +func TestParseScalingPlanIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ScalingPlanId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/scalingPlans", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/sCaLiNgPlAnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/scalingPlans/scalingPlanValue", + Expected: &ScalingPlanId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ScalingPlanName: "scalingPlanValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/scalingPlans/scalingPlanValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/sCaLiNgPlAnS/sCaLiNgPlAnVaLuE", + Expected: &ScalingPlanId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ScalingPlanName: "sCaLiNgPlAnVaLuE", + }, + }, + { + // 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.dEsKtOpViRtUaLiZaTiOn/sCaLiNgPlAnS/sCaLiNgPlAnVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseScalingPlanIDInsensitively(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.ScalingPlanName != v.Expected.ScalingPlanName { + t.Fatalf("Expected %q but got %q for ScalingPlanName", v.Expected.ScalingPlanName, actual.ScalingPlanName) + } + + } +} + +func TestSegmentsForScalingPlanId(t *testing.T) { + segments := ScalingPlanId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ScalingPlanId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/method_create_autorest.go b/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/method_create_autorest.go new file mode 100644 index 00000000000..8841c6898fd --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/method_create_autorest.go @@ -0,0 +1,68 @@ +package scalingplan + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOperationResponse struct { + HttpResponse *http.Response + Model *ScalingPlan +} + +// Create ... +func (c ScalingPlanClient) Create(ctx context.Context, id ScalingPlanId, input ScalingPlan) (result CreateOperationResponse, err error) { + req, err := c.preparerForCreate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "scalingplan.ScalingPlanClient", "Create", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "scalingplan.ScalingPlanClient", "Create", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForCreate(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "scalingplan.ScalingPlanClient", "Create", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForCreate prepares the Create request. +func (c ScalingPlanClient) preparerForCreate(ctx context.Context, id ScalingPlanId, input ScalingPlan) (*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 ScalingPlanClient) responderForCreate(resp *http.Response) (result CreateOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/method_delete_autorest.go b/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/method_delete_autorest.go new file mode 100644 index 00000000000..75755b5784c --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/method_delete_autorest.go @@ -0,0 +1,65 @@ +package scalingplan + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response +} + +// Delete ... +func (c ScalingPlanClient) Delete(ctx context.Context, id ScalingPlanId) (result DeleteOperationResponse, err error) { + req, err := c.preparerForDelete(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "scalingplan.ScalingPlanClient", "Delete", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "scalingplan.ScalingPlanClient", "Delete", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForDelete(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "scalingplan.ScalingPlanClient", "Delete", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForDelete prepares the Delete request. +func (c ScalingPlanClient) preparerForDelete(ctx context.Context, id ScalingPlanId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + 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 ScalingPlanClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/method_get_autorest.go b/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/method_get_autorest.go new file mode 100644 index 00000000000..5550e0d3eb9 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/method_get_autorest.go @@ -0,0 +1,67 @@ +package scalingplan + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *ScalingPlan +} + +// Get ... +func (c ScalingPlanClient) Get(ctx context.Context, id ScalingPlanId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "scalingplan.ScalingPlanClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "scalingplan.ScalingPlanClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "scalingplan.ScalingPlanClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c ScalingPlanClient) preparerForGet(ctx context.Context, id ScalingPlanId) (*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 ScalingPlanClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/method_listbyhostpool_autorest.go b/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/method_listbyhostpool_autorest.go new file mode 100644 index 00000000000..b60add783d3 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/method_listbyhostpool_autorest.go @@ -0,0 +1,186 @@ +package scalingplan + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByHostPoolOperationResponse struct { + HttpResponse *http.Response + Model *[]ScalingPlan + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListByHostPoolOperationResponse, error) +} + +type ListByHostPoolCompleteResult struct { + Items []ScalingPlan +} + +func (r ListByHostPoolOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListByHostPoolOperationResponse) LoadMore(ctx context.Context) (resp ListByHostPoolOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// ListByHostPool ... +func (c ScalingPlanClient) ListByHostPool(ctx context.Context, id HostPoolId) (resp ListByHostPoolOperationResponse, err error) { + req, err := c.preparerForListByHostPool(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "scalingplan.ScalingPlanClient", "ListByHostPool", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "scalingplan.ScalingPlanClient", "ListByHostPool", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForListByHostPool(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "scalingplan.ScalingPlanClient", "ListByHostPool", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// ListByHostPoolComplete retrieves all of the results into a single object +func (c ScalingPlanClient) ListByHostPoolComplete(ctx context.Context, id HostPoolId) (ListByHostPoolCompleteResult, error) { + return c.ListByHostPoolCompleteMatchingPredicate(ctx, id, ScalingPlanOperationPredicate{}) +} + +// ListByHostPoolCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c ScalingPlanClient) ListByHostPoolCompleteMatchingPredicate(ctx context.Context, id HostPoolId, predicate ScalingPlanOperationPredicate) (resp ListByHostPoolCompleteResult, err error) { + items := make([]ScalingPlan, 0) + + page, err := c.ListByHostPool(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListByHostPoolCompleteResult{ + Items: items, + } + return out, nil +} + +// preparerForListByHostPool prepares the ListByHostPool request. +func (c ScalingPlanClient) preparerForListByHostPool(ctx context.Context, id HostPoolId) (*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/scalingPlans", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListByHostPoolWithNextLink prepares the ListByHostPool request with the given nextLink token. +func (c ScalingPlanClient) preparerForListByHostPoolWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForListByHostPool handles the response to the ListByHostPool request. The method always +// closes the http.Response Body. +func (c ScalingPlanClient) responderForListByHostPool(resp *http.Response) (result ListByHostPoolOperationResponse, err error) { + type page struct { + Values []ScalingPlan `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListByHostPoolOperationResponse, err error) { + req, err := c.preparerForListByHostPoolWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "scalingplan.ScalingPlanClient", "ListByHostPool", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "scalingplan.ScalingPlanClient", "ListByHostPool", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForListByHostPool(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "scalingplan.ScalingPlanClient", "ListByHostPool", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/method_listbyresourcegroup_autorest.go b/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/method_listbyresourcegroup_autorest.go new file mode 100644 index 00000000000..81cad260899 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/method_listbyresourcegroup_autorest.go @@ -0,0 +1,187 @@ +package scalingplan + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByResourceGroupOperationResponse struct { + HttpResponse *http.Response + Model *[]ScalingPlan + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListByResourceGroupOperationResponse, error) +} + +type ListByResourceGroupCompleteResult struct { + Items []ScalingPlan +} + +func (r ListByResourceGroupOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListByResourceGroupOperationResponse) LoadMore(ctx context.Context) (resp ListByResourceGroupOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// ListByResourceGroup ... +func (c ScalingPlanClient) ListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (resp ListByResourceGroupOperationResponse, err error) { + req, err := c.preparerForListByResourceGroup(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "scalingplan.ScalingPlanClient", "ListByResourceGroup", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "scalingplan.ScalingPlanClient", "ListByResourceGroup", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForListByResourceGroup(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "scalingplan.ScalingPlanClient", "ListByResourceGroup", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// ListByResourceGroupComplete retrieves all of the results into a single object +func (c ScalingPlanClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (ListByResourceGroupCompleteResult, error) { + return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, ScalingPlanOperationPredicate{}) +} + +// ListByResourceGroupCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c ScalingPlanClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate ScalingPlanOperationPredicate) (resp ListByResourceGroupCompleteResult, err error) { + items := make([]ScalingPlan, 0) + + page, err := c.ListByResourceGroup(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListByResourceGroupCompleteResult{ + Items: items, + } + return out, nil +} + +// preparerForListByResourceGroup prepares the ListByResourceGroup request. +func (c ScalingPlanClient) preparerForListByResourceGroup(ctx context.Context, id commonids.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.DesktopVirtualization/scalingPlans", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListByResourceGroupWithNextLink prepares the ListByResourceGroup request with the given nextLink token. +func (c ScalingPlanClient) preparerForListByResourceGroupWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForListByResourceGroup handles the response to the ListByResourceGroup request. The method always +// closes the http.Response Body. +func (c ScalingPlanClient) responderForListByResourceGroup(resp *http.Response) (result ListByResourceGroupOperationResponse, err error) { + type page struct { + Values []ScalingPlan `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListByResourceGroupOperationResponse, err error) { + req, err := c.preparerForListByResourceGroupWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "scalingplan.ScalingPlanClient", "ListByResourceGroup", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "scalingplan.ScalingPlanClient", "ListByResourceGroup", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForListByResourceGroup(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "scalingplan.ScalingPlanClient", "ListByResourceGroup", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/method_listbysubscription_autorest.go b/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/method_listbysubscription_autorest.go new file mode 100644 index 00000000000..aa6c7049d5a --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/method_listbysubscription_autorest.go @@ -0,0 +1,187 @@ +package scalingplan + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListBySubscriptionOperationResponse struct { + HttpResponse *http.Response + Model *[]ScalingPlan + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListBySubscriptionOperationResponse, error) +} + +type ListBySubscriptionCompleteResult struct { + Items []ScalingPlan +} + +func (r ListBySubscriptionOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListBySubscriptionOperationResponse) LoadMore(ctx context.Context) (resp ListBySubscriptionOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// ListBySubscription ... +func (c ScalingPlanClient) ListBySubscription(ctx context.Context, id commonids.SubscriptionId) (resp ListBySubscriptionOperationResponse, err error) { + req, err := c.preparerForListBySubscription(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "scalingplan.ScalingPlanClient", "ListBySubscription", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "scalingplan.ScalingPlanClient", "ListBySubscription", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForListBySubscription(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "scalingplan.ScalingPlanClient", "ListBySubscription", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// ListBySubscriptionComplete retrieves all of the results into a single object +func (c ScalingPlanClient) ListBySubscriptionComplete(ctx context.Context, id commonids.SubscriptionId) (ListBySubscriptionCompleteResult, error) { + return c.ListBySubscriptionCompleteMatchingPredicate(ctx, id, ScalingPlanOperationPredicate{}) +} + +// ListBySubscriptionCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c ScalingPlanClient) ListBySubscriptionCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate ScalingPlanOperationPredicate) (resp ListBySubscriptionCompleteResult, err error) { + items := make([]ScalingPlan, 0) + + page, err := c.ListBySubscription(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListBySubscriptionCompleteResult{ + Items: items, + } + return out, nil +} + +// preparerForListBySubscription prepares the ListBySubscription request. +func (c ScalingPlanClient) preparerForListBySubscription(ctx context.Context, id commonids.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.DesktopVirtualization/scalingPlans", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListBySubscriptionWithNextLink prepares the ListBySubscription request with the given nextLink token. +func (c ScalingPlanClient) preparerForListBySubscriptionWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForListBySubscription handles the response to the ListBySubscription request. The method always +// closes the http.Response Body. +func (c ScalingPlanClient) responderForListBySubscription(resp *http.Response) (result ListBySubscriptionOperationResponse, err error) { + type page struct { + Values []ScalingPlan `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListBySubscriptionOperationResponse, err error) { + req, err := c.preparerForListBySubscriptionWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "scalingplan.ScalingPlanClient", "ListBySubscription", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "scalingplan.ScalingPlanClient", "ListBySubscription", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForListBySubscription(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "scalingplan.ScalingPlanClient", "ListBySubscription", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/method_update_autorest.go b/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/method_update_autorest.go new file mode 100644 index 00000000000..1a91bb11694 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/method_update_autorest.go @@ -0,0 +1,68 @@ +package scalingplan + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + HttpResponse *http.Response + Model *ScalingPlan +} + +// Update ... +func (c ScalingPlanClient) Update(ctx context.Context, id ScalingPlanId, input ScalingPlanPatch) (result UpdateOperationResponse, err error) { + req, err := c.preparerForUpdate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "scalingplan.ScalingPlanClient", "Update", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "scalingplan.ScalingPlanClient", "Update", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForUpdate(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "scalingplan.ScalingPlanClient", "Update", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForUpdate prepares the Update request. +func (c ScalingPlanClient) preparerForUpdate(ctx context.Context, id ScalingPlanId, input ScalingPlanPatch) (*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 ScalingPlanClient) responderForUpdate(resp *http.Response) (result UpdateOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/model_plan.go b/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/model_plan.go new file mode 100644 index 00000000000..07296ec4765 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/model_plan.go @@ -0,0 +1,12 @@ +package scalingplan + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Plan struct { + Name string `json:"name"` + Product string `json:"product"` + PromotionCode *string `json:"promotionCode,omitempty"` + Publisher string `json:"publisher"` + Version *string `json:"version,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/model_scalinghostpoolreference.go b/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/model_scalinghostpoolreference.go new file mode 100644 index 00000000000..0bd8fd048bb --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/model_scalinghostpoolreference.go @@ -0,0 +1,9 @@ +package scalingplan + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ScalingHostPoolReference struct { + HostPoolArmPath *string `json:"hostPoolArmPath,omitempty"` + ScalingPlanEnabled *bool `json:"scalingPlanEnabled,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/model_scalingplan.go b/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/model_scalingplan.go new file mode 100644 index 00000000000..8b59d34339e --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/model_scalingplan.go @@ -0,0 +1,25 @@ +package scalingplan + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/identity" + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ScalingPlan struct { + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Identity *identity.SystemAssigned `json:"identity,omitempty"` + Kind *string `json:"kind,omitempty"` + Location *string `json:"location,omitempty"` + ManagedBy *string `json:"managedBy,omitempty"` + Name *string `json:"name,omitempty"` + Plan *Plan `json:"plan,omitempty"` + Properties *ScalingPlanProperties `json:"properties,omitempty"` + Sku *Sku `json:"sku,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/model_scalingplanpatch.go b/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/model_scalingplanpatch.go new file mode 100644 index 00000000000..642647709fe --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/model_scalingplanpatch.go @@ -0,0 +1,9 @@ +package scalingplan + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ScalingPlanPatch struct { + Properties *ScalingPlanPatchProperties `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/model_scalingplanpatchproperties.go b/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/model_scalingplanpatchproperties.go new file mode 100644 index 00000000000..393a26bb413 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/model_scalingplanpatchproperties.go @@ -0,0 +1,13 @@ +package scalingplan + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ScalingPlanPatchProperties struct { + Description *string `json:"description,omitempty"` + ExclusionTag *string `json:"exclusionTag,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + HostPoolReferences *[]ScalingHostPoolReference `json:"hostPoolReferences,omitempty"` + Schedules *[]ScalingSchedule `json:"schedules,omitempty"` + TimeZone *string `json:"timeZone,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/model_scalingplanproperties.go b/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/model_scalingplanproperties.go new file mode 100644 index 00000000000..520ed16aa9a --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/model_scalingplanproperties.go @@ -0,0 +1,15 @@ +package scalingplan + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ScalingPlanProperties struct { + Description *string `json:"description,omitempty"` + ExclusionTag *string `json:"exclusionTag,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + HostPoolReferences *[]ScalingHostPoolReference `json:"hostPoolReferences,omitempty"` + HostPoolType *ScalingHostPoolType `json:"hostPoolType,omitempty"` + ObjectId *string `json:"objectId,omitempty"` + Schedules *[]ScalingSchedule `json:"schedules,omitempty"` + TimeZone *string `json:"timeZone,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/model_scalingschedule.go b/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/model_scalingschedule.go new file mode 100644 index 00000000000..313ed8bdf13 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/model_scalingschedule.go @@ -0,0 +1,25 @@ +package scalingplan + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ScalingSchedule struct { + DaysOfWeek *[]DaysOfWeek `json:"daysOfWeek,omitempty"` + Name *string `json:"name,omitempty"` + OffPeakLoadBalancingAlgorithm *SessionHostLoadBalancingAlgorithm `json:"offPeakLoadBalancingAlgorithm,omitempty"` + OffPeakStartTime *Time `json:"offPeakStartTime,omitempty"` + PeakLoadBalancingAlgorithm *SessionHostLoadBalancingAlgorithm `json:"peakLoadBalancingAlgorithm,omitempty"` + PeakStartTime *Time `json:"peakStartTime,omitempty"` + RampDownCapacityThresholdPct *int64 `json:"rampDownCapacityThresholdPct,omitempty"` + RampDownForceLogoffUsers *bool `json:"rampDownForceLogoffUsers,omitempty"` + RampDownLoadBalancingAlgorithm *SessionHostLoadBalancingAlgorithm `json:"rampDownLoadBalancingAlgorithm,omitempty"` + RampDownMinimumHostsPct *int64 `json:"rampDownMinimumHostsPct,omitempty"` + RampDownNotificationMessage *string `json:"rampDownNotificationMessage,omitempty"` + RampDownStartTime *Time `json:"rampDownStartTime,omitempty"` + RampDownStopHostsWhen *StopHostsWhen `json:"rampDownStopHostsWhen,omitempty"` + RampDownWaitTimeMinutes *int64 `json:"rampDownWaitTimeMinutes,omitempty"` + RampUpCapacityThresholdPct *int64 `json:"rampUpCapacityThresholdPct,omitempty"` + RampUpLoadBalancingAlgorithm *SessionHostLoadBalancingAlgorithm `json:"rampUpLoadBalancingAlgorithm,omitempty"` + RampUpMinimumHostsPct *int64 `json:"rampUpMinimumHostsPct,omitempty"` + RampUpStartTime *Time `json:"rampUpStartTime,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/model_sku.go b/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/model_sku.go new file mode 100644 index 00000000000..364fdaef1a0 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/model_sku.go @@ -0,0 +1,12 @@ +package scalingplan + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Sku struct { + Capacity *int64 `json:"capacity,omitempty"` + Family *string `json:"family,omitempty"` + Name string `json:"name"` + Size *string `json:"size,omitempty"` + Tier *SkuTier `json:"tier,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/model_time.go b/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/model_time.go new file mode 100644 index 00000000000..f9e8b6f4484 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/model_time.go @@ -0,0 +1,9 @@ +package scalingplan + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Time struct { + Hour int64 `json:"hour"` + Minute int64 `json:"minute"` +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/predicates.go b/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/predicates.go new file mode 100644 index 00000000000..7633debe906 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/predicates.go @@ -0,0 +1,44 @@ +package scalingplan + +type ScalingPlanOperationPredicate struct { + Etag *string + Id *string + Kind *string + Location *string + ManagedBy *string + Name *string + Type *string +} + +func (p ScalingPlanOperationPredicate) Matches(input ScalingPlan) bool { + + if p.Etag != nil && (input.Etag == nil && *p.Etag != *input.Etag) { + return false + } + + if p.Id != nil && (input.Id == nil && *p.Id != *input.Id) { + return false + } + + if p.Kind != nil && (input.Kind == nil && *p.Kind != *input.Kind) { + return false + } + + if p.Location != nil && (input.Location == nil && *p.Location != *input.Location) { + return false + } + + if p.ManagedBy != nil && (input.ManagedBy == nil && *p.ManagedBy != *input.ManagedBy) { + return false + } + + if p.Name != nil && (input.Name == nil && *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil && *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/version.go b/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/version.go new file mode 100644 index 00000000000..577b2cdd7db --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/scalingplan/version.go @@ -0,0 +1,12 @@ +package scalingplan + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2021-09-03-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/scalingplan/%s", defaultApiVersion) +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/sessionhost/client.go b/resource-manager/desktopvirtualization/2021-09-03-preview/sessionhost/client.go new file mode 100644 index 00000000000..69a79d045fe --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/sessionhost/client.go @@ -0,0 +1,18 @@ +package sessionhost + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SessionHostClient struct { + Client autorest.Client + baseUri string +} + +func NewSessionHostClientWithBaseURI(endpoint string) SessionHostClient { + return SessionHostClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/sessionhost/constants.go b/resource-manager/desktopvirtualization/2021-09-03-preview/sessionhost/constants.go new file mode 100644 index 00000000000..ef4b007d663 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/sessionhost/constants.go @@ -0,0 +1,190 @@ +package sessionhost + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type HealthCheckName string + +const ( + HealthCheckNameAppAttachHealthCheck HealthCheckName = "AppAttachHealthCheck" + HealthCheckNameDomainJoinedCheck HealthCheckName = "DomainJoinedCheck" + HealthCheckNameDomainReachable HealthCheckName = "DomainReachable" + HealthCheckNameDomainTrustCheck HealthCheckName = "DomainTrustCheck" + HealthCheckNameFSLogixHealthCheck HealthCheckName = "FSLogixHealthCheck" + HealthCheckNameMetaDataServiceCheck HealthCheckName = "MetaDataServiceCheck" + HealthCheckNameMonitoringAgentCheck HealthCheckName = "MonitoringAgentCheck" + HealthCheckNameSupportedEncryptionCheck HealthCheckName = "SupportedEncryptionCheck" + HealthCheckNameSxSStackListenerCheck HealthCheckName = "SxSStackListenerCheck" + HealthCheckNameUrlsAccessibleCheck HealthCheckName = "UrlsAccessibleCheck" + HealthCheckNameWebRTCRedirectorCheck HealthCheckName = "WebRTCRedirectorCheck" +) + +func PossibleValuesForHealthCheckName() []string { + return []string{ + string(HealthCheckNameAppAttachHealthCheck), + string(HealthCheckNameDomainJoinedCheck), + string(HealthCheckNameDomainReachable), + string(HealthCheckNameDomainTrustCheck), + string(HealthCheckNameFSLogixHealthCheck), + string(HealthCheckNameMetaDataServiceCheck), + string(HealthCheckNameMonitoringAgentCheck), + string(HealthCheckNameSupportedEncryptionCheck), + string(HealthCheckNameSxSStackListenerCheck), + string(HealthCheckNameUrlsAccessibleCheck), + string(HealthCheckNameWebRTCRedirectorCheck), + } +} + +func parseHealthCheckName(input string) (*HealthCheckName, error) { + vals := map[string]HealthCheckName{ + "appattachhealthcheck": HealthCheckNameAppAttachHealthCheck, + "domainjoinedcheck": HealthCheckNameDomainJoinedCheck, + "domainreachable": HealthCheckNameDomainReachable, + "domaintrustcheck": HealthCheckNameDomainTrustCheck, + "fslogixhealthcheck": HealthCheckNameFSLogixHealthCheck, + "metadataservicecheck": HealthCheckNameMetaDataServiceCheck, + "monitoringagentcheck": HealthCheckNameMonitoringAgentCheck, + "supportedencryptioncheck": HealthCheckNameSupportedEncryptionCheck, + "sxsstacklistenercheck": HealthCheckNameSxSStackListenerCheck, + "urlsaccessiblecheck": HealthCheckNameUrlsAccessibleCheck, + "webrtcredirectorcheck": HealthCheckNameWebRTCRedirectorCheck, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := HealthCheckName(input) + return &out, nil +} + +type HealthCheckResult string + +const ( + HealthCheckResultHealthCheckFailed HealthCheckResult = "HealthCheckFailed" + HealthCheckResultHealthCheckSucceeded HealthCheckResult = "HealthCheckSucceeded" + HealthCheckResultSessionHostShutdown HealthCheckResult = "SessionHostShutdown" + HealthCheckResultUnknown HealthCheckResult = "Unknown" +) + +func PossibleValuesForHealthCheckResult() []string { + return []string{ + string(HealthCheckResultHealthCheckFailed), + string(HealthCheckResultHealthCheckSucceeded), + string(HealthCheckResultSessionHostShutdown), + string(HealthCheckResultUnknown), + } +} + +func parseHealthCheckResult(input string) (*HealthCheckResult, error) { + vals := map[string]HealthCheckResult{ + "healthcheckfailed": HealthCheckResultHealthCheckFailed, + "healthchecksucceeded": HealthCheckResultHealthCheckSucceeded, + "sessionhostshutdown": HealthCheckResultSessionHostShutdown, + "unknown": HealthCheckResultUnknown, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := HealthCheckResult(input) + return &out, nil +} + +type Status string + +const ( + StatusAvailable Status = "Available" + StatusDisconnected Status = "Disconnected" + StatusDomainTrustRelationshipLost Status = "DomainTrustRelationshipLost" + StatusFSLogixNotHealthy Status = "FSLogixNotHealthy" + StatusNeedsAssistance Status = "NeedsAssistance" + StatusNoHeartbeat Status = "NoHeartbeat" + StatusNotJoinedToDomain Status = "NotJoinedToDomain" + StatusShutdown Status = "Shutdown" + StatusSxSStackListenerNotReady Status = "SxSStackListenerNotReady" + StatusUnavailable Status = "Unavailable" + StatusUpgradeFailed Status = "UpgradeFailed" + StatusUpgrading Status = "Upgrading" +) + +func PossibleValuesForStatus() []string { + return []string{ + string(StatusAvailable), + string(StatusDisconnected), + string(StatusDomainTrustRelationshipLost), + string(StatusFSLogixNotHealthy), + string(StatusNeedsAssistance), + string(StatusNoHeartbeat), + string(StatusNotJoinedToDomain), + string(StatusShutdown), + string(StatusSxSStackListenerNotReady), + string(StatusUnavailable), + string(StatusUpgradeFailed), + string(StatusUpgrading), + } +} + +func parseStatus(input string) (*Status, error) { + vals := map[string]Status{ + "available": StatusAvailable, + "disconnected": StatusDisconnected, + "domaintrustrelationshiplost": StatusDomainTrustRelationshipLost, + "fslogixnothealthy": StatusFSLogixNotHealthy, + "needsassistance": StatusNeedsAssistance, + "noheartbeat": StatusNoHeartbeat, + "notjoinedtodomain": StatusNotJoinedToDomain, + "shutdown": StatusShutdown, + "sxsstacklistenernotready": StatusSxSStackListenerNotReady, + "unavailable": StatusUnavailable, + "upgradefailed": StatusUpgradeFailed, + "upgrading": StatusUpgrading, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Status(input) + return &out, nil +} + +type UpdateState string + +const ( + UpdateStateFailed UpdateState = "Failed" + UpdateStateInitial UpdateState = "Initial" + UpdateStatePending UpdateState = "Pending" + UpdateStateStarted UpdateState = "Started" + UpdateStateSucceeded UpdateState = "Succeeded" +) + +func PossibleValuesForUpdateState() []string { + return []string{ + string(UpdateStateFailed), + string(UpdateStateInitial), + string(UpdateStatePending), + string(UpdateStateStarted), + string(UpdateStateSucceeded), + } +} + +func parseUpdateState(input string) (*UpdateState, error) { + vals := map[string]UpdateState{ + "failed": UpdateStateFailed, + "initial": UpdateStateInitial, + "pending": UpdateStatePending, + "started": UpdateStateStarted, + "succeeded": UpdateStateSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := UpdateState(input) + return &out, nil +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/sessionhost/id_hostpool.go b/resource-manager/desktopvirtualization/2021-09-03-preview/sessionhost/id_hostpool.go new file mode 100644 index 00000000000..b42dea32fb0 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/sessionhost/id_hostpool.go @@ -0,0 +1,124 @@ +package sessionhost + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = HostPoolId{} + +// HostPoolId is a struct representing the Resource ID for a Host Pool +type HostPoolId struct { + SubscriptionId string + ResourceGroupName string + HostPoolName string +} + +// NewHostPoolID returns a new HostPoolId struct +func NewHostPoolID(subscriptionId string, resourceGroupName string, hostPoolName string) HostPoolId { + return HostPoolId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + HostPoolName: hostPoolName, + } +} + +// ParseHostPoolID parses 'input' into a HostPoolId +func ParseHostPoolID(input string) (*HostPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(HostPoolId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := HostPoolId{} + + 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.HostPoolName, ok = parsed.Parsed["hostPoolName"]; !ok { + return nil, fmt.Errorf("the segment 'hostPoolName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseHostPoolIDInsensitively parses 'input' case-insensitively into a HostPoolId +// note: this method should only be used for API response data and not user input +func ParseHostPoolIDInsensitively(input string) (*HostPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(HostPoolId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := HostPoolId{} + + 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.HostPoolName, ok = parsed.Parsed["hostPoolName"]; !ok { + return nil, fmt.Errorf("the segment 'hostPoolName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateHostPoolID checks that 'input' can be parsed as a Host Pool ID +func ValidateHostPoolID(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 := ParseHostPoolID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Host Pool ID +func (id HostPoolId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DesktopVirtualization/hostPools/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.HostPoolName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Host Pool ID +func (id HostPoolId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftDesktopVirtualization", "Microsoft.DesktopVirtualization", "Microsoft.DesktopVirtualization"), + resourceids.StaticSegment("staticHostPools", "hostPools", "hostPools"), + resourceids.UserSpecifiedSegment("hostPoolName", "hostPoolValue"), + } +} + +// String returns a human-readable description of this Host Pool ID +func (id HostPoolId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Host Pool Name: %q", id.HostPoolName), + } + return fmt.Sprintf("Host Pool (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/sessionhost/id_hostpool_test.go b/resource-manager/desktopvirtualization/2021-09-03-preview/sessionhost/id_hostpool_test.go new file mode 100644 index 00000000000..32838d09b91 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/sessionhost/id_hostpool_test.go @@ -0,0 +1,279 @@ +package sessionhost + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = HostPoolId{} + +func TestNewHostPoolID(t *testing.T) { + id := NewHostPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "hostPoolValue") + + 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.HostPoolName != "hostPoolValue" { + t.Fatalf("Expected %q but got %q for Segment 'HostPoolName'", id.HostPoolName, "hostPoolValue") + } +} + +func TestFormatHostPoolID(t *testing.T) { + actual := NewHostPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "hostPoolValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseHostPoolID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *HostPoolId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue", + Expected: &HostPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + HostPoolName: "hostPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseHostPoolID(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.HostPoolName != v.Expected.HostPoolName { + t.Fatalf("Expected %q but got %q for HostPoolName", v.Expected.HostPoolName, actual.HostPoolName) + } + + } +} + +func TestParseHostPoolIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *HostPoolId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue", + Expected: &HostPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + HostPoolName: "hostPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe", + Expected: &HostPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + HostPoolName: "hOsTpOoLvAlUe", + }, + }, + { + // 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.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseHostPoolIDInsensitively(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.HostPoolName != v.Expected.HostPoolName { + t.Fatalf("Expected %q but got %q for HostPoolName", v.Expected.HostPoolName, actual.HostPoolName) + } + + } +} + +func TestSegmentsForHostPoolId(t *testing.T) { + segments := HostPoolId{}.Segments() + if len(segments) == 0 { + t.Fatalf("HostPoolId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/sessionhost/id_sessionhost.go b/resource-manager/desktopvirtualization/2021-09-03-preview/sessionhost/id_sessionhost.go new file mode 100644 index 00000000000..cd3fe90122c --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/sessionhost/id_sessionhost.go @@ -0,0 +1,137 @@ +package sessionhost + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = SessionHostId{} + +// SessionHostId is a struct representing the Resource ID for a Session Host +type SessionHostId struct { + SubscriptionId string + ResourceGroupName string + HostPoolName string + SessionHostName string +} + +// NewSessionHostID returns a new SessionHostId struct +func NewSessionHostID(subscriptionId string, resourceGroupName string, hostPoolName string, sessionHostName string) SessionHostId { + return SessionHostId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + HostPoolName: hostPoolName, + SessionHostName: sessionHostName, + } +} + +// ParseSessionHostID parses 'input' into a SessionHostId +func ParseSessionHostID(input string) (*SessionHostId, error) { + parser := resourceids.NewParserFromResourceIdType(SessionHostId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := SessionHostId{} + + 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.HostPoolName, ok = parsed.Parsed["hostPoolName"]; !ok { + return nil, fmt.Errorf("the segment 'hostPoolName' was not found in the resource id %q", input) + } + + if id.SessionHostName, ok = parsed.Parsed["sessionHostName"]; !ok { + return nil, fmt.Errorf("the segment 'sessionHostName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseSessionHostIDInsensitively parses 'input' case-insensitively into a SessionHostId +// note: this method should only be used for API response data and not user input +func ParseSessionHostIDInsensitively(input string) (*SessionHostId, error) { + parser := resourceids.NewParserFromResourceIdType(SessionHostId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := SessionHostId{} + + 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.HostPoolName, ok = parsed.Parsed["hostPoolName"]; !ok { + return nil, fmt.Errorf("the segment 'hostPoolName' was not found in the resource id %q", input) + } + + if id.SessionHostName, ok = parsed.Parsed["sessionHostName"]; !ok { + return nil, fmt.Errorf("the segment 'sessionHostName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateSessionHostID checks that 'input' can be parsed as a Session Host ID +func ValidateSessionHostID(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 := ParseSessionHostID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Session Host ID +func (id SessionHostId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DesktopVirtualization/hostPools/%s/sessionHosts/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.HostPoolName, id.SessionHostName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Session Host ID +func (id SessionHostId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftDesktopVirtualization", "Microsoft.DesktopVirtualization", "Microsoft.DesktopVirtualization"), + resourceids.StaticSegment("staticHostPools", "hostPools", "hostPools"), + resourceids.UserSpecifiedSegment("hostPoolName", "hostPoolValue"), + resourceids.StaticSegment("staticSessionHosts", "sessionHosts", "sessionHosts"), + resourceids.UserSpecifiedSegment("sessionHostName", "sessionHostValue"), + } +} + +// String returns a human-readable description of this Session Host ID +func (id SessionHostId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Host Pool Name: %q", id.HostPoolName), + fmt.Sprintf("Session Host Name: %q", id.SessionHostName), + } + return fmt.Sprintf("Session Host (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/sessionhost/id_sessionhost_test.go b/resource-manager/desktopvirtualization/2021-09-03-preview/sessionhost/id_sessionhost_test.go new file mode 100644 index 00000000000..3e279eebe25 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/sessionhost/id_sessionhost_test.go @@ -0,0 +1,324 @@ +package sessionhost + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = SessionHostId{} + +func TestNewSessionHostID(t *testing.T) { + id := NewSessionHostID("12345678-1234-9876-4563-123456789012", "example-resource-group", "hostPoolValue", "sessionHostValue") + + 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.HostPoolName != "hostPoolValue" { + t.Fatalf("Expected %q but got %q for Segment 'HostPoolName'", id.HostPoolName, "hostPoolValue") + } + + if id.SessionHostName != "sessionHostValue" { + t.Fatalf("Expected %q but got %q for Segment 'SessionHostName'", id.SessionHostName, "sessionHostValue") + } +} + +func TestFormatSessionHostID(t *testing.T) { + actual := NewSessionHostID("12345678-1234-9876-4563-123456789012", "example-resource-group", "hostPoolValue", "sessionHostValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/sessionHosts/sessionHostValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseSessionHostID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SessionHostId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/sessionHosts", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/sessionHosts/sessionHostValue", + Expected: &SessionHostId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + HostPoolName: "hostPoolValue", + SessionHostName: "sessionHostValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/sessionHosts/sessionHostValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSessionHostID(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.HostPoolName != v.Expected.HostPoolName { + t.Fatalf("Expected %q but got %q for HostPoolName", v.Expected.HostPoolName, actual.HostPoolName) + } + + if actual.SessionHostName != v.Expected.SessionHostName { + t.Fatalf("Expected %q but got %q for SessionHostName", v.Expected.SessionHostName, actual.SessionHostName) + } + + } +} + +func TestParseSessionHostIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SessionHostId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/sessionHosts", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe/sEsSiOnHoStS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/sessionHosts/sessionHostValue", + Expected: &SessionHostId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + HostPoolName: "hostPoolValue", + SessionHostName: "sessionHostValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/sessionHosts/sessionHostValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe/sEsSiOnHoStS/sEsSiOnHoStVaLuE", + Expected: &SessionHostId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + HostPoolName: "hOsTpOoLvAlUe", + SessionHostName: "sEsSiOnHoStVaLuE", + }, + }, + { + // 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.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe/sEsSiOnHoStS/sEsSiOnHoStVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSessionHostIDInsensitively(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.HostPoolName != v.Expected.HostPoolName { + t.Fatalf("Expected %q but got %q for HostPoolName", v.Expected.HostPoolName, actual.HostPoolName) + } + + if actual.SessionHostName != v.Expected.SessionHostName { + t.Fatalf("Expected %q but got %q for SessionHostName", v.Expected.SessionHostName, actual.SessionHostName) + } + + } +} + +func TestSegmentsForSessionHostId(t *testing.T) { + segments := SessionHostId{}.Segments() + if len(segments) == 0 { + t.Fatalf("SessionHostId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/sessionhost/method_delete_autorest.go b/resource-manager/desktopvirtualization/2021-09-03-preview/sessionhost/method_delete_autorest.go new file mode 100644 index 00000000000..3eb9fdf7cf7 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/sessionhost/method_delete_autorest.go @@ -0,0 +1,94 @@ +package sessionhost + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response +} + +type DeleteOperationOptions struct { + Force *bool +} + +func DefaultDeleteOperationOptions() DeleteOperationOptions { + return DeleteOperationOptions{} +} + +func (o DeleteOperationOptions) toHeaders() map[string]interface{} { + out := make(map[string]interface{}) + + return out +} + +func (o DeleteOperationOptions) toQueryString() map[string]interface{} { + out := make(map[string]interface{}) + + if o.Force != nil { + out["force"] = *o.Force + } + + return out +} + +// Delete ... +func (c SessionHostClient) Delete(ctx context.Context, id SessionHostId, options DeleteOperationOptions) (result DeleteOperationResponse, err error) { + req, err := c.preparerForDelete(ctx, id, options) + if err != nil { + err = autorest.NewErrorWithError(err, "sessionhost.SessionHostClient", "Delete", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "sessionhost.SessionHostClient", "Delete", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForDelete(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "sessionhost.SessionHostClient", "Delete", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForDelete prepares the Delete request. +func (c SessionHostClient) preparerForDelete(ctx context.Context, id SessionHostId, options DeleteOperationOptions) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + for k, v := range options.toQueryString() { + queryParameters[k] = autorest.Encode("query", v) + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsDelete(), + autorest.WithBaseURL(c.baseUri), + autorest.WithHeaders(options.toHeaders()), + 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 SessionHostClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/sessionhost/method_get_autorest.go b/resource-manager/desktopvirtualization/2021-09-03-preview/sessionhost/method_get_autorest.go new file mode 100644 index 00000000000..e28f5b328c6 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/sessionhost/method_get_autorest.go @@ -0,0 +1,67 @@ +package sessionhost + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *SessionHost +} + +// Get ... +func (c SessionHostClient) Get(ctx context.Context, id SessionHostId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "sessionhost.SessionHostClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "sessionhost.SessionHostClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "sessionhost.SessionHostClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c SessionHostClient) preparerForGet(ctx context.Context, id SessionHostId) (*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 SessionHostClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/sessionhost/method_list_autorest.go b/resource-manager/desktopvirtualization/2021-09-03-preview/sessionhost/method_list_autorest.go new file mode 100644 index 00000000000..5d42759afa6 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/sessionhost/method_list_autorest.go @@ -0,0 +1,186 @@ +package sessionhost + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + Model *[]SessionHost + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) +} + +type ListCompleteResult struct { + Items []SessionHost +} + +func (r ListOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// List ... +func (c SessionHostClient) List(ctx context.Context, id HostPoolId) (resp ListOperationResponse, err error) { + req, err := c.preparerForList(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "sessionhost.SessionHostClient", "List", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "sessionhost.SessionHostClient", "List", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForList(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "sessionhost.SessionHostClient", "List", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// ListComplete retrieves all of the results into a single object +func (c SessionHostClient) ListComplete(ctx context.Context, id HostPoolId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, SessionHostOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c SessionHostClient) ListCompleteMatchingPredicate(ctx context.Context, id HostPoolId, predicate SessionHostOperationPredicate) (resp ListCompleteResult, err error) { + items := make([]SessionHost, 0) + + page, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListCompleteResult{ + Items: items, + } + return out, nil +} + +// preparerForList prepares the List request. +func (c SessionHostClient) preparerForList(ctx context.Context, id HostPoolId) (*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/sessionHosts", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListWithNextLink prepares the List request with the given nextLink token. +func (c SessionHostClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForList handles the response to the List request. The method always +// closes the http.Response Body. +func (c SessionHostClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { + type page struct { + Values []SessionHost `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { + req, err := c.preparerForListWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "sessionhost.SessionHostClient", "List", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "sessionhost.SessionHostClient", "List", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "sessionhost.SessionHostClient", "List", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/sessionhost/method_update_autorest.go b/resource-manager/desktopvirtualization/2021-09-03-preview/sessionhost/method_update_autorest.go new file mode 100644 index 00000000000..8036bc4eb72 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/sessionhost/method_update_autorest.go @@ -0,0 +1,97 @@ +package sessionhost + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + HttpResponse *http.Response + Model *SessionHost +} + +type UpdateOperationOptions struct { + Force *bool +} + +func DefaultUpdateOperationOptions() UpdateOperationOptions { + return UpdateOperationOptions{} +} + +func (o UpdateOperationOptions) toHeaders() map[string]interface{} { + out := make(map[string]interface{}) + + return out +} + +func (o UpdateOperationOptions) toQueryString() map[string]interface{} { + out := make(map[string]interface{}) + + if o.Force != nil { + out["force"] = *o.Force + } + + return out +} + +// Update ... +func (c SessionHostClient) Update(ctx context.Context, id SessionHostId, input SessionHostPatch, options UpdateOperationOptions) (result UpdateOperationResponse, err error) { + req, err := c.preparerForUpdate(ctx, id, input, options) + if err != nil { + err = autorest.NewErrorWithError(err, "sessionhost.SessionHostClient", "Update", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "sessionhost.SessionHostClient", "Update", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForUpdate(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "sessionhost.SessionHostClient", "Update", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForUpdate prepares the Update request. +func (c SessionHostClient) preparerForUpdate(ctx context.Context, id SessionHostId, input SessionHostPatch, options UpdateOperationOptions) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + for k, v := range options.toQueryString() { + queryParameters[k] = autorest.Encode("query", v) + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPatch(), + autorest.WithBaseURL(c.baseUri), + autorest.WithHeaders(options.toHeaders()), + 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 SessionHostClient) responderForUpdate(resp *http.Response) (result UpdateOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/sessionhost/model_sessionhost.go b/resource-manager/desktopvirtualization/2021-09-03-preview/sessionhost/model_sessionhost.go new file mode 100644 index 00000000000..6a59b593c4c --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/sessionhost/model_sessionhost.go @@ -0,0 +1,16 @@ +package sessionhost + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SessionHost struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *SessionHostProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/sessionhost/model_sessionhosthealthcheckfailuredetails.go b/resource-manager/desktopvirtualization/2021-09-03-preview/sessionhost/model_sessionhosthealthcheckfailuredetails.go new file mode 100644 index 00000000000..e2430e721a2 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/sessionhost/model_sessionhosthealthcheckfailuredetails.go @@ -0,0 +1,28 @@ +package sessionhost + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SessionHostHealthCheckFailureDetails struct { + ErrorCode *int64 `json:"errorCode,omitempty"` + LastHealthCheckDateTime *string `json:"lastHealthCheckDateTime,omitempty"` + Message *string `json:"message,omitempty"` +} + +func (o *SessionHostHealthCheckFailureDetails) GetLastHealthCheckDateTimeAsTime() (*time.Time, error) { + if o.LastHealthCheckDateTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastHealthCheckDateTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *SessionHostHealthCheckFailureDetails) SetLastHealthCheckDateTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastHealthCheckDateTime = &formatted +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/sessionhost/model_sessionhosthealthcheckreport.go b/resource-manager/desktopvirtualization/2021-09-03-preview/sessionhost/model_sessionhosthealthcheckreport.go new file mode 100644 index 00000000000..6545cf0a038 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/sessionhost/model_sessionhosthealthcheckreport.go @@ -0,0 +1,10 @@ +package sessionhost + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SessionHostHealthCheckReport struct { + AdditionalFailureDetails *SessionHostHealthCheckFailureDetails `json:"additionalFailureDetails,omitempty"` + HealthCheckName *HealthCheckName `json:"healthCheckName,omitempty"` + HealthCheckResult *HealthCheckResult `json:"healthCheckResult,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/sessionhost/model_sessionhostpatch.go b/resource-manager/desktopvirtualization/2021-09-03-preview/sessionhost/model_sessionhostpatch.go new file mode 100644 index 00000000000..f8fa6a57624 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/sessionhost/model_sessionhostpatch.go @@ -0,0 +1,11 @@ +package sessionhost + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SessionHostPatch struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *SessionHostPatchProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/sessionhost/model_sessionhostpatchproperties.go b/resource-manager/desktopvirtualization/2021-09-03-preview/sessionhost/model_sessionhostpatchproperties.go new file mode 100644 index 00000000000..11eecb2240b --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/sessionhost/model_sessionhostpatchproperties.go @@ -0,0 +1,9 @@ +package sessionhost + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SessionHostPatchProperties struct { + AllowNewSession *bool `json:"allowNewSession,omitempty"` + AssignedUser *string `json:"assignedUser,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/sessionhost/model_sessionhostproperties.go b/resource-manager/desktopvirtualization/2021-09-03-preview/sessionhost/model_sessionhostproperties.go new file mode 100644 index 00000000000..71f9dc987b9 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/sessionhost/model_sessionhostproperties.go @@ -0,0 +1,65 @@ +package sessionhost + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SessionHostProperties struct { + AgentVersion *string `json:"agentVersion,omitempty"` + AllowNewSession *bool `json:"allowNewSession,omitempty"` + AssignedUser *string `json:"assignedUser,omitempty"` + LastHeartBeat *string `json:"lastHeartBeat,omitempty"` + LastUpdateTime *string `json:"lastUpdateTime,omitempty"` + ObjectId *string `json:"objectId,omitempty"` + OsVersion *string `json:"osVersion,omitempty"` + ResourceId *string `json:"resourceId,omitempty"` + SessionHostHealthCheckResults *[]SessionHostHealthCheckReport `json:"sessionHostHealthCheckResults,omitempty"` + Sessions *int64 `json:"sessions,omitempty"` + Status *Status `json:"status,omitempty"` + StatusTimestamp *string `json:"statusTimestamp,omitempty"` + SxSStackVersion *string `json:"sxSStackVersion,omitempty"` + UpdateErrorMessage *string `json:"updateErrorMessage,omitempty"` + UpdateState *UpdateState `json:"updateState,omitempty"` + VirtualMachineId *string `json:"virtualMachineId,omitempty"` +} + +func (o *SessionHostProperties) GetLastHeartBeatAsTime() (*time.Time, error) { + if o.LastHeartBeat == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastHeartBeat, "2006-01-02T15:04:05Z07:00") +} + +func (o *SessionHostProperties) SetLastHeartBeatAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastHeartBeat = &formatted +} + +func (o *SessionHostProperties) GetLastUpdateTimeAsTime() (*time.Time, error) { + if o.LastUpdateTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastUpdateTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *SessionHostProperties) SetLastUpdateTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastUpdateTime = &formatted +} + +func (o *SessionHostProperties) GetStatusTimestampAsTime() (*time.Time, error) { + if o.StatusTimestamp == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StatusTimestamp, "2006-01-02T15:04:05Z07:00") +} + +func (o *SessionHostProperties) SetStatusTimestampAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StatusTimestamp = &formatted +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/sessionhost/predicates.go b/resource-manager/desktopvirtualization/2021-09-03-preview/sessionhost/predicates.go new file mode 100644 index 00000000000..e1112a03be0 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/sessionhost/predicates.go @@ -0,0 +1,24 @@ +package sessionhost + +type SessionHostOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p SessionHostOperationPredicate) Matches(input SessionHost) bool { + + if p.Id != nil && (input.Id == nil && *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil && *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil && *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/sessionhost/version.go b/resource-manager/desktopvirtualization/2021-09-03-preview/sessionhost/version.go new file mode 100644 index 00000000000..a9a312570df --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/sessionhost/version.go @@ -0,0 +1,12 @@ +package sessionhost + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2021-09-03-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/sessionhost/%s", defaultApiVersion) +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/startmenuitem/client.go b/resource-manager/desktopvirtualization/2021-09-03-preview/startmenuitem/client.go new file mode 100644 index 00000000000..4747b663da8 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/startmenuitem/client.go @@ -0,0 +1,18 @@ +package startmenuitem + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StartMenuItemClient struct { + Client autorest.Client + baseUri string +} + +func NewStartMenuItemClientWithBaseURI(endpoint string) StartMenuItemClient { + return StartMenuItemClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/startmenuitem/id_applicationgroup.go b/resource-manager/desktopvirtualization/2021-09-03-preview/startmenuitem/id_applicationgroup.go new file mode 100644 index 00000000000..fed7e31f354 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/startmenuitem/id_applicationgroup.go @@ -0,0 +1,124 @@ +package startmenuitem + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = ApplicationGroupId{} + +// ApplicationGroupId is a struct representing the Resource ID for a Application Group +type ApplicationGroupId struct { + SubscriptionId string + ResourceGroupName string + ApplicationGroupName string +} + +// NewApplicationGroupID returns a new ApplicationGroupId struct +func NewApplicationGroupID(subscriptionId string, resourceGroupName string, applicationGroupName string) ApplicationGroupId { + return ApplicationGroupId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ApplicationGroupName: applicationGroupName, + } +} + +// ParseApplicationGroupID parses 'input' into a ApplicationGroupId +func ParseApplicationGroupID(input string) (*ApplicationGroupId, error) { + parser := resourceids.NewParserFromResourceIdType(ApplicationGroupId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ApplicationGroupId{} + + 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.ApplicationGroupName, ok = parsed.Parsed["applicationGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'applicationGroupName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseApplicationGroupIDInsensitively parses 'input' case-insensitively into a ApplicationGroupId +// note: this method should only be used for API response data and not user input +func ParseApplicationGroupIDInsensitively(input string) (*ApplicationGroupId, error) { + parser := resourceids.NewParserFromResourceIdType(ApplicationGroupId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ApplicationGroupId{} + + 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.ApplicationGroupName, ok = parsed.Parsed["applicationGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'applicationGroupName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateApplicationGroupID checks that 'input' can be parsed as a Application Group ID +func ValidateApplicationGroupID(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 := ParseApplicationGroupID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Application Group ID +func (id ApplicationGroupId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DesktopVirtualization/applicationGroups/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ApplicationGroupName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Application Group ID +func (id ApplicationGroupId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftDesktopVirtualization", "Microsoft.DesktopVirtualization", "Microsoft.DesktopVirtualization"), + resourceids.StaticSegment("staticApplicationGroups", "applicationGroups", "applicationGroups"), + resourceids.UserSpecifiedSegment("applicationGroupName", "applicationGroupValue"), + } +} + +// String returns a human-readable description of this Application Group ID +func (id ApplicationGroupId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Application Group Name: %q", id.ApplicationGroupName), + } + return fmt.Sprintf("Application Group (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/startmenuitem/id_applicationgroup_test.go b/resource-manager/desktopvirtualization/2021-09-03-preview/startmenuitem/id_applicationgroup_test.go new file mode 100644 index 00000000000..918a617083d --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/startmenuitem/id_applicationgroup_test.go @@ -0,0 +1,279 @@ +package startmenuitem + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = ApplicationGroupId{} + +func TestNewApplicationGroupID(t *testing.T) { + id := NewApplicationGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "applicationGroupValue") + + 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.ApplicationGroupName != "applicationGroupValue" { + t.Fatalf("Expected %q but got %q for Segment 'ApplicationGroupName'", id.ApplicationGroupName, "applicationGroupValue") + } +} + +func TestFormatApplicationGroupID(t *testing.T) { + actual := NewApplicationGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "applicationGroupValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseApplicationGroupID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApplicationGroupId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue", + Expected: &ApplicationGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ApplicationGroupName: "applicationGroupValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApplicationGroupID(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.ApplicationGroupName != v.Expected.ApplicationGroupName { + t.Fatalf("Expected %q but got %q for ApplicationGroupName", v.Expected.ApplicationGroupName, actual.ApplicationGroupName) + } + + } +} + +func TestParseApplicationGroupIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApplicationGroupId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/aPpLiCaTiOnGrOuPs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue", + Expected: &ApplicationGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ApplicationGroupName: "applicationGroupValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/aPpLiCaTiOnGrOuPs/aPpLiCaTiOnGrOuPvAlUe", + Expected: &ApplicationGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ApplicationGroupName: "aPpLiCaTiOnGrOuPvAlUe", + }, + }, + { + // 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.dEsKtOpViRtUaLiZaTiOn/aPpLiCaTiOnGrOuPs/aPpLiCaTiOnGrOuPvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApplicationGroupIDInsensitively(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.ApplicationGroupName != v.Expected.ApplicationGroupName { + t.Fatalf("Expected %q but got %q for ApplicationGroupName", v.Expected.ApplicationGroupName, actual.ApplicationGroupName) + } + + } +} + +func TestSegmentsForApplicationGroupId(t *testing.T) { + segments := ApplicationGroupId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ApplicationGroupId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/startmenuitem/method_list_autorest.go b/resource-manager/desktopvirtualization/2021-09-03-preview/startmenuitem/method_list_autorest.go new file mode 100644 index 00000000000..360dbd9437e --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/startmenuitem/method_list_autorest.go @@ -0,0 +1,186 @@ +package startmenuitem + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + Model *[]StartMenuItem + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) +} + +type ListCompleteResult struct { + Items []StartMenuItem +} + +func (r ListOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// List ... +func (c StartMenuItemClient) List(ctx context.Context, id ApplicationGroupId) (resp ListOperationResponse, err error) { + req, err := c.preparerForList(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "startmenuitem.StartMenuItemClient", "List", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "startmenuitem.StartMenuItemClient", "List", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForList(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "startmenuitem.StartMenuItemClient", "List", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// ListComplete retrieves all of the results into a single object +func (c StartMenuItemClient) ListComplete(ctx context.Context, id ApplicationGroupId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, StartMenuItemOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c StartMenuItemClient) ListCompleteMatchingPredicate(ctx context.Context, id ApplicationGroupId, predicate StartMenuItemOperationPredicate) (resp ListCompleteResult, err error) { + items := make([]StartMenuItem, 0) + + page, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListCompleteResult{ + Items: items, + } + return out, nil +} + +// preparerForList prepares the List request. +func (c StartMenuItemClient) preparerForList(ctx context.Context, id ApplicationGroupId) (*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/startMenuItems", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListWithNextLink prepares the List request with the given nextLink token. +func (c StartMenuItemClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForList handles the response to the List request. The method always +// closes the http.Response Body. +func (c StartMenuItemClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { + type page struct { + Values []StartMenuItem `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { + req, err := c.preparerForListWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "startmenuitem.StartMenuItemClient", "List", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "startmenuitem.StartMenuItemClient", "List", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "startmenuitem.StartMenuItemClient", "List", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/startmenuitem/model_startmenuitem.go b/resource-manager/desktopvirtualization/2021-09-03-preview/startmenuitem/model_startmenuitem.go new file mode 100644 index 00000000000..966f16fd06f --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/startmenuitem/model_startmenuitem.go @@ -0,0 +1,11 @@ +package startmenuitem + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StartMenuItem struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *StartMenuItemProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/startmenuitem/model_startmenuitemproperties.go b/resource-manager/desktopvirtualization/2021-09-03-preview/startmenuitem/model_startmenuitemproperties.go new file mode 100644 index 00000000000..53a69769271 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/startmenuitem/model_startmenuitemproperties.go @@ -0,0 +1,12 @@ +package startmenuitem + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StartMenuItemProperties struct { + AppAlias *string `json:"appAlias,omitempty"` + CommandLineArguments *string `json:"commandLineArguments,omitempty"` + FilePath *string `json:"filePath,omitempty"` + IconIndex *int64 `json:"iconIndex,omitempty"` + IconPath *string `json:"iconPath,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/startmenuitem/predicates.go b/resource-manager/desktopvirtualization/2021-09-03-preview/startmenuitem/predicates.go new file mode 100644 index 00000000000..e1ee24542dd --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/startmenuitem/predicates.go @@ -0,0 +1,24 @@ +package startmenuitem + +type StartMenuItemOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p StartMenuItemOperationPredicate) Matches(input StartMenuItem) bool { + + if p.Id != nil && (input.Id == nil && *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil && *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil && *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/startmenuitem/version.go b/resource-manager/desktopvirtualization/2021-09-03-preview/startmenuitem/version.go new file mode 100644 index 00000000000..73375b36830 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/startmenuitem/version.go @@ -0,0 +1,12 @@ +package startmenuitem + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2021-09-03-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/startmenuitem/%s", defaultApiVersion) +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/usersession/client.go b/resource-manager/desktopvirtualization/2021-09-03-preview/usersession/client.go new file mode 100644 index 00000000000..3f58916e0ce --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/usersession/client.go @@ -0,0 +1,18 @@ +package usersession + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UserSessionClient struct { + Client autorest.Client + baseUri string +} + +func NewUserSessionClientWithBaseURI(endpoint string) UserSessionClient { + return UserSessionClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/usersession/constants.go b/resource-manager/desktopvirtualization/2021-09-03-preview/usersession/constants.go new file mode 100644 index 00000000000..7a32115a7e0 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/usersession/constants.go @@ -0,0 +1,74 @@ +package usersession + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApplicationType string + +const ( + ApplicationTypeDesktop ApplicationType = "Desktop" + ApplicationTypeRemoteApp ApplicationType = "RemoteApp" +) + +func PossibleValuesForApplicationType() []string { + return []string{ + string(ApplicationTypeDesktop), + string(ApplicationTypeRemoteApp), + } +} + +func parseApplicationType(input string) (*ApplicationType, error) { + vals := map[string]ApplicationType{ + "desktop": ApplicationTypeDesktop, + "remoteapp": ApplicationTypeRemoteApp, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ApplicationType(input) + return &out, nil +} + +type SessionState string + +const ( + SessionStateActive SessionState = "Active" + SessionStateDisconnected SessionState = "Disconnected" + SessionStateLogOff SessionState = "LogOff" + SessionStatePending SessionState = "Pending" + SessionStateUnknown SessionState = "Unknown" + SessionStateUserProfileDiskMounted SessionState = "UserProfileDiskMounted" +) + +func PossibleValuesForSessionState() []string { + return []string{ + string(SessionStateActive), + string(SessionStateDisconnected), + string(SessionStateLogOff), + string(SessionStatePending), + string(SessionStateUnknown), + string(SessionStateUserProfileDiskMounted), + } +} + +func parseSessionState(input string) (*SessionState, error) { + vals := map[string]SessionState{ + "active": SessionStateActive, + "disconnected": SessionStateDisconnected, + "logoff": SessionStateLogOff, + "pending": SessionStatePending, + "unknown": SessionStateUnknown, + "userprofilediskmounted": SessionStateUserProfileDiskMounted, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SessionState(input) + return &out, nil +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/usersession/id_hostpool.go b/resource-manager/desktopvirtualization/2021-09-03-preview/usersession/id_hostpool.go new file mode 100644 index 00000000000..b67dbb68b32 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/usersession/id_hostpool.go @@ -0,0 +1,124 @@ +package usersession + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = HostPoolId{} + +// HostPoolId is a struct representing the Resource ID for a Host Pool +type HostPoolId struct { + SubscriptionId string + ResourceGroupName string + HostPoolName string +} + +// NewHostPoolID returns a new HostPoolId struct +func NewHostPoolID(subscriptionId string, resourceGroupName string, hostPoolName string) HostPoolId { + return HostPoolId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + HostPoolName: hostPoolName, + } +} + +// ParseHostPoolID parses 'input' into a HostPoolId +func ParseHostPoolID(input string) (*HostPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(HostPoolId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := HostPoolId{} + + 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.HostPoolName, ok = parsed.Parsed["hostPoolName"]; !ok { + return nil, fmt.Errorf("the segment 'hostPoolName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseHostPoolIDInsensitively parses 'input' case-insensitively into a HostPoolId +// note: this method should only be used for API response data and not user input +func ParseHostPoolIDInsensitively(input string) (*HostPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(HostPoolId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := HostPoolId{} + + 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.HostPoolName, ok = parsed.Parsed["hostPoolName"]; !ok { + return nil, fmt.Errorf("the segment 'hostPoolName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateHostPoolID checks that 'input' can be parsed as a Host Pool ID +func ValidateHostPoolID(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 := ParseHostPoolID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Host Pool ID +func (id HostPoolId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DesktopVirtualization/hostPools/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.HostPoolName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Host Pool ID +func (id HostPoolId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftDesktopVirtualization", "Microsoft.DesktopVirtualization", "Microsoft.DesktopVirtualization"), + resourceids.StaticSegment("staticHostPools", "hostPools", "hostPools"), + resourceids.UserSpecifiedSegment("hostPoolName", "hostPoolValue"), + } +} + +// String returns a human-readable description of this Host Pool ID +func (id HostPoolId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Host Pool Name: %q", id.HostPoolName), + } + return fmt.Sprintf("Host Pool (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/usersession/id_hostpool_test.go b/resource-manager/desktopvirtualization/2021-09-03-preview/usersession/id_hostpool_test.go new file mode 100644 index 00000000000..afec4ae73df --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/usersession/id_hostpool_test.go @@ -0,0 +1,279 @@ +package usersession + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = HostPoolId{} + +func TestNewHostPoolID(t *testing.T) { + id := NewHostPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "hostPoolValue") + + 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.HostPoolName != "hostPoolValue" { + t.Fatalf("Expected %q but got %q for Segment 'HostPoolName'", id.HostPoolName, "hostPoolValue") + } +} + +func TestFormatHostPoolID(t *testing.T) { + actual := NewHostPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "hostPoolValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseHostPoolID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *HostPoolId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue", + Expected: &HostPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + HostPoolName: "hostPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseHostPoolID(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.HostPoolName != v.Expected.HostPoolName { + t.Fatalf("Expected %q but got %q for HostPoolName", v.Expected.HostPoolName, actual.HostPoolName) + } + + } +} + +func TestParseHostPoolIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *HostPoolId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue", + Expected: &HostPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + HostPoolName: "hostPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe", + Expected: &HostPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + HostPoolName: "hOsTpOoLvAlUe", + }, + }, + { + // 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.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseHostPoolIDInsensitively(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.HostPoolName != v.Expected.HostPoolName { + t.Fatalf("Expected %q but got %q for HostPoolName", v.Expected.HostPoolName, actual.HostPoolName) + } + + } +} + +func TestSegmentsForHostPoolId(t *testing.T) { + segments := HostPoolId{}.Segments() + if len(segments) == 0 { + t.Fatalf("HostPoolId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/usersession/id_sessionhost.go b/resource-manager/desktopvirtualization/2021-09-03-preview/usersession/id_sessionhost.go new file mode 100644 index 00000000000..88169aaadb0 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/usersession/id_sessionhost.go @@ -0,0 +1,137 @@ +package usersession + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = SessionHostId{} + +// SessionHostId is a struct representing the Resource ID for a Session Host +type SessionHostId struct { + SubscriptionId string + ResourceGroupName string + HostPoolName string + SessionHostName string +} + +// NewSessionHostID returns a new SessionHostId struct +func NewSessionHostID(subscriptionId string, resourceGroupName string, hostPoolName string, sessionHostName string) SessionHostId { + return SessionHostId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + HostPoolName: hostPoolName, + SessionHostName: sessionHostName, + } +} + +// ParseSessionHostID parses 'input' into a SessionHostId +func ParseSessionHostID(input string) (*SessionHostId, error) { + parser := resourceids.NewParserFromResourceIdType(SessionHostId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := SessionHostId{} + + 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.HostPoolName, ok = parsed.Parsed["hostPoolName"]; !ok { + return nil, fmt.Errorf("the segment 'hostPoolName' was not found in the resource id %q", input) + } + + if id.SessionHostName, ok = parsed.Parsed["sessionHostName"]; !ok { + return nil, fmt.Errorf("the segment 'sessionHostName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseSessionHostIDInsensitively parses 'input' case-insensitively into a SessionHostId +// note: this method should only be used for API response data and not user input +func ParseSessionHostIDInsensitively(input string) (*SessionHostId, error) { + parser := resourceids.NewParserFromResourceIdType(SessionHostId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := SessionHostId{} + + 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.HostPoolName, ok = parsed.Parsed["hostPoolName"]; !ok { + return nil, fmt.Errorf("the segment 'hostPoolName' was not found in the resource id %q", input) + } + + if id.SessionHostName, ok = parsed.Parsed["sessionHostName"]; !ok { + return nil, fmt.Errorf("the segment 'sessionHostName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateSessionHostID checks that 'input' can be parsed as a Session Host ID +func ValidateSessionHostID(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 := ParseSessionHostID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Session Host ID +func (id SessionHostId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DesktopVirtualization/hostPools/%s/sessionHosts/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.HostPoolName, id.SessionHostName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Session Host ID +func (id SessionHostId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftDesktopVirtualization", "Microsoft.DesktopVirtualization", "Microsoft.DesktopVirtualization"), + resourceids.StaticSegment("staticHostPools", "hostPools", "hostPools"), + resourceids.UserSpecifiedSegment("hostPoolName", "hostPoolValue"), + resourceids.StaticSegment("staticSessionHosts", "sessionHosts", "sessionHosts"), + resourceids.UserSpecifiedSegment("sessionHostName", "sessionHostValue"), + } +} + +// String returns a human-readable description of this Session Host ID +func (id SessionHostId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Host Pool Name: %q", id.HostPoolName), + fmt.Sprintf("Session Host Name: %q", id.SessionHostName), + } + return fmt.Sprintf("Session Host (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/usersession/id_sessionhost_test.go b/resource-manager/desktopvirtualization/2021-09-03-preview/usersession/id_sessionhost_test.go new file mode 100644 index 00000000000..2ae17d1d252 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/usersession/id_sessionhost_test.go @@ -0,0 +1,324 @@ +package usersession + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = SessionHostId{} + +func TestNewSessionHostID(t *testing.T) { + id := NewSessionHostID("12345678-1234-9876-4563-123456789012", "example-resource-group", "hostPoolValue", "sessionHostValue") + + 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.HostPoolName != "hostPoolValue" { + t.Fatalf("Expected %q but got %q for Segment 'HostPoolName'", id.HostPoolName, "hostPoolValue") + } + + if id.SessionHostName != "sessionHostValue" { + t.Fatalf("Expected %q but got %q for Segment 'SessionHostName'", id.SessionHostName, "sessionHostValue") + } +} + +func TestFormatSessionHostID(t *testing.T) { + actual := NewSessionHostID("12345678-1234-9876-4563-123456789012", "example-resource-group", "hostPoolValue", "sessionHostValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/sessionHosts/sessionHostValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseSessionHostID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SessionHostId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/sessionHosts", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/sessionHosts/sessionHostValue", + Expected: &SessionHostId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + HostPoolName: "hostPoolValue", + SessionHostName: "sessionHostValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/sessionHosts/sessionHostValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSessionHostID(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.HostPoolName != v.Expected.HostPoolName { + t.Fatalf("Expected %q but got %q for HostPoolName", v.Expected.HostPoolName, actual.HostPoolName) + } + + if actual.SessionHostName != v.Expected.SessionHostName { + t.Fatalf("Expected %q but got %q for SessionHostName", v.Expected.SessionHostName, actual.SessionHostName) + } + + } +} + +func TestParseSessionHostIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SessionHostId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/sessionHosts", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe/sEsSiOnHoStS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/sessionHosts/sessionHostValue", + Expected: &SessionHostId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + HostPoolName: "hostPoolValue", + SessionHostName: "sessionHostValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/sessionHosts/sessionHostValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe/sEsSiOnHoStS/sEsSiOnHoStVaLuE", + Expected: &SessionHostId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + HostPoolName: "hOsTpOoLvAlUe", + SessionHostName: "sEsSiOnHoStVaLuE", + }, + }, + { + // 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.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe/sEsSiOnHoStS/sEsSiOnHoStVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSessionHostIDInsensitively(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.HostPoolName != v.Expected.HostPoolName { + t.Fatalf("Expected %q but got %q for HostPoolName", v.Expected.HostPoolName, actual.HostPoolName) + } + + if actual.SessionHostName != v.Expected.SessionHostName { + t.Fatalf("Expected %q but got %q for SessionHostName", v.Expected.SessionHostName, actual.SessionHostName) + } + + } +} + +func TestSegmentsForSessionHostId(t *testing.T) { + segments := SessionHostId{}.Segments() + if len(segments) == 0 { + t.Fatalf("SessionHostId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/usersession/id_usersession.go b/resource-manager/desktopvirtualization/2021-09-03-preview/usersession/id_usersession.go new file mode 100644 index 00000000000..f595f47205e --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/usersession/id_usersession.go @@ -0,0 +1,150 @@ +package usersession + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = UserSessionId{} + +// UserSessionId is a struct representing the Resource ID for a User Session +type UserSessionId struct { + SubscriptionId string + ResourceGroupName string + HostPoolName string + SessionHostName string + UserSessionId string +} + +// NewUserSessionID returns a new UserSessionId struct +func NewUserSessionID(subscriptionId string, resourceGroupName string, hostPoolName string, sessionHostName string, userSessionId string) UserSessionId { + return UserSessionId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + HostPoolName: hostPoolName, + SessionHostName: sessionHostName, + UserSessionId: userSessionId, + } +} + +// ParseUserSessionID parses 'input' into a UserSessionId +func ParseUserSessionID(input string) (*UserSessionId, error) { + parser := resourceids.NewParserFromResourceIdType(UserSessionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := UserSessionId{} + + 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.HostPoolName, ok = parsed.Parsed["hostPoolName"]; !ok { + return nil, fmt.Errorf("the segment 'hostPoolName' was not found in the resource id %q", input) + } + + if id.SessionHostName, ok = parsed.Parsed["sessionHostName"]; !ok { + return nil, fmt.Errorf("the segment 'sessionHostName' was not found in the resource id %q", input) + } + + if id.UserSessionId, ok = parsed.Parsed["userSessionId"]; !ok { + return nil, fmt.Errorf("the segment 'userSessionId' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseUserSessionIDInsensitively parses 'input' case-insensitively into a UserSessionId +// note: this method should only be used for API response data and not user input +func ParseUserSessionIDInsensitively(input string) (*UserSessionId, error) { + parser := resourceids.NewParserFromResourceIdType(UserSessionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := UserSessionId{} + + 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.HostPoolName, ok = parsed.Parsed["hostPoolName"]; !ok { + return nil, fmt.Errorf("the segment 'hostPoolName' was not found in the resource id %q", input) + } + + if id.SessionHostName, ok = parsed.Parsed["sessionHostName"]; !ok { + return nil, fmt.Errorf("the segment 'sessionHostName' was not found in the resource id %q", input) + } + + if id.UserSessionId, ok = parsed.Parsed["userSessionId"]; !ok { + return nil, fmt.Errorf("the segment 'userSessionId' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateUserSessionID checks that 'input' can be parsed as a User Session ID +func ValidateUserSessionID(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 := ParseUserSessionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted User Session ID +func (id UserSessionId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DesktopVirtualization/hostPools/%s/sessionHosts/%s/userSessions/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.HostPoolName, id.SessionHostName, id.UserSessionId) +} + +// Segments returns a slice of Resource ID Segments which comprise this User Session ID +func (id UserSessionId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftDesktopVirtualization", "Microsoft.DesktopVirtualization", "Microsoft.DesktopVirtualization"), + resourceids.StaticSegment("staticHostPools", "hostPools", "hostPools"), + resourceids.UserSpecifiedSegment("hostPoolName", "hostPoolValue"), + resourceids.StaticSegment("staticSessionHosts", "sessionHosts", "sessionHosts"), + resourceids.UserSpecifiedSegment("sessionHostName", "sessionHostValue"), + resourceids.StaticSegment("staticUserSessions", "userSessions", "userSessions"), + resourceids.UserSpecifiedSegment("userSessionId", "userSessionIdValue"), + } +} + +// String returns a human-readable description of this User Session ID +func (id UserSessionId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Host Pool Name: %q", id.HostPoolName), + fmt.Sprintf("Session Host Name: %q", id.SessionHostName), + fmt.Sprintf("User Session: %q", id.UserSessionId), + } + return fmt.Sprintf("User Session (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/usersession/id_usersession_test.go b/resource-manager/desktopvirtualization/2021-09-03-preview/usersession/id_usersession_test.go new file mode 100644 index 00000000000..9dbe9ec4b86 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/usersession/id_usersession_test.go @@ -0,0 +1,369 @@ +package usersession + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = UserSessionId{} + +func TestNewUserSessionID(t *testing.T) { + id := NewUserSessionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "hostPoolValue", "sessionHostValue", "userSessionIdValue") + + 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.HostPoolName != "hostPoolValue" { + t.Fatalf("Expected %q but got %q for Segment 'HostPoolName'", id.HostPoolName, "hostPoolValue") + } + + if id.SessionHostName != "sessionHostValue" { + t.Fatalf("Expected %q but got %q for Segment 'SessionHostName'", id.SessionHostName, "sessionHostValue") + } + + if id.UserSessionId != "userSessionIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'UserSessionId'", id.UserSessionId, "userSessionIdValue") + } +} + +func TestFormatUserSessionID(t *testing.T) { + actual := NewUserSessionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "hostPoolValue", "sessionHostValue", "userSessionIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/sessionHosts/sessionHostValue/userSessions/userSessionIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseUserSessionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *UserSessionId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/sessionHosts", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/sessionHosts/sessionHostValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/sessionHosts/sessionHostValue/userSessions", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/sessionHosts/sessionHostValue/userSessions/userSessionIdValue", + Expected: &UserSessionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + HostPoolName: "hostPoolValue", + SessionHostName: "sessionHostValue", + UserSessionId: "userSessionIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/sessionHosts/sessionHostValue/userSessions/userSessionIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseUserSessionID(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.HostPoolName != v.Expected.HostPoolName { + t.Fatalf("Expected %q but got %q for HostPoolName", v.Expected.HostPoolName, actual.HostPoolName) + } + + if actual.SessionHostName != v.Expected.SessionHostName { + t.Fatalf("Expected %q but got %q for SessionHostName", v.Expected.SessionHostName, actual.SessionHostName) + } + + if actual.UserSessionId != v.Expected.UserSessionId { + t.Fatalf("Expected %q but got %q for UserSessionId", v.Expected.UserSessionId, actual.UserSessionId) + } + + } +} + +func TestParseUserSessionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *UserSessionId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/sessionHosts", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe/sEsSiOnHoStS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/sessionHosts/sessionHostValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe/sEsSiOnHoStS/sEsSiOnHoStVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/sessionHosts/sessionHostValue/userSessions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe/sEsSiOnHoStS/sEsSiOnHoStVaLuE/uSeRsEsSiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/sessionHosts/sessionHostValue/userSessions/userSessionIdValue", + Expected: &UserSessionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + HostPoolName: "hostPoolValue", + SessionHostName: "sessionHostValue", + UserSessionId: "userSessionIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/sessionHosts/sessionHostValue/userSessions/userSessionIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe/sEsSiOnHoStS/sEsSiOnHoStVaLuE/uSeRsEsSiOnS/uSeRsEsSiOnIdVaLuE", + Expected: &UserSessionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + HostPoolName: "hOsTpOoLvAlUe", + SessionHostName: "sEsSiOnHoStVaLuE", + UserSessionId: "uSeRsEsSiOnIdVaLuE", + }, + }, + { + // 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.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe/sEsSiOnHoStS/sEsSiOnHoStVaLuE/uSeRsEsSiOnS/uSeRsEsSiOnIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseUserSessionIDInsensitively(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.HostPoolName != v.Expected.HostPoolName { + t.Fatalf("Expected %q but got %q for HostPoolName", v.Expected.HostPoolName, actual.HostPoolName) + } + + if actual.SessionHostName != v.Expected.SessionHostName { + t.Fatalf("Expected %q but got %q for SessionHostName", v.Expected.SessionHostName, actual.SessionHostName) + } + + if actual.UserSessionId != v.Expected.UserSessionId { + t.Fatalf("Expected %q but got %q for UserSessionId", v.Expected.UserSessionId, actual.UserSessionId) + } + + } +} + +func TestSegmentsForUserSessionId(t *testing.T) { + segments := UserSessionId{}.Segments() + if len(segments) == 0 { + t.Fatalf("UserSessionId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/usersession/method_delete_autorest.go b/resource-manager/desktopvirtualization/2021-09-03-preview/usersession/method_delete_autorest.go new file mode 100644 index 00000000000..a6ace80a14a --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/usersession/method_delete_autorest.go @@ -0,0 +1,94 @@ +package usersession + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response +} + +type DeleteOperationOptions struct { + Force *bool +} + +func DefaultDeleteOperationOptions() DeleteOperationOptions { + return DeleteOperationOptions{} +} + +func (o DeleteOperationOptions) toHeaders() map[string]interface{} { + out := make(map[string]interface{}) + + return out +} + +func (o DeleteOperationOptions) toQueryString() map[string]interface{} { + out := make(map[string]interface{}) + + if o.Force != nil { + out["force"] = *o.Force + } + + return out +} + +// Delete ... +func (c UserSessionClient) Delete(ctx context.Context, id UserSessionId, options DeleteOperationOptions) (result DeleteOperationResponse, err error) { + req, err := c.preparerForDelete(ctx, id, options) + if err != nil { + err = autorest.NewErrorWithError(err, "usersession.UserSessionClient", "Delete", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "usersession.UserSessionClient", "Delete", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForDelete(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "usersession.UserSessionClient", "Delete", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForDelete prepares the Delete request. +func (c UserSessionClient) preparerForDelete(ctx context.Context, id UserSessionId, options DeleteOperationOptions) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + for k, v := range options.toQueryString() { + queryParameters[k] = autorest.Encode("query", v) + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsDelete(), + autorest.WithBaseURL(c.baseUri), + autorest.WithHeaders(options.toHeaders()), + 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 UserSessionClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/usersession/method_disconnect_autorest.go b/resource-manager/desktopvirtualization/2021-09-03-preview/usersession/method_disconnect_autorest.go new file mode 100644 index 00000000000..07af79bf79d --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/usersession/method_disconnect_autorest.go @@ -0,0 +1,66 @@ +package usersession + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DisconnectOperationResponse struct { + HttpResponse *http.Response +} + +// Disconnect ... +func (c UserSessionClient) Disconnect(ctx context.Context, id UserSessionId) (result DisconnectOperationResponse, err error) { + req, err := c.preparerForDisconnect(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "usersession.UserSessionClient", "Disconnect", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "usersession.UserSessionClient", "Disconnect", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForDisconnect(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "usersession.UserSessionClient", "Disconnect", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForDisconnect prepares the Disconnect request. +func (c UserSessionClient) preparerForDisconnect(ctx context.Context, id UserSessionId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/disconnect", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForDisconnect handles the response to the Disconnect request. The method always +// closes the http.Response Body. +func (c UserSessionClient) responderForDisconnect(resp *http.Response) (result DisconnectOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/usersession/method_get_autorest.go b/resource-manager/desktopvirtualization/2021-09-03-preview/usersession/method_get_autorest.go new file mode 100644 index 00000000000..95e4ede3489 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/usersession/method_get_autorest.go @@ -0,0 +1,67 @@ +package usersession + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *UserSession +} + +// Get ... +func (c UserSessionClient) Get(ctx context.Context, id UserSessionId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "usersession.UserSessionClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "usersession.UserSessionClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "usersession.UserSessionClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c UserSessionClient) preparerForGet(ctx context.Context, id UserSessionId) (*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 UserSessionClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/usersession/method_list_autorest.go b/resource-manager/desktopvirtualization/2021-09-03-preview/usersession/method_list_autorest.go new file mode 100644 index 00000000000..b0104c70b7a --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/usersession/method_list_autorest.go @@ -0,0 +1,186 @@ +package usersession + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + Model *[]UserSession + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) +} + +type ListCompleteResult struct { + Items []UserSession +} + +func (r ListOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// List ... +func (c UserSessionClient) List(ctx context.Context, id SessionHostId) (resp ListOperationResponse, err error) { + req, err := c.preparerForList(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "usersession.UserSessionClient", "List", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "usersession.UserSessionClient", "List", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForList(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "usersession.UserSessionClient", "List", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// ListComplete retrieves all of the results into a single object +func (c UserSessionClient) ListComplete(ctx context.Context, id SessionHostId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, UserSessionOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c UserSessionClient) ListCompleteMatchingPredicate(ctx context.Context, id SessionHostId, predicate UserSessionOperationPredicate) (resp ListCompleteResult, err error) { + items := make([]UserSession, 0) + + page, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListCompleteResult{ + Items: items, + } + return out, nil +} + +// preparerForList prepares the List request. +func (c UserSessionClient) preparerForList(ctx context.Context, id SessionHostId) (*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/userSessions", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListWithNextLink prepares the List request with the given nextLink token. +func (c UserSessionClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForList handles the response to the List request. The method always +// closes the http.Response Body. +func (c UserSessionClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { + type page struct { + Values []UserSession `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { + req, err := c.preparerForListWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "usersession.UserSessionClient", "List", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "usersession.UserSessionClient", "List", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "usersession.UserSessionClient", "List", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/usersession/method_listbyhostpool_autorest.go b/resource-manager/desktopvirtualization/2021-09-03-preview/usersession/method_listbyhostpool_autorest.go new file mode 100644 index 00000000000..3c04145f13f --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/usersession/method_listbyhostpool_autorest.go @@ -0,0 +1,215 @@ +package usersession + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByHostPoolOperationResponse struct { + HttpResponse *http.Response + Model *[]UserSession + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListByHostPoolOperationResponse, error) +} + +type ListByHostPoolCompleteResult struct { + Items []UserSession +} + +func (r ListByHostPoolOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListByHostPoolOperationResponse) LoadMore(ctx context.Context) (resp ListByHostPoolOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +type ListByHostPoolOperationOptions struct { + Filter *string +} + +func DefaultListByHostPoolOperationOptions() ListByHostPoolOperationOptions { + return ListByHostPoolOperationOptions{} +} + +func (o ListByHostPoolOperationOptions) toHeaders() map[string]interface{} { + out := make(map[string]interface{}) + + return out +} + +func (o ListByHostPoolOperationOptions) toQueryString() map[string]interface{} { + out := make(map[string]interface{}) + + if o.Filter != nil { + out["$filter"] = *o.Filter + } + + return out +} + +// ListByHostPool ... +func (c UserSessionClient) ListByHostPool(ctx context.Context, id HostPoolId, options ListByHostPoolOperationOptions) (resp ListByHostPoolOperationResponse, err error) { + req, err := c.preparerForListByHostPool(ctx, id, options) + if err != nil { + err = autorest.NewErrorWithError(err, "usersession.UserSessionClient", "ListByHostPool", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "usersession.UserSessionClient", "ListByHostPool", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForListByHostPool(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "usersession.UserSessionClient", "ListByHostPool", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// ListByHostPoolComplete retrieves all of the results into a single object +func (c UserSessionClient) ListByHostPoolComplete(ctx context.Context, id HostPoolId, options ListByHostPoolOperationOptions) (ListByHostPoolCompleteResult, error) { + return c.ListByHostPoolCompleteMatchingPredicate(ctx, id, options, UserSessionOperationPredicate{}) +} + +// ListByHostPoolCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c UserSessionClient) ListByHostPoolCompleteMatchingPredicate(ctx context.Context, id HostPoolId, options ListByHostPoolOperationOptions, predicate UserSessionOperationPredicate) (resp ListByHostPoolCompleteResult, err error) { + items := make([]UserSession, 0) + + page, err := c.ListByHostPool(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListByHostPoolCompleteResult{ + Items: items, + } + return out, nil +} + +// preparerForListByHostPool prepares the ListByHostPool request. +func (c UserSessionClient) preparerForListByHostPool(ctx context.Context, id HostPoolId, options ListByHostPoolOperationOptions) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + for k, v := range options.toQueryString() { + queryParameters[k] = autorest.Encode("query", v) + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithHeaders(options.toHeaders()), + autorest.WithPath(fmt.Sprintf("%s/userSessions", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListByHostPoolWithNextLink prepares the ListByHostPool request with the given nextLink token. +func (c UserSessionClient) preparerForListByHostPoolWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForListByHostPool handles the response to the ListByHostPool request. The method always +// closes the http.Response Body. +func (c UserSessionClient) responderForListByHostPool(resp *http.Response) (result ListByHostPoolOperationResponse, err error) { + type page struct { + Values []UserSession `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListByHostPoolOperationResponse, err error) { + req, err := c.preparerForListByHostPoolWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "usersession.UserSessionClient", "ListByHostPool", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "usersession.UserSessionClient", "ListByHostPool", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForListByHostPool(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "usersession.UserSessionClient", "ListByHostPool", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/usersession/method_sendmessage_autorest.go b/resource-manager/desktopvirtualization/2021-09-03-preview/usersession/method_sendmessage_autorest.go new file mode 100644 index 00000000000..8cb3b5580ec --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/usersession/method_sendmessage_autorest.go @@ -0,0 +1,67 @@ +package usersession + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SendMessageOperationResponse struct { + HttpResponse *http.Response +} + +// SendMessage ... +func (c UserSessionClient) SendMessage(ctx context.Context, id UserSessionId, input SendMessage) (result SendMessageOperationResponse, err error) { + req, err := c.preparerForSendMessage(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "usersession.UserSessionClient", "SendMessage", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "usersession.UserSessionClient", "SendMessage", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForSendMessage(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "usersession.UserSessionClient", "SendMessage", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForSendMessage prepares the SendMessage request. +func (c UserSessionClient) preparerForSendMessage(ctx context.Context, id UserSessionId, input SendMessage) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/sendMessage", id.ID())), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForSendMessage handles the response to the SendMessage request. The method always +// closes the http.Response Body. +func (c UserSessionClient) responderForSendMessage(resp *http.Response) (result SendMessageOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/usersession/model_sendmessage.go b/resource-manager/desktopvirtualization/2021-09-03-preview/usersession/model_sendmessage.go new file mode 100644 index 00000000000..6e74c2bcb0a --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/usersession/model_sendmessage.go @@ -0,0 +1,9 @@ +package usersession + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SendMessage struct { + MessageBody *string `json:"messageBody,omitempty"` + MessageTitle *string `json:"messageTitle,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/usersession/model_usersession.go b/resource-manager/desktopvirtualization/2021-09-03-preview/usersession/model_usersession.go new file mode 100644 index 00000000000..34c95e10b6f --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/usersession/model_usersession.go @@ -0,0 +1,16 @@ +package usersession + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UserSession struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *UserSessionProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/usersession/model_usersessionproperties.go b/resource-manager/desktopvirtualization/2021-09-03-preview/usersession/model_usersessionproperties.go new file mode 100644 index 00000000000..e9f81a882eb --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/usersession/model_usersessionproperties.go @@ -0,0 +1,31 @@ +package usersession + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UserSessionProperties struct { + ActiveDirectoryUserName *string `json:"activeDirectoryUserName,omitempty"` + ApplicationType *ApplicationType `json:"applicationType,omitempty"` + CreateTime *string `json:"createTime,omitempty"` + ObjectId *string `json:"objectId,omitempty"` + SessionState *SessionState `json:"sessionState,omitempty"` + UserPrincipalName *string `json:"userPrincipalName,omitempty"` +} + +func (o *UserSessionProperties) GetCreateTimeAsTime() (*time.Time, error) { + if o.CreateTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreateTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *UserSessionProperties) SetCreateTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreateTime = &formatted +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/usersession/predicates.go b/resource-manager/desktopvirtualization/2021-09-03-preview/usersession/predicates.go new file mode 100644 index 00000000000..206015c6dd2 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/usersession/predicates.go @@ -0,0 +1,24 @@ +package usersession + +type UserSessionOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p UserSessionOperationPredicate) Matches(input UserSession) bool { + + if p.Id != nil && (input.Id == nil && *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil && *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil && *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/usersession/version.go b/resource-manager/desktopvirtualization/2021-09-03-preview/usersession/version.go new file mode 100644 index 00000000000..c5379e4bd38 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/usersession/version.go @@ -0,0 +1,12 @@ +package usersession + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2021-09-03-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/usersession/%s", defaultApiVersion) +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/workspace/client.go b/resource-manager/desktopvirtualization/2021-09-03-preview/workspace/client.go new file mode 100644 index 00000000000..57fd58240e0 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/workspace/client.go @@ -0,0 +1,18 @@ +package workspace + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspaceClient struct { + Client autorest.Client + baseUri string +} + +func NewWorkspaceClientWithBaseURI(endpoint string) WorkspaceClient { + return WorkspaceClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/workspace/constants.go b/resource-manager/desktopvirtualization/2021-09-03-preview/workspace/constants.go new file mode 100644 index 00000000000..d2244015bc2 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/workspace/constants.go @@ -0,0 +1,68 @@ +package workspace + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PublicNetworkAccess string + +const ( + PublicNetworkAccessDisabled PublicNetworkAccess = "Disabled" + PublicNetworkAccessEnabled PublicNetworkAccess = "Enabled" +) + +func PossibleValuesForPublicNetworkAccess() []string { + return []string{ + string(PublicNetworkAccessDisabled), + string(PublicNetworkAccessEnabled), + } +} + +func parsePublicNetworkAccess(input string) (*PublicNetworkAccess, error) { + vals := map[string]PublicNetworkAccess{ + "disabled": PublicNetworkAccessDisabled, + "enabled": PublicNetworkAccessEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PublicNetworkAccess(input) + return &out, nil +} + +type SkuTier string + +const ( + SkuTierBasic SkuTier = "Basic" + SkuTierFree SkuTier = "Free" + SkuTierPremium SkuTier = "Premium" + SkuTierStandard SkuTier = "Standard" +) + +func PossibleValuesForSkuTier() []string { + return []string{ + string(SkuTierBasic), + string(SkuTierFree), + string(SkuTierPremium), + string(SkuTierStandard), + } +} + +func parseSkuTier(input string) (*SkuTier, error) { + vals := map[string]SkuTier{ + "basic": SkuTierBasic, + "free": SkuTierFree, + "premium": SkuTierPremium, + "standard": SkuTierStandard, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SkuTier(input) + return &out, nil +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/workspace/id_workspace.go b/resource-manager/desktopvirtualization/2021-09-03-preview/workspace/id_workspace.go new file mode 100644 index 00000000000..90f00ab2c31 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/workspace/id_workspace.go @@ -0,0 +1,124 @@ +package workspace + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace +type WorkspaceId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string +} + +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, workspaceName string) WorkspaceId { + return WorkspaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + } +} + +// ParseWorkspaceID parses 'input' into a WorkspaceId +func ParseWorkspaceID(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(WorkspaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := WorkspaceId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.WorkspaceName, ok = parsed.Parsed["workspaceName"]; !ok { + return nil, fmt.Errorf("the segment 'workspaceName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(WorkspaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := WorkspaceId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.WorkspaceName, ok = parsed.Parsed["workspaceName"]; !ok { + return nil, fmt.Errorf("the segment 'workspaceName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DesktopVirtualization/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftDesktopVirtualization", "Microsoft.DesktopVirtualization", "Microsoft.DesktopVirtualization"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + } +} + +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/workspace/id_workspace_test.go b/resource-manager/desktopvirtualization/2021-09-03-preview/workspace/id_workspace_test.go new file mode 100644 index 00000000000..bbbdfae6035 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/workspace/id_workspace_test.go @@ -0,0 +1,279 @@ +package workspace + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = WorkspaceId{} + +func TestNewWorkspaceID(t *testing.T) { + id := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } +} + +func TestFormatWorkspaceID(t *testing.T) { + actual := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/workspaces/workspaceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/workspaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/workspaces/workspaceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestParseWorkspaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/wOrKsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/workspaces/workspaceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/wOrKsPaCeS/wOrKsPaCeVaLuE", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/wOrKsPaCeS/wOrKsPaCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestSegmentsForWorkspaceId(t *testing.T) { + segments := WorkspaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/workspace/method_createorupdate_autorest.go b/resource-manager/desktopvirtualization/2021-09-03-preview/workspace/method_createorupdate_autorest.go new file mode 100644 index 00000000000..2dfa75cfe31 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/workspace/method_createorupdate_autorest.go @@ -0,0 +1,68 @@ +package workspace + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + Model *Workspace +} + +// CreateOrUpdate ... +func (c WorkspaceClient) CreateOrUpdate(ctx context.Context, id WorkspaceId, input Workspace) (result CreateOrUpdateOperationResponse, err error) { + req, err := c.preparerForCreateOrUpdate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "workspace.WorkspaceClient", "CreateOrUpdate", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "workspace.WorkspaceClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForCreateOrUpdate(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "workspace.WorkspaceClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForCreateOrUpdate prepares the CreateOrUpdate request. +func (c WorkspaceClient) preparerForCreateOrUpdate(ctx context.Context, id WorkspaceId, input Workspace) (*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)) +} + +// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always +// closes the http.Response Body. +func (c WorkspaceClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/workspace/method_delete_autorest.go b/resource-manager/desktopvirtualization/2021-09-03-preview/workspace/method_delete_autorest.go new file mode 100644 index 00000000000..dceeb977a12 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/workspace/method_delete_autorest.go @@ -0,0 +1,65 @@ +package workspace + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response +} + +// Delete ... +func (c WorkspaceClient) Delete(ctx context.Context, id WorkspaceId) (result DeleteOperationResponse, err error) { + req, err := c.preparerForDelete(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "workspace.WorkspaceClient", "Delete", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "workspace.WorkspaceClient", "Delete", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForDelete(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "workspace.WorkspaceClient", "Delete", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForDelete prepares the Delete request. +func (c WorkspaceClient) preparerForDelete(ctx context.Context, id WorkspaceId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.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 WorkspaceClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/workspace/method_get_autorest.go b/resource-manager/desktopvirtualization/2021-09-03-preview/workspace/method_get_autorest.go new file mode 100644 index 00000000000..93915990f1c --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/workspace/method_get_autorest.go @@ -0,0 +1,67 @@ +package workspace + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *Workspace +} + +// Get ... +func (c WorkspaceClient) Get(ctx context.Context, id WorkspaceId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "workspace.WorkspaceClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "workspace.WorkspaceClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "workspace.WorkspaceClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c WorkspaceClient) preparerForGet(ctx context.Context, id WorkspaceId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(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 WorkspaceClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/workspace/method_listbyresourcegroup_autorest.go b/resource-manager/desktopvirtualization/2021-09-03-preview/workspace/method_listbyresourcegroup_autorest.go new file mode 100644 index 00000000000..426896e9541 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/workspace/method_listbyresourcegroup_autorest.go @@ -0,0 +1,187 @@ +package workspace + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByResourceGroupOperationResponse struct { + HttpResponse *http.Response + Model *[]Workspace + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListByResourceGroupOperationResponse, error) +} + +type ListByResourceGroupCompleteResult struct { + Items []Workspace +} + +func (r ListByResourceGroupOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListByResourceGroupOperationResponse) LoadMore(ctx context.Context) (resp ListByResourceGroupOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// ListByResourceGroup ... +func (c WorkspaceClient) ListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (resp ListByResourceGroupOperationResponse, err error) { + req, err := c.preparerForListByResourceGroup(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "workspace.WorkspaceClient", "ListByResourceGroup", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "workspace.WorkspaceClient", "ListByResourceGroup", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForListByResourceGroup(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "workspace.WorkspaceClient", "ListByResourceGroup", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// ListByResourceGroupComplete retrieves all of the results into a single object +func (c WorkspaceClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (ListByResourceGroupCompleteResult, error) { + return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, WorkspaceOperationPredicate{}) +} + +// ListByResourceGroupCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c WorkspaceClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate WorkspaceOperationPredicate) (resp ListByResourceGroupCompleteResult, err error) { + items := make([]Workspace, 0) + + page, err := c.ListByResourceGroup(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListByResourceGroupCompleteResult{ + Items: items, + } + return out, nil +} + +// preparerForListByResourceGroup prepares the ListByResourceGroup request. +func (c WorkspaceClient) preparerForListByResourceGroup(ctx context.Context, id commonids.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.DesktopVirtualization/workspaces", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListByResourceGroupWithNextLink prepares the ListByResourceGroup request with the given nextLink token. +func (c WorkspaceClient) preparerForListByResourceGroupWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForListByResourceGroup handles the response to the ListByResourceGroup request. The method always +// closes the http.Response Body. +func (c WorkspaceClient) responderForListByResourceGroup(resp *http.Response) (result ListByResourceGroupOperationResponse, err error) { + type page struct { + Values []Workspace `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListByResourceGroupOperationResponse, err error) { + req, err := c.preparerForListByResourceGroupWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "workspace.WorkspaceClient", "ListByResourceGroup", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "workspace.WorkspaceClient", "ListByResourceGroup", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForListByResourceGroup(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "workspace.WorkspaceClient", "ListByResourceGroup", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/workspace/method_listbysubscription_autorest.go b/resource-manager/desktopvirtualization/2021-09-03-preview/workspace/method_listbysubscription_autorest.go new file mode 100644 index 00000000000..6ab5742aa3f --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/workspace/method_listbysubscription_autorest.go @@ -0,0 +1,187 @@ +package workspace + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListBySubscriptionOperationResponse struct { + HttpResponse *http.Response + Model *[]Workspace + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListBySubscriptionOperationResponse, error) +} + +type ListBySubscriptionCompleteResult struct { + Items []Workspace +} + +func (r ListBySubscriptionOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListBySubscriptionOperationResponse) LoadMore(ctx context.Context) (resp ListBySubscriptionOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// ListBySubscription ... +func (c WorkspaceClient) ListBySubscription(ctx context.Context, id commonids.SubscriptionId) (resp ListBySubscriptionOperationResponse, err error) { + req, err := c.preparerForListBySubscription(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "workspace.WorkspaceClient", "ListBySubscription", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "workspace.WorkspaceClient", "ListBySubscription", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForListBySubscription(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "workspace.WorkspaceClient", "ListBySubscription", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// ListBySubscriptionComplete retrieves all of the results into a single object +func (c WorkspaceClient) ListBySubscriptionComplete(ctx context.Context, id commonids.SubscriptionId) (ListBySubscriptionCompleteResult, error) { + return c.ListBySubscriptionCompleteMatchingPredicate(ctx, id, WorkspaceOperationPredicate{}) +} + +// ListBySubscriptionCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c WorkspaceClient) ListBySubscriptionCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate WorkspaceOperationPredicate) (resp ListBySubscriptionCompleteResult, err error) { + items := make([]Workspace, 0) + + page, err := c.ListBySubscription(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListBySubscriptionCompleteResult{ + Items: items, + } + return out, nil +} + +// preparerForListBySubscription prepares the ListBySubscription request. +func (c WorkspaceClient) preparerForListBySubscription(ctx context.Context, id commonids.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.DesktopVirtualization/workspaces", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListBySubscriptionWithNextLink prepares the ListBySubscription request with the given nextLink token. +func (c WorkspaceClient) preparerForListBySubscriptionWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForListBySubscription handles the response to the ListBySubscription request. The method always +// closes the http.Response Body. +func (c WorkspaceClient) responderForListBySubscription(resp *http.Response) (result ListBySubscriptionOperationResponse, err error) { + type page struct { + Values []Workspace `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListBySubscriptionOperationResponse, err error) { + req, err := c.preparerForListBySubscriptionWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "workspace.WorkspaceClient", "ListBySubscription", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "workspace.WorkspaceClient", "ListBySubscription", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForListBySubscription(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "workspace.WorkspaceClient", "ListBySubscription", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/workspace/method_update_autorest.go b/resource-manager/desktopvirtualization/2021-09-03-preview/workspace/method_update_autorest.go new file mode 100644 index 00000000000..d822ab589a6 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/workspace/method_update_autorest.go @@ -0,0 +1,68 @@ +package workspace + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + HttpResponse *http.Response + Model *Workspace +} + +// Update ... +func (c WorkspaceClient) Update(ctx context.Context, id WorkspaceId, input WorkspacePatch) (result UpdateOperationResponse, err error) { + req, err := c.preparerForUpdate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "workspace.WorkspaceClient", "Update", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "workspace.WorkspaceClient", "Update", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForUpdate(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "workspace.WorkspaceClient", "Update", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForUpdate prepares the Update request. +func (c WorkspaceClient) preparerForUpdate(ctx context.Context, id WorkspaceId, input WorkspacePatch) (*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 WorkspaceClient) responderForUpdate(resp *http.Response) (result UpdateOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/workspace/model_plan.go b/resource-manager/desktopvirtualization/2021-09-03-preview/workspace/model_plan.go new file mode 100644 index 00000000000..5fb713a75fe --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/workspace/model_plan.go @@ -0,0 +1,12 @@ +package workspace + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Plan struct { + Name string `json:"name"` + Product string `json:"product"` + PromotionCode *string `json:"promotionCode,omitempty"` + Publisher string `json:"publisher"` + Version *string `json:"version,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/workspace/model_sku.go b/resource-manager/desktopvirtualization/2021-09-03-preview/workspace/model_sku.go new file mode 100644 index 00000000000..8b18e233d75 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/workspace/model_sku.go @@ -0,0 +1,12 @@ +package workspace + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Sku struct { + Capacity *int64 `json:"capacity,omitempty"` + Family *string `json:"family,omitempty"` + Name string `json:"name"` + Size *string `json:"size,omitempty"` + Tier *SkuTier `json:"tier,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/workspace/model_workspace.go b/resource-manager/desktopvirtualization/2021-09-03-preview/workspace/model_workspace.go new file mode 100644 index 00000000000..6b48aa98737 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/workspace/model_workspace.go @@ -0,0 +1,25 @@ +package workspace + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/identity" + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Workspace struct { + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Identity *identity.SystemAssigned `json:"identity,omitempty"` + Kind *string `json:"kind,omitempty"` + Location *string `json:"location,omitempty"` + ManagedBy *string `json:"managedBy,omitempty"` + Name *string `json:"name,omitempty"` + Plan *Plan `json:"plan,omitempty"` + Properties *WorkspaceProperties `json:"properties,omitempty"` + Sku *Sku `json:"sku,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/workspace/model_workspacepatch.go b/resource-manager/desktopvirtualization/2021-09-03-preview/workspace/model_workspacepatch.go new file mode 100644 index 00000000000..1ac870f647e --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/workspace/model_workspacepatch.go @@ -0,0 +1,9 @@ +package workspace + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspacePatch struct { + Properties *WorkspacePatchProperties `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/workspace/model_workspacepatchproperties.go b/resource-manager/desktopvirtualization/2021-09-03-preview/workspace/model_workspacepatchproperties.go new file mode 100644 index 00000000000..3f010914b65 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/workspace/model_workspacepatchproperties.go @@ -0,0 +1,11 @@ +package workspace + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspacePatchProperties struct { + ApplicationGroupReferences *[]string `json:"applicationGroupReferences,omitempty"` + Description *string `json:"description,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + PublicNetworkAccess *PublicNetworkAccess `json:"publicNetworkAccess,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/workspace/model_workspaceproperties.go b/resource-manager/desktopvirtualization/2021-09-03-preview/workspace/model_workspaceproperties.go new file mode 100644 index 00000000000..8c39ae8289b --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/workspace/model_workspaceproperties.go @@ -0,0 +1,13 @@ +package workspace + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspaceProperties struct { + ApplicationGroupReferences *[]string `json:"applicationGroupReferences,omitempty"` + CloudPcResource *bool `json:"cloudPcResource,omitempty"` + Description *string `json:"description,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + ObjectId *string `json:"objectId,omitempty"` + PublicNetworkAccess *PublicNetworkAccess `json:"publicNetworkAccess,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/workspace/predicates.go b/resource-manager/desktopvirtualization/2021-09-03-preview/workspace/predicates.go new file mode 100644 index 00000000000..232537375c9 --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/workspace/predicates.go @@ -0,0 +1,44 @@ +package workspace + +type WorkspaceOperationPredicate struct { + Etag *string + Id *string + Kind *string + Location *string + ManagedBy *string + Name *string + Type *string +} + +func (p WorkspaceOperationPredicate) Matches(input Workspace) bool { + + if p.Etag != nil && (input.Etag == nil && *p.Etag != *input.Etag) { + return false + } + + if p.Id != nil && (input.Id == nil && *p.Id != *input.Id) { + return false + } + + if p.Kind != nil && (input.Kind == nil && *p.Kind != *input.Kind) { + return false + } + + if p.Location != nil && (input.Location == nil && *p.Location != *input.Location) { + return false + } + + if p.ManagedBy != nil && (input.ManagedBy == nil && *p.ManagedBy != *input.ManagedBy) { + return false + } + + if p.Name != nil && (input.Name == nil && *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil && *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/desktopvirtualization/2021-09-03-preview/workspace/version.go b/resource-manager/desktopvirtualization/2021-09-03-preview/workspace/version.go new file mode 100644 index 00000000000..2337ea8938f --- /dev/null +++ b/resource-manager/desktopvirtualization/2021-09-03-preview/workspace/version.go @@ -0,0 +1,12 @@ +package workspace + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2021-09-03-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/workspace/%s", defaultApiVersion) +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/application/client.go b/resource-manager/desktopvirtualization/2022-02-10-preview/application/client.go new file mode 100644 index 00000000000..56913082b95 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/application/client.go @@ -0,0 +1,18 @@ +package application + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApplicationClient struct { + Client autorest.Client + baseUri string +} + +func NewApplicationClientWithBaseURI(endpoint string) ApplicationClient { + return ApplicationClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/application/constants.go b/resource-manager/desktopvirtualization/2022-02-10-preview/application/constants.go new file mode 100644 index 00000000000..5b2bf0a7cd4 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/application/constants.go @@ -0,0 +1,65 @@ +package application + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CommandLineSetting string + +const ( + CommandLineSettingAllow CommandLineSetting = "Allow" + CommandLineSettingDoNotAllow CommandLineSetting = "DoNotAllow" + CommandLineSettingRequire CommandLineSetting = "Require" +) + +func PossibleValuesForCommandLineSetting() []string { + return []string{ + string(CommandLineSettingAllow), + string(CommandLineSettingDoNotAllow), + string(CommandLineSettingRequire), + } +} + +func parseCommandLineSetting(input string) (*CommandLineSetting, error) { + vals := map[string]CommandLineSetting{ + "allow": CommandLineSettingAllow, + "donotallow": CommandLineSettingDoNotAllow, + "require": CommandLineSettingRequire, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CommandLineSetting(input) + return &out, nil +} + +type RemoteApplicationType string + +const ( + RemoteApplicationTypeInBuilt RemoteApplicationType = "InBuilt" + RemoteApplicationTypeMsixApplication RemoteApplicationType = "MsixApplication" +) + +func PossibleValuesForRemoteApplicationType() []string { + return []string{ + string(RemoteApplicationTypeInBuilt), + string(RemoteApplicationTypeMsixApplication), + } +} + +func parseRemoteApplicationType(input string) (*RemoteApplicationType, error) { + vals := map[string]RemoteApplicationType{ + "inbuilt": RemoteApplicationTypeInBuilt, + "msixapplication": RemoteApplicationTypeMsixApplication, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RemoteApplicationType(input) + return &out, nil +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/application/id_application.go b/resource-manager/desktopvirtualization/2022-02-10-preview/application/id_application.go new file mode 100644 index 00000000000..e5609ed2b7f --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/application/id_application.go @@ -0,0 +1,137 @@ +package application + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = ApplicationId{} + +// ApplicationId is a struct representing the Resource ID for a Application +type ApplicationId struct { + SubscriptionId string + ResourceGroupName string + ApplicationGroupName string + ApplicationName string +} + +// NewApplicationID returns a new ApplicationId struct +func NewApplicationID(subscriptionId string, resourceGroupName string, applicationGroupName string, applicationName string) ApplicationId { + return ApplicationId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ApplicationGroupName: applicationGroupName, + ApplicationName: applicationName, + } +} + +// ParseApplicationID parses 'input' into a ApplicationId +func ParseApplicationID(input string) (*ApplicationId, error) { + parser := resourceids.NewParserFromResourceIdType(ApplicationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ApplicationId{} + + 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.ApplicationGroupName, ok = parsed.Parsed["applicationGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'applicationGroupName' was not found in the resource id %q", input) + } + + if id.ApplicationName, ok = parsed.Parsed["applicationName"]; !ok { + return nil, fmt.Errorf("the segment 'applicationName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseApplicationIDInsensitively parses 'input' case-insensitively into a ApplicationId +// note: this method should only be used for API response data and not user input +func ParseApplicationIDInsensitively(input string) (*ApplicationId, error) { + parser := resourceids.NewParserFromResourceIdType(ApplicationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ApplicationId{} + + 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.ApplicationGroupName, ok = parsed.Parsed["applicationGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'applicationGroupName' was not found in the resource id %q", input) + } + + if id.ApplicationName, ok = parsed.Parsed["applicationName"]; !ok { + return nil, fmt.Errorf("the segment 'applicationName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateApplicationID checks that 'input' can be parsed as a Application ID +func ValidateApplicationID(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 := ParseApplicationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Application ID +func (id ApplicationId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DesktopVirtualization/applicationGroups/%s/applications/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ApplicationGroupName, id.ApplicationName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Application ID +func (id ApplicationId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftDesktopVirtualization", "Microsoft.DesktopVirtualization", "Microsoft.DesktopVirtualization"), + resourceids.StaticSegment("staticApplicationGroups", "applicationGroups", "applicationGroups"), + resourceids.UserSpecifiedSegment("applicationGroupName", "applicationGroupValue"), + resourceids.StaticSegment("staticApplications", "applications", "applications"), + resourceids.UserSpecifiedSegment("applicationName", "applicationValue"), + } +} + +// String returns a human-readable description of this Application ID +func (id ApplicationId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Application Group Name: %q", id.ApplicationGroupName), + fmt.Sprintf("Application Name: %q", id.ApplicationName), + } + return fmt.Sprintf("Application (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/application/id_application_test.go b/resource-manager/desktopvirtualization/2022-02-10-preview/application/id_application_test.go new file mode 100644 index 00000000000..255e35ace80 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/application/id_application_test.go @@ -0,0 +1,324 @@ +package application + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = ApplicationId{} + +func TestNewApplicationID(t *testing.T) { + id := NewApplicationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "applicationGroupValue", "applicationValue") + + 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.ApplicationGroupName != "applicationGroupValue" { + t.Fatalf("Expected %q but got %q for Segment 'ApplicationGroupName'", id.ApplicationGroupName, "applicationGroupValue") + } + + if id.ApplicationName != "applicationValue" { + t.Fatalf("Expected %q but got %q for Segment 'ApplicationName'", id.ApplicationName, "applicationValue") + } +} + +func TestFormatApplicationID(t *testing.T) { + actual := NewApplicationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "applicationGroupValue", "applicationValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue/applications/applicationValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseApplicationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApplicationId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue/applications", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue/applications/applicationValue", + Expected: &ApplicationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ApplicationGroupName: "applicationGroupValue", + ApplicationName: "applicationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue/applications/applicationValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApplicationID(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.ApplicationGroupName != v.Expected.ApplicationGroupName { + t.Fatalf("Expected %q but got %q for ApplicationGroupName", v.Expected.ApplicationGroupName, actual.ApplicationGroupName) + } + + if actual.ApplicationName != v.Expected.ApplicationName { + t.Fatalf("Expected %q but got %q for ApplicationName", v.Expected.ApplicationName, actual.ApplicationName) + } + + } +} + +func TestParseApplicationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApplicationId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/aPpLiCaTiOnGrOuPs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/aPpLiCaTiOnGrOuPs/aPpLiCaTiOnGrOuPvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue/applications", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/aPpLiCaTiOnGrOuPs/aPpLiCaTiOnGrOuPvAlUe/aPpLiCaTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue/applications/applicationValue", + Expected: &ApplicationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ApplicationGroupName: "applicationGroupValue", + ApplicationName: "applicationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue/applications/applicationValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/aPpLiCaTiOnGrOuPs/aPpLiCaTiOnGrOuPvAlUe/aPpLiCaTiOnS/aPpLiCaTiOnVaLuE", + Expected: &ApplicationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ApplicationGroupName: "aPpLiCaTiOnGrOuPvAlUe", + ApplicationName: "aPpLiCaTiOnVaLuE", + }, + }, + { + // 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.dEsKtOpViRtUaLiZaTiOn/aPpLiCaTiOnGrOuPs/aPpLiCaTiOnGrOuPvAlUe/aPpLiCaTiOnS/aPpLiCaTiOnVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApplicationIDInsensitively(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.ApplicationGroupName != v.Expected.ApplicationGroupName { + t.Fatalf("Expected %q but got %q for ApplicationGroupName", v.Expected.ApplicationGroupName, actual.ApplicationGroupName) + } + + if actual.ApplicationName != v.Expected.ApplicationName { + t.Fatalf("Expected %q but got %q for ApplicationName", v.Expected.ApplicationName, actual.ApplicationName) + } + + } +} + +func TestSegmentsForApplicationId(t *testing.T) { + segments := ApplicationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ApplicationId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/application/id_applicationgroup.go b/resource-manager/desktopvirtualization/2022-02-10-preview/application/id_applicationgroup.go new file mode 100644 index 00000000000..74e10313b6a --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/application/id_applicationgroup.go @@ -0,0 +1,124 @@ +package application + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = ApplicationGroupId{} + +// ApplicationGroupId is a struct representing the Resource ID for a Application Group +type ApplicationGroupId struct { + SubscriptionId string + ResourceGroupName string + ApplicationGroupName string +} + +// NewApplicationGroupID returns a new ApplicationGroupId struct +func NewApplicationGroupID(subscriptionId string, resourceGroupName string, applicationGroupName string) ApplicationGroupId { + return ApplicationGroupId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ApplicationGroupName: applicationGroupName, + } +} + +// ParseApplicationGroupID parses 'input' into a ApplicationGroupId +func ParseApplicationGroupID(input string) (*ApplicationGroupId, error) { + parser := resourceids.NewParserFromResourceIdType(ApplicationGroupId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ApplicationGroupId{} + + 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.ApplicationGroupName, ok = parsed.Parsed["applicationGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'applicationGroupName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseApplicationGroupIDInsensitively parses 'input' case-insensitively into a ApplicationGroupId +// note: this method should only be used for API response data and not user input +func ParseApplicationGroupIDInsensitively(input string) (*ApplicationGroupId, error) { + parser := resourceids.NewParserFromResourceIdType(ApplicationGroupId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ApplicationGroupId{} + + 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.ApplicationGroupName, ok = parsed.Parsed["applicationGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'applicationGroupName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateApplicationGroupID checks that 'input' can be parsed as a Application Group ID +func ValidateApplicationGroupID(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 := ParseApplicationGroupID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Application Group ID +func (id ApplicationGroupId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DesktopVirtualization/applicationGroups/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ApplicationGroupName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Application Group ID +func (id ApplicationGroupId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftDesktopVirtualization", "Microsoft.DesktopVirtualization", "Microsoft.DesktopVirtualization"), + resourceids.StaticSegment("staticApplicationGroups", "applicationGroups", "applicationGroups"), + resourceids.UserSpecifiedSegment("applicationGroupName", "applicationGroupValue"), + } +} + +// String returns a human-readable description of this Application Group ID +func (id ApplicationGroupId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Application Group Name: %q", id.ApplicationGroupName), + } + return fmt.Sprintf("Application Group (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/application/id_applicationgroup_test.go b/resource-manager/desktopvirtualization/2022-02-10-preview/application/id_applicationgroup_test.go new file mode 100644 index 00000000000..80b402a5a80 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/application/id_applicationgroup_test.go @@ -0,0 +1,279 @@ +package application + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = ApplicationGroupId{} + +func TestNewApplicationGroupID(t *testing.T) { + id := NewApplicationGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "applicationGroupValue") + + 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.ApplicationGroupName != "applicationGroupValue" { + t.Fatalf("Expected %q but got %q for Segment 'ApplicationGroupName'", id.ApplicationGroupName, "applicationGroupValue") + } +} + +func TestFormatApplicationGroupID(t *testing.T) { + actual := NewApplicationGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "applicationGroupValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseApplicationGroupID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApplicationGroupId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue", + Expected: &ApplicationGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ApplicationGroupName: "applicationGroupValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApplicationGroupID(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.ApplicationGroupName != v.Expected.ApplicationGroupName { + t.Fatalf("Expected %q but got %q for ApplicationGroupName", v.Expected.ApplicationGroupName, actual.ApplicationGroupName) + } + + } +} + +func TestParseApplicationGroupIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApplicationGroupId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/aPpLiCaTiOnGrOuPs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue", + Expected: &ApplicationGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ApplicationGroupName: "applicationGroupValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/aPpLiCaTiOnGrOuPs/aPpLiCaTiOnGrOuPvAlUe", + Expected: &ApplicationGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ApplicationGroupName: "aPpLiCaTiOnGrOuPvAlUe", + }, + }, + { + // 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.dEsKtOpViRtUaLiZaTiOn/aPpLiCaTiOnGrOuPs/aPpLiCaTiOnGrOuPvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApplicationGroupIDInsensitively(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.ApplicationGroupName != v.Expected.ApplicationGroupName { + t.Fatalf("Expected %q but got %q for ApplicationGroupName", v.Expected.ApplicationGroupName, actual.ApplicationGroupName) + } + + } +} + +func TestSegmentsForApplicationGroupId(t *testing.T) { + segments := ApplicationGroupId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ApplicationGroupId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/application/method_createorupdate_autorest.go b/resource-manager/desktopvirtualization/2022-02-10-preview/application/method_createorupdate_autorest.go new file mode 100644 index 00000000000..667a27450cc --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/application/method_createorupdate_autorest.go @@ -0,0 +1,68 @@ +package application + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + Model *Application +} + +// CreateOrUpdate ... +func (c ApplicationClient) CreateOrUpdate(ctx context.Context, id ApplicationId, input Application) (result CreateOrUpdateOperationResponse, err error) { + req, err := c.preparerForCreateOrUpdate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "application.ApplicationClient", "CreateOrUpdate", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "application.ApplicationClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForCreateOrUpdate(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "application.ApplicationClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForCreateOrUpdate prepares the CreateOrUpdate request. +func (c ApplicationClient) preparerForCreateOrUpdate(ctx context.Context, id ApplicationId, input Application) (*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)) +} + +// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always +// closes the http.Response Body. +func (c ApplicationClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/application/method_delete_autorest.go b/resource-manager/desktopvirtualization/2022-02-10-preview/application/method_delete_autorest.go new file mode 100644 index 00000000000..0bb3f01ae02 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/application/method_delete_autorest.go @@ -0,0 +1,65 @@ +package application + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response +} + +// Delete ... +func (c ApplicationClient) Delete(ctx context.Context, id ApplicationId) (result DeleteOperationResponse, err error) { + req, err := c.preparerForDelete(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "application.ApplicationClient", "Delete", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "application.ApplicationClient", "Delete", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForDelete(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "application.ApplicationClient", "Delete", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForDelete prepares the Delete request. +func (c ApplicationClient) preparerForDelete(ctx context.Context, id ApplicationId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + 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 ApplicationClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/application/method_get_autorest.go b/resource-manager/desktopvirtualization/2022-02-10-preview/application/method_get_autorest.go new file mode 100644 index 00000000000..7c04468f2c8 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/application/method_get_autorest.go @@ -0,0 +1,67 @@ +package application + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *Application +} + +// Get ... +func (c ApplicationClient) Get(ctx context.Context, id ApplicationId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "application.ApplicationClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "application.ApplicationClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "application.ApplicationClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c ApplicationClient) preparerForGet(ctx context.Context, id ApplicationId) (*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 ApplicationClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/application/method_list_autorest.go b/resource-manager/desktopvirtualization/2022-02-10-preview/application/method_list_autorest.go new file mode 100644 index 00000000000..6810fcb1719 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/application/method_list_autorest.go @@ -0,0 +1,186 @@ +package application + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + Model *[]Application + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) +} + +type ListCompleteResult struct { + Items []Application +} + +func (r ListOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// List ... +func (c ApplicationClient) List(ctx context.Context, id ApplicationGroupId) (resp ListOperationResponse, err error) { + req, err := c.preparerForList(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "application.ApplicationClient", "List", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "application.ApplicationClient", "List", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForList(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "application.ApplicationClient", "List", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// ListComplete retrieves all of the results into a single object +func (c ApplicationClient) ListComplete(ctx context.Context, id ApplicationGroupId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, ApplicationOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c ApplicationClient) ListCompleteMatchingPredicate(ctx context.Context, id ApplicationGroupId, predicate ApplicationOperationPredicate) (resp ListCompleteResult, err error) { + items := make([]Application, 0) + + page, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListCompleteResult{ + Items: items, + } + return out, nil +} + +// preparerForList prepares the List request. +func (c ApplicationClient) preparerForList(ctx context.Context, id ApplicationGroupId) (*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/applications", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListWithNextLink prepares the List request with the given nextLink token. +func (c ApplicationClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForList handles the response to the List request. The method always +// closes the http.Response Body. +func (c ApplicationClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { + type page struct { + Values []Application `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { + req, err := c.preparerForListWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "application.ApplicationClient", "List", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "application.ApplicationClient", "List", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "application.ApplicationClient", "List", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/application/method_update_autorest.go b/resource-manager/desktopvirtualization/2022-02-10-preview/application/method_update_autorest.go new file mode 100644 index 00000000000..ac806964944 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/application/method_update_autorest.go @@ -0,0 +1,68 @@ +package application + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + HttpResponse *http.Response + Model *Application +} + +// Update ... +func (c ApplicationClient) Update(ctx context.Context, id ApplicationId, input ApplicationPatch) (result UpdateOperationResponse, err error) { + req, err := c.preparerForUpdate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "application.ApplicationClient", "Update", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "application.ApplicationClient", "Update", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForUpdate(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "application.ApplicationClient", "Update", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForUpdate prepares the Update request. +func (c ApplicationClient) preparerForUpdate(ctx context.Context, id ApplicationId, input ApplicationPatch) (*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 ApplicationClient) responderForUpdate(resp *http.Response) (result UpdateOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/application/model_application.go b/resource-manager/desktopvirtualization/2022-02-10-preview/application/model_application.go new file mode 100644 index 00000000000..700c972b9de --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/application/model_application.go @@ -0,0 +1,16 @@ +package application + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Application struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties ApplicationProperties `json:"properties"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/application/model_applicationpatch.go b/resource-manager/desktopvirtualization/2022-02-10-preview/application/model_applicationpatch.go new file mode 100644 index 00000000000..5b0e7d1a071 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/application/model_applicationpatch.go @@ -0,0 +1,9 @@ +package application + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApplicationPatch struct { + Properties *ApplicationPatchProperties `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/application/model_applicationpatchproperties.go b/resource-manager/desktopvirtualization/2022-02-10-preview/application/model_applicationpatchproperties.go new file mode 100644 index 00000000000..ada985872c6 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/application/model_applicationpatchproperties.go @@ -0,0 +1,18 @@ +package application + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApplicationPatchProperties struct { + ApplicationType *RemoteApplicationType `json:"applicationType,omitempty"` + CommandLineArguments *string `json:"commandLineArguments,omitempty"` + CommandLineSetting *CommandLineSetting `json:"commandLineSetting,omitempty"` + Description *string `json:"description,omitempty"` + FilePath *string `json:"filePath,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + IconIndex *int64 `json:"iconIndex,omitempty"` + IconPath *string `json:"iconPath,omitempty"` + MsixPackageApplicationId *string `json:"msixPackageApplicationId,omitempty"` + MsixPackageFamilyName *string `json:"msixPackageFamilyName,omitempty"` + ShowInPortal *bool `json:"showInPortal,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/application/model_applicationproperties.go b/resource-manager/desktopvirtualization/2022-02-10-preview/application/model_applicationproperties.go new file mode 100644 index 00000000000..74362ae1d50 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/application/model_applicationproperties.go @@ -0,0 +1,21 @@ +package application + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApplicationProperties struct { + ApplicationType *RemoteApplicationType `json:"applicationType,omitempty"` + CommandLineArguments *string `json:"commandLineArguments,omitempty"` + CommandLineSetting CommandLineSetting `json:"commandLineSetting"` + Description *string `json:"description,omitempty"` + FilePath *string `json:"filePath,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + IconContent *string `json:"iconContent,omitempty"` + IconHash *string `json:"iconHash,omitempty"` + IconIndex *int64 `json:"iconIndex,omitempty"` + IconPath *string `json:"iconPath,omitempty"` + MsixPackageApplicationId *string `json:"msixPackageApplicationId,omitempty"` + MsixPackageFamilyName *string `json:"msixPackageFamilyName,omitempty"` + ObjectId *string `json:"objectId,omitempty"` + ShowInPortal *bool `json:"showInPortal,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/application/predicates.go b/resource-manager/desktopvirtualization/2022-02-10-preview/application/predicates.go new file mode 100644 index 00000000000..82c6b7d376d --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/application/predicates.go @@ -0,0 +1,24 @@ +package application + +type ApplicationOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ApplicationOperationPredicate) Matches(input Application) bool { + + if p.Id != nil && (input.Id == nil && *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil && *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil && *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/application/version.go b/resource-manager/desktopvirtualization/2022-02-10-preview/application/version.go new file mode 100644 index 00000000000..48bb39efae5 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/application/version.go @@ -0,0 +1,12 @@ +package application + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2022-02-10-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/application/%s", defaultApiVersion) +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/applicationgroup/client.go b/resource-manager/desktopvirtualization/2022-02-10-preview/applicationgroup/client.go new file mode 100644 index 00000000000..20ca14a850a --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/applicationgroup/client.go @@ -0,0 +1,18 @@ +package applicationgroup + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApplicationGroupClient struct { + Client autorest.Client + baseUri string +} + +func NewApplicationGroupClientWithBaseURI(endpoint string) ApplicationGroupClient { + return ApplicationGroupClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/applicationgroup/constants.go b/resource-manager/desktopvirtualization/2022-02-10-preview/applicationgroup/constants.go new file mode 100644 index 00000000000..a24e7261f53 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/applicationgroup/constants.go @@ -0,0 +1,105 @@ +package applicationgroup + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApplicationGroupType string + +const ( + ApplicationGroupTypeDesktop ApplicationGroupType = "Desktop" + ApplicationGroupTypeRemoteApp ApplicationGroupType = "RemoteApp" +) + +func PossibleValuesForApplicationGroupType() []string { + return []string{ + string(ApplicationGroupTypeDesktop), + string(ApplicationGroupTypeRemoteApp), + } +} + +func parseApplicationGroupType(input string) (*ApplicationGroupType, error) { + vals := map[string]ApplicationGroupType{ + "desktop": ApplicationGroupTypeDesktop, + "remoteapp": ApplicationGroupTypeRemoteApp, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ApplicationGroupType(input) + return &out, nil +} + +type Operation string + +const ( + OperationComplete Operation = "Complete" + OperationHide Operation = "Hide" + OperationRevoke Operation = "Revoke" + OperationStart Operation = "Start" + OperationUnhide Operation = "Unhide" +) + +func PossibleValuesForOperation() []string { + return []string{ + string(OperationComplete), + string(OperationHide), + string(OperationRevoke), + string(OperationStart), + string(OperationUnhide), + } +} + +func parseOperation(input string) (*Operation, error) { + vals := map[string]Operation{ + "complete": OperationComplete, + "hide": OperationHide, + "revoke": OperationRevoke, + "start": OperationStart, + "unhide": OperationUnhide, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Operation(input) + return &out, nil +} + +type SkuTier string + +const ( + SkuTierBasic SkuTier = "Basic" + SkuTierFree SkuTier = "Free" + SkuTierPremium SkuTier = "Premium" + SkuTierStandard SkuTier = "Standard" +) + +func PossibleValuesForSkuTier() []string { + return []string{ + string(SkuTierBasic), + string(SkuTierFree), + string(SkuTierPremium), + string(SkuTierStandard), + } +} + +func parseSkuTier(input string) (*SkuTier, error) { + vals := map[string]SkuTier{ + "basic": SkuTierBasic, + "free": SkuTierFree, + "premium": SkuTierPremium, + "standard": SkuTierStandard, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SkuTier(input) + return &out, nil +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/applicationgroup/id_applicationgroup.go b/resource-manager/desktopvirtualization/2022-02-10-preview/applicationgroup/id_applicationgroup.go new file mode 100644 index 00000000000..6c20bd489e9 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/applicationgroup/id_applicationgroup.go @@ -0,0 +1,124 @@ +package applicationgroup + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = ApplicationGroupId{} + +// ApplicationGroupId is a struct representing the Resource ID for a Application Group +type ApplicationGroupId struct { + SubscriptionId string + ResourceGroupName string + ApplicationGroupName string +} + +// NewApplicationGroupID returns a new ApplicationGroupId struct +func NewApplicationGroupID(subscriptionId string, resourceGroupName string, applicationGroupName string) ApplicationGroupId { + return ApplicationGroupId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ApplicationGroupName: applicationGroupName, + } +} + +// ParseApplicationGroupID parses 'input' into a ApplicationGroupId +func ParseApplicationGroupID(input string) (*ApplicationGroupId, error) { + parser := resourceids.NewParserFromResourceIdType(ApplicationGroupId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ApplicationGroupId{} + + 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.ApplicationGroupName, ok = parsed.Parsed["applicationGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'applicationGroupName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseApplicationGroupIDInsensitively parses 'input' case-insensitively into a ApplicationGroupId +// note: this method should only be used for API response data and not user input +func ParseApplicationGroupIDInsensitively(input string) (*ApplicationGroupId, error) { + parser := resourceids.NewParserFromResourceIdType(ApplicationGroupId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ApplicationGroupId{} + + 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.ApplicationGroupName, ok = parsed.Parsed["applicationGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'applicationGroupName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateApplicationGroupID checks that 'input' can be parsed as a Application Group ID +func ValidateApplicationGroupID(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 := ParseApplicationGroupID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Application Group ID +func (id ApplicationGroupId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DesktopVirtualization/applicationGroups/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ApplicationGroupName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Application Group ID +func (id ApplicationGroupId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftDesktopVirtualization", "Microsoft.DesktopVirtualization", "Microsoft.DesktopVirtualization"), + resourceids.StaticSegment("staticApplicationGroups", "applicationGroups", "applicationGroups"), + resourceids.UserSpecifiedSegment("applicationGroupName", "applicationGroupValue"), + } +} + +// String returns a human-readable description of this Application Group ID +func (id ApplicationGroupId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Application Group Name: %q", id.ApplicationGroupName), + } + return fmt.Sprintf("Application Group (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/applicationgroup/id_applicationgroup_test.go b/resource-manager/desktopvirtualization/2022-02-10-preview/applicationgroup/id_applicationgroup_test.go new file mode 100644 index 00000000000..253650b9f15 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/applicationgroup/id_applicationgroup_test.go @@ -0,0 +1,279 @@ +package applicationgroup + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = ApplicationGroupId{} + +func TestNewApplicationGroupID(t *testing.T) { + id := NewApplicationGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "applicationGroupValue") + + 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.ApplicationGroupName != "applicationGroupValue" { + t.Fatalf("Expected %q but got %q for Segment 'ApplicationGroupName'", id.ApplicationGroupName, "applicationGroupValue") + } +} + +func TestFormatApplicationGroupID(t *testing.T) { + actual := NewApplicationGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "applicationGroupValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseApplicationGroupID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApplicationGroupId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue", + Expected: &ApplicationGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ApplicationGroupName: "applicationGroupValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApplicationGroupID(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.ApplicationGroupName != v.Expected.ApplicationGroupName { + t.Fatalf("Expected %q but got %q for ApplicationGroupName", v.Expected.ApplicationGroupName, actual.ApplicationGroupName) + } + + } +} + +func TestParseApplicationGroupIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApplicationGroupId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/aPpLiCaTiOnGrOuPs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue", + Expected: &ApplicationGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ApplicationGroupName: "applicationGroupValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/aPpLiCaTiOnGrOuPs/aPpLiCaTiOnGrOuPvAlUe", + Expected: &ApplicationGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ApplicationGroupName: "aPpLiCaTiOnGrOuPvAlUe", + }, + }, + { + // 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.dEsKtOpViRtUaLiZaTiOn/aPpLiCaTiOnGrOuPs/aPpLiCaTiOnGrOuPvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApplicationGroupIDInsensitively(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.ApplicationGroupName != v.Expected.ApplicationGroupName { + t.Fatalf("Expected %q but got %q for ApplicationGroupName", v.Expected.ApplicationGroupName, actual.ApplicationGroupName) + } + + } +} + +func TestSegmentsForApplicationGroupId(t *testing.T) { + segments := ApplicationGroupId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ApplicationGroupId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/applicationgroup/method_createorupdate_autorest.go b/resource-manager/desktopvirtualization/2022-02-10-preview/applicationgroup/method_createorupdate_autorest.go new file mode 100644 index 00000000000..268106c8d09 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/applicationgroup/method_createorupdate_autorest.go @@ -0,0 +1,68 @@ +package applicationgroup + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + Model *ApplicationGroup +} + +// CreateOrUpdate ... +func (c ApplicationGroupClient) CreateOrUpdate(ctx context.Context, id ApplicationGroupId, input ApplicationGroup) (result CreateOrUpdateOperationResponse, err error) { + req, err := c.preparerForCreateOrUpdate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "applicationgroup.ApplicationGroupClient", "CreateOrUpdate", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "applicationgroup.ApplicationGroupClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForCreateOrUpdate(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "applicationgroup.ApplicationGroupClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForCreateOrUpdate prepares the CreateOrUpdate request. +func (c ApplicationGroupClient) preparerForCreateOrUpdate(ctx context.Context, id ApplicationGroupId, input ApplicationGroup) (*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)) +} + +// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always +// closes the http.Response Body. +func (c ApplicationGroupClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/applicationgroup/method_delete_autorest.go b/resource-manager/desktopvirtualization/2022-02-10-preview/applicationgroup/method_delete_autorest.go new file mode 100644 index 00000000000..981983b00a9 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/applicationgroup/method_delete_autorest.go @@ -0,0 +1,65 @@ +package applicationgroup + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response +} + +// Delete ... +func (c ApplicationGroupClient) Delete(ctx context.Context, id ApplicationGroupId) (result DeleteOperationResponse, err error) { + req, err := c.preparerForDelete(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "applicationgroup.ApplicationGroupClient", "Delete", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "applicationgroup.ApplicationGroupClient", "Delete", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForDelete(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "applicationgroup.ApplicationGroupClient", "Delete", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForDelete prepares the Delete request. +func (c ApplicationGroupClient) preparerForDelete(ctx context.Context, id ApplicationGroupId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + 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 ApplicationGroupClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/applicationgroup/method_get_autorest.go b/resource-manager/desktopvirtualization/2022-02-10-preview/applicationgroup/method_get_autorest.go new file mode 100644 index 00000000000..77376fc5b5c --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/applicationgroup/method_get_autorest.go @@ -0,0 +1,67 @@ +package applicationgroup + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *ApplicationGroup +} + +// Get ... +func (c ApplicationGroupClient) Get(ctx context.Context, id ApplicationGroupId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "applicationgroup.ApplicationGroupClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "applicationgroup.ApplicationGroupClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "applicationgroup.ApplicationGroupClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c ApplicationGroupClient) preparerForGet(ctx context.Context, id ApplicationGroupId) (*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 ApplicationGroupClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/applicationgroup/method_listbyresourcegroup_autorest.go b/resource-manager/desktopvirtualization/2022-02-10-preview/applicationgroup/method_listbyresourcegroup_autorest.go new file mode 100644 index 00000000000..16186a1f419 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/applicationgroup/method_listbyresourcegroup_autorest.go @@ -0,0 +1,216 @@ +package applicationgroup + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByResourceGroupOperationResponse struct { + HttpResponse *http.Response + Model *[]ApplicationGroup + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListByResourceGroupOperationResponse, error) +} + +type ListByResourceGroupCompleteResult struct { + Items []ApplicationGroup +} + +func (r ListByResourceGroupOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListByResourceGroupOperationResponse) LoadMore(ctx context.Context) (resp ListByResourceGroupOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +type ListByResourceGroupOperationOptions struct { + Filter *string +} + +func DefaultListByResourceGroupOperationOptions() ListByResourceGroupOperationOptions { + return ListByResourceGroupOperationOptions{} +} + +func (o ListByResourceGroupOperationOptions) toHeaders() map[string]interface{} { + out := make(map[string]interface{}) + + return out +} + +func (o ListByResourceGroupOperationOptions) toQueryString() map[string]interface{} { + out := make(map[string]interface{}) + + if o.Filter != nil { + out["$filter"] = *o.Filter + } + + return out +} + +// ListByResourceGroup ... +func (c ApplicationGroupClient) ListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions) (resp ListByResourceGroupOperationResponse, err error) { + req, err := c.preparerForListByResourceGroup(ctx, id, options) + if err != nil { + err = autorest.NewErrorWithError(err, "applicationgroup.ApplicationGroupClient", "ListByResourceGroup", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "applicationgroup.ApplicationGroupClient", "ListByResourceGroup", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForListByResourceGroup(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "applicationgroup.ApplicationGroupClient", "ListByResourceGroup", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// ListByResourceGroupComplete retrieves all of the results into a single object +func (c ApplicationGroupClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions) (ListByResourceGroupCompleteResult, error) { + return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, options, ApplicationGroupOperationPredicate{}) +} + +// ListByResourceGroupCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c ApplicationGroupClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions, predicate ApplicationGroupOperationPredicate) (resp ListByResourceGroupCompleteResult, err error) { + items := make([]ApplicationGroup, 0) + + page, err := c.ListByResourceGroup(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListByResourceGroupCompleteResult{ + Items: items, + } + return out, nil +} + +// preparerForListByResourceGroup prepares the ListByResourceGroup request. +func (c ApplicationGroupClient) preparerForListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + for k, v := range options.toQueryString() { + queryParameters[k] = autorest.Encode("query", v) + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithHeaders(options.toHeaders()), + autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.DesktopVirtualization/applicationGroups", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListByResourceGroupWithNextLink prepares the ListByResourceGroup request with the given nextLink token. +func (c ApplicationGroupClient) preparerForListByResourceGroupWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForListByResourceGroup handles the response to the ListByResourceGroup request. The method always +// closes the http.Response Body. +func (c ApplicationGroupClient) responderForListByResourceGroup(resp *http.Response) (result ListByResourceGroupOperationResponse, err error) { + type page struct { + Values []ApplicationGroup `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListByResourceGroupOperationResponse, err error) { + req, err := c.preparerForListByResourceGroupWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "applicationgroup.ApplicationGroupClient", "ListByResourceGroup", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "applicationgroup.ApplicationGroupClient", "ListByResourceGroup", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForListByResourceGroup(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "applicationgroup.ApplicationGroupClient", "ListByResourceGroup", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/applicationgroup/method_listbysubscription_autorest.go b/resource-manager/desktopvirtualization/2022-02-10-preview/applicationgroup/method_listbysubscription_autorest.go new file mode 100644 index 00000000000..18a438e150d --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/applicationgroup/method_listbysubscription_autorest.go @@ -0,0 +1,216 @@ +package applicationgroup + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListBySubscriptionOperationResponse struct { + HttpResponse *http.Response + Model *[]ApplicationGroup + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListBySubscriptionOperationResponse, error) +} + +type ListBySubscriptionCompleteResult struct { + Items []ApplicationGroup +} + +func (r ListBySubscriptionOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListBySubscriptionOperationResponse) LoadMore(ctx context.Context) (resp ListBySubscriptionOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +type ListBySubscriptionOperationOptions struct { + Filter *string +} + +func DefaultListBySubscriptionOperationOptions() ListBySubscriptionOperationOptions { + return ListBySubscriptionOperationOptions{} +} + +func (o ListBySubscriptionOperationOptions) toHeaders() map[string]interface{} { + out := make(map[string]interface{}) + + return out +} + +func (o ListBySubscriptionOperationOptions) toQueryString() map[string]interface{} { + out := make(map[string]interface{}) + + if o.Filter != nil { + out["$filter"] = *o.Filter + } + + return out +} + +// ListBySubscription ... +func (c ApplicationGroupClient) ListBySubscription(ctx context.Context, id commonids.SubscriptionId, options ListBySubscriptionOperationOptions) (resp ListBySubscriptionOperationResponse, err error) { + req, err := c.preparerForListBySubscription(ctx, id, options) + if err != nil { + err = autorest.NewErrorWithError(err, "applicationgroup.ApplicationGroupClient", "ListBySubscription", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "applicationgroup.ApplicationGroupClient", "ListBySubscription", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForListBySubscription(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "applicationgroup.ApplicationGroupClient", "ListBySubscription", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// ListBySubscriptionComplete retrieves all of the results into a single object +func (c ApplicationGroupClient) ListBySubscriptionComplete(ctx context.Context, id commonids.SubscriptionId, options ListBySubscriptionOperationOptions) (ListBySubscriptionCompleteResult, error) { + return c.ListBySubscriptionCompleteMatchingPredicate(ctx, id, options, ApplicationGroupOperationPredicate{}) +} + +// ListBySubscriptionCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c ApplicationGroupClient) ListBySubscriptionCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, options ListBySubscriptionOperationOptions, predicate ApplicationGroupOperationPredicate) (resp ListBySubscriptionCompleteResult, err error) { + items := make([]ApplicationGroup, 0) + + page, err := c.ListBySubscription(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListBySubscriptionCompleteResult{ + Items: items, + } + return out, nil +} + +// preparerForListBySubscription prepares the ListBySubscription request. +func (c ApplicationGroupClient) preparerForListBySubscription(ctx context.Context, id commonids.SubscriptionId, options ListBySubscriptionOperationOptions) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + for k, v := range options.toQueryString() { + queryParameters[k] = autorest.Encode("query", v) + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithHeaders(options.toHeaders()), + autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.DesktopVirtualization/applicationGroups", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListBySubscriptionWithNextLink prepares the ListBySubscription request with the given nextLink token. +func (c ApplicationGroupClient) preparerForListBySubscriptionWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForListBySubscription handles the response to the ListBySubscription request. The method always +// closes the http.Response Body. +func (c ApplicationGroupClient) responderForListBySubscription(resp *http.Response) (result ListBySubscriptionOperationResponse, err error) { + type page struct { + Values []ApplicationGroup `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListBySubscriptionOperationResponse, err error) { + req, err := c.preparerForListBySubscriptionWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "applicationgroup.ApplicationGroupClient", "ListBySubscription", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "applicationgroup.ApplicationGroupClient", "ListBySubscription", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForListBySubscription(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "applicationgroup.ApplicationGroupClient", "ListBySubscription", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/applicationgroup/method_update_autorest.go b/resource-manager/desktopvirtualization/2022-02-10-preview/applicationgroup/method_update_autorest.go new file mode 100644 index 00000000000..b8b18e55d46 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/applicationgroup/method_update_autorest.go @@ -0,0 +1,68 @@ +package applicationgroup + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + HttpResponse *http.Response + Model *ApplicationGroup +} + +// Update ... +func (c ApplicationGroupClient) Update(ctx context.Context, id ApplicationGroupId, input ApplicationGroupPatch) (result UpdateOperationResponse, err error) { + req, err := c.preparerForUpdate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "applicationgroup.ApplicationGroupClient", "Update", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "applicationgroup.ApplicationGroupClient", "Update", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForUpdate(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "applicationgroup.ApplicationGroupClient", "Update", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForUpdate prepares the Update request. +func (c ApplicationGroupClient) preparerForUpdate(ctx context.Context, id ApplicationGroupId, input ApplicationGroupPatch) (*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 ApplicationGroupClient) responderForUpdate(resp *http.Response) (result UpdateOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/applicationgroup/model_applicationgroup.go b/resource-manager/desktopvirtualization/2022-02-10-preview/applicationgroup/model_applicationgroup.go new file mode 100644 index 00000000000..afb13f5670b --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/applicationgroup/model_applicationgroup.go @@ -0,0 +1,25 @@ +package applicationgroup + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/identity" + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApplicationGroup struct { + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Identity *identity.SystemAssigned `json:"identity,omitempty"` + Kind *string `json:"kind,omitempty"` + Location *string `json:"location,omitempty"` + ManagedBy *string `json:"managedBy,omitempty"` + Name *string `json:"name,omitempty"` + Plan *Plan `json:"plan,omitempty"` + Properties ApplicationGroupProperties `json:"properties"` + Sku *Sku `json:"sku,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/applicationgroup/model_applicationgrouppatch.go b/resource-manager/desktopvirtualization/2022-02-10-preview/applicationgroup/model_applicationgrouppatch.go new file mode 100644 index 00000000000..e5d63002544 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/applicationgroup/model_applicationgrouppatch.go @@ -0,0 +1,12 @@ +package applicationgroup + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApplicationGroupPatch struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ApplicationGroupPatchProperties `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/applicationgroup/model_applicationgrouppatchproperties.go b/resource-manager/desktopvirtualization/2022-02-10-preview/applicationgroup/model_applicationgrouppatchproperties.go new file mode 100644 index 00000000000..2f2f5c20d79 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/applicationgroup/model_applicationgrouppatchproperties.go @@ -0,0 +1,9 @@ +package applicationgroup + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApplicationGroupPatchProperties struct { + Description *string `json:"description,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/applicationgroup/model_applicationgroupproperties.go b/resource-manager/desktopvirtualization/2022-02-10-preview/applicationgroup/model_applicationgroupproperties.go new file mode 100644 index 00000000000..8cc435c3bd9 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/applicationgroup/model_applicationgroupproperties.go @@ -0,0 +1,15 @@ +package applicationgroup + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApplicationGroupProperties struct { + ApplicationGroupType ApplicationGroupType `json:"applicationGroupType"` + CloudPcResource *bool `json:"cloudPcResource,omitempty"` + Description *string `json:"description,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + HostPoolArmPath string `json:"hostPoolArmPath"` + MigrationRequest *MigrationRequestProperties `json:"migrationRequest,omitempty"` + ObjectId *string `json:"objectId,omitempty"` + WorkspaceArmPath *string `json:"workspaceArmPath,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/applicationgroup/model_migrationrequestproperties.go b/resource-manager/desktopvirtualization/2022-02-10-preview/applicationgroup/model_migrationrequestproperties.go new file mode 100644 index 00000000000..238d6d02365 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/applicationgroup/model_migrationrequestproperties.go @@ -0,0 +1,9 @@ +package applicationgroup + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MigrationRequestProperties struct { + MigrationPath *string `json:"migrationPath,omitempty"` + Operation *Operation `json:"operation,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/applicationgroup/model_plan.go b/resource-manager/desktopvirtualization/2022-02-10-preview/applicationgroup/model_plan.go new file mode 100644 index 00000000000..865073b6a3e --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/applicationgroup/model_plan.go @@ -0,0 +1,12 @@ +package applicationgroup + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Plan struct { + Name string `json:"name"` + Product string `json:"product"` + PromotionCode *string `json:"promotionCode,omitempty"` + Publisher string `json:"publisher"` + Version *string `json:"version,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/applicationgroup/model_sku.go b/resource-manager/desktopvirtualization/2022-02-10-preview/applicationgroup/model_sku.go new file mode 100644 index 00000000000..57066762740 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/applicationgroup/model_sku.go @@ -0,0 +1,12 @@ +package applicationgroup + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Sku struct { + Capacity *int64 `json:"capacity,omitempty"` + Family *string `json:"family,omitempty"` + Name string `json:"name"` + Size *string `json:"size,omitempty"` + Tier *SkuTier `json:"tier,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/applicationgroup/predicates.go b/resource-manager/desktopvirtualization/2022-02-10-preview/applicationgroup/predicates.go new file mode 100644 index 00000000000..f0e69f1abd2 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/applicationgroup/predicates.go @@ -0,0 +1,44 @@ +package applicationgroup + +type ApplicationGroupOperationPredicate struct { + Etag *string + Id *string + Kind *string + Location *string + ManagedBy *string + Name *string + Type *string +} + +func (p ApplicationGroupOperationPredicate) Matches(input ApplicationGroup) bool { + + if p.Etag != nil && (input.Etag == nil && *p.Etag != *input.Etag) { + return false + } + + if p.Id != nil && (input.Id == nil && *p.Id != *input.Id) { + return false + } + + if p.Kind != nil && (input.Kind == nil && *p.Kind != *input.Kind) { + return false + } + + if p.Location != nil && (input.Location == nil && *p.Location != *input.Location) { + return false + } + + if p.ManagedBy != nil && (input.ManagedBy == nil && *p.ManagedBy != *input.ManagedBy) { + return false + } + + if p.Name != nil && (input.Name == nil && *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil && *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/applicationgroup/version.go b/resource-manager/desktopvirtualization/2022-02-10-preview/applicationgroup/version.go new file mode 100644 index 00000000000..077a0ddc441 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/applicationgroup/version.go @@ -0,0 +1,12 @@ +package applicationgroup + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2022-02-10-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/applicationgroup/%s", defaultApiVersion) +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/desktop/client.go b/resource-manager/desktopvirtualization/2022-02-10-preview/desktop/client.go new file mode 100644 index 00000000000..cc153930daa --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/desktop/client.go @@ -0,0 +1,18 @@ +package desktop + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DesktopClient struct { + Client autorest.Client + baseUri string +} + +func NewDesktopClientWithBaseURI(endpoint string) DesktopClient { + return DesktopClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/desktop/id_applicationgroup.go b/resource-manager/desktopvirtualization/2022-02-10-preview/desktop/id_applicationgroup.go new file mode 100644 index 00000000000..fe30e445a4f --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/desktop/id_applicationgroup.go @@ -0,0 +1,124 @@ +package desktop + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = ApplicationGroupId{} + +// ApplicationGroupId is a struct representing the Resource ID for a Application Group +type ApplicationGroupId struct { + SubscriptionId string + ResourceGroupName string + ApplicationGroupName string +} + +// NewApplicationGroupID returns a new ApplicationGroupId struct +func NewApplicationGroupID(subscriptionId string, resourceGroupName string, applicationGroupName string) ApplicationGroupId { + return ApplicationGroupId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ApplicationGroupName: applicationGroupName, + } +} + +// ParseApplicationGroupID parses 'input' into a ApplicationGroupId +func ParseApplicationGroupID(input string) (*ApplicationGroupId, error) { + parser := resourceids.NewParserFromResourceIdType(ApplicationGroupId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ApplicationGroupId{} + + 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.ApplicationGroupName, ok = parsed.Parsed["applicationGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'applicationGroupName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseApplicationGroupIDInsensitively parses 'input' case-insensitively into a ApplicationGroupId +// note: this method should only be used for API response data and not user input +func ParseApplicationGroupIDInsensitively(input string) (*ApplicationGroupId, error) { + parser := resourceids.NewParserFromResourceIdType(ApplicationGroupId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ApplicationGroupId{} + + 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.ApplicationGroupName, ok = parsed.Parsed["applicationGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'applicationGroupName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateApplicationGroupID checks that 'input' can be parsed as a Application Group ID +func ValidateApplicationGroupID(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 := ParseApplicationGroupID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Application Group ID +func (id ApplicationGroupId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DesktopVirtualization/applicationGroups/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ApplicationGroupName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Application Group ID +func (id ApplicationGroupId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftDesktopVirtualization", "Microsoft.DesktopVirtualization", "Microsoft.DesktopVirtualization"), + resourceids.StaticSegment("staticApplicationGroups", "applicationGroups", "applicationGroups"), + resourceids.UserSpecifiedSegment("applicationGroupName", "applicationGroupValue"), + } +} + +// String returns a human-readable description of this Application Group ID +func (id ApplicationGroupId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Application Group Name: %q", id.ApplicationGroupName), + } + return fmt.Sprintf("Application Group (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/desktop/id_applicationgroup_test.go b/resource-manager/desktopvirtualization/2022-02-10-preview/desktop/id_applicationgroup_test.go new file mode 100644 index 00000000000..0a3348e4c4c --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/desktop/id_applicationgroup_test.go @@ -0,0 +1,279 @@ +package desktop + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = ApplicationGroupId{} + +func TestNewApplicationGroupID(t *testing.T) { + id := NewApplicationGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "applicationGroupValue") + + 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.ApplicationGroupName != "applicationGroupValue" { + t.Fatalf("Expected %q but got %q for Segment 'ApplicationGroupName'", id.ApplicationGroupName, "applicationGroupValue") + } +} + +func TestFormatApplicationGroupID(t *testing.T) { + actual := NewApplicationGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "applicationGroupValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseApplicationGroupID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApplicationGroupId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue", + Expected: &ApplicationGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ApplicationGroupName: "applicationGroupValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApplicationGroupID(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.ApplicationGroupName != v.Expected.ApplicationGroupName { + t.Fatalf("Expected %q but got %q for ApplicationGroupName", v.Expected.ApplicationGroupName, actual.ApplicationGroupName) + } + + } +} + +func TestParseApplicationGroupIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApplicationGroupId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/aPpLiCaTiOnGrOuPs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue", + Expected: &ApplicationGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ApplicationGroupName: "applicationGroupValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/aPpLiCaTiOnGrOuPs/aPpLiCaTiOnGrOuPvAlUe", + Expected: &ApplicationGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ApplicationGroupName: "aPpLiCaTiOnGrOuPvAlUe", + }, + }, + { + // 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.dEsKtOpViRtUaLiZaTiOn/aPpLiCaTiOnGrOuPs/aPpLiCaTiOnGrOuPvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApplicationGroupIDInsensitively(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.ApplicationGroupName != v.Expected.ApplicationGroupName { + t.Fatalf("Expected %q but got %q for ApplicationGroupName", v.Expected.ApplicationGroupName, actual.ApplicationGroupName) + } + + } +} + +func TestSegmentsForApplicationGroupId(t *testing.T) { + segments := ApplicationGroupId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ApplicationGroupId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/desktop/id_desktop.go b/resource-manager/desktopvirtualization/2022-02-10-preview/desktop/id_desktop.go new file mode 100644 index 00000000000..1b44ed2f282 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/desktop/id_desktop.go @@ -0,0 +1,137 @@ +package desktop + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = DesktopId{} + +// DesktopId is a struct representing the Resource ID for a Desktop +type DesktopId struct { + SubscriptionId string + ResourceGroupName string + ApplicationGroupName string + DesktopName string +} + +// NewDesktopID returns a new DesktopId struct +func NewDesktopID(subscriptionId string, resourceGroupName string, applicationGroupName string, desktopName string) DesktopId { + return DesktopId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ApplicationGroupName: applicationGroupName, + DesktopName: desktopName, + } +} + +// ParseDesktopID parses 'input' into a DesktopId +func ParseDesktopID(input string) (*DesktopId, error) { + parser := resourceids.NewParserFromResourceIdType(DesktopId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := DesktopId{} + + 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.ApplicationGroupName, ok = parsed.Parsed["applicationGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'applicationGroupName' was not found in the resource id %q", input) + } + + if id.DesktopName, ok = parsed.Parsed["desktopName"]; !ok { + return nil, fmt.Errorf("the segment 'desktopName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseDesktopIDInsensitively parses 'input' case-insensitively into a DesktopId +// note: this method should only be used for API response data and not user input +func ParseDesktopIDInsensitively(input string) (*DesktopId, error) { + parser := resourceids.NewParserFromResourceIdType(DesktopId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := DesktopId{} + + 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.ApplicationGroupName, ok = parsed.Parsed["applicationGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'applicationGroupName' was not found in the resource id %q", input) + } + + if id.DesktopName, ok = parsed.Parsed["desktopName"]; !ok { + return nil, fmt.Errorf("the segment 'desktopName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateDesktopID checks that 'input' can be parsed as a Desktop ID +func ValidateDesktopID(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 := ParseDesktopID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Desktop ID +func (id DesktopId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DesktopVirtualization/applicationGroups/%s/desktops/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ApplicationGroupName, id.DesktopName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Desktop ID +func (id DesktopId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftDesktopVirtualization", "Microsoft.DesktopVirtualization", "Microsoft.DesktopVirtualization"), + resourceids.StaticSegment("staticApplicationGroups", "applicationGroups", "applicationGroups"), + resourceids.UserSpecifiedSegment("applicationGroupName", "applicationGroupValue"), + resourceids.StaticSegment("staticDesktops", "desktops", "desktops"), + resourceids.UserSpecifiedSegment("desktopName", "desktopValue"), + } +} + +// String returns a human-readable description of this Desktop ID +func (id DesktopId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Application Group Name: %q", id.ApplicationGroupName), + fmt.Sprintf("Desktop Name: %q", id.DesktopName), + } + return fmt.Sprintf("Desktop (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/desktop/id_desktop_test.go b/resource-manager/desktopvirtualization/2022-02-10-preview/desktop/id_desktop_test.go new file mode 100644 index 00000000000..e5b24fb5f69 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/desktop/id_desktop_test.go @@ -0,0 +1,324 @@ +package desktop + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = DesktopId{} + +func TestNewDesktopID(t *testing.T) { + id := NewDesktopID("12345678-1234-9876-4563-123456789012", "example-resource-group", "applicationGroupValue", "desktopValue") + + 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.ApplicationGroupName != "applicationGroupValue" { + t.Fatalf("Expected %q but got %q for Segment 'ApplicationGroupName'", id.ApplicationGroupName, "applicationGroupValue") + } + + if id.DesktopName != "desktopValue" { + t.Fatalf("Expected %q but got %q for Segment 'DesktopName'", id.DesktopName, "desktopValue") + } +} + +func TestFormatDesktopID(t *testing.T) { + actual := NewDesktopID("12345678-1234-9876-4563-123456789012", "example-resource-group", "applicationGroupValue", "desktopValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue/desktops/desktopValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseDesktopID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DesktopId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue/desktops", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue/desktops/desktopValue", + Expected: &DesktopId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ApplicationGroupName: "applicationGroupValue", + DesktopName: "desktopValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue/desktops/desktopValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDesktopID(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.ApplicationGroupName != v.Expected.ApplicationGroupName { + t.Fatalf("Expected %q but got %q for ApplicationGroupName", v.Expected.ApplicationGroupName, actual.ApplicationGroupName) + } + + if actual.DesktopName != v.Expected.DesktopName { + t.Fatalf("Expected %q but got %q for DesktopName", v.Expected.DesktopName, actual.DesktopName) + } + + } +} + +func TestParseDesktopIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DesktopId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/aPpLiCaTiOnGrOuPs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/aPpLiCaTiOnGrOuPs/aPpLiCaTiOnGrOuPvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue/desktops", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/aPpLiCaTiOnGrOuPs/aPpLiCaTiOnGrOuPvAlUe/dEsKtOpS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue/desktops/desktopValue", + Expected: &DesktopId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ApplicationGroupName: "applicationGroupValue", + DesktopName: "desktopValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue/desktops/desktopValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/aPpLiCaTiOnGrOuPs/aPpLiCaTiOnGrOuPvAlUe/dEsKtOpS/dEsKtOpVaLuE", + Expected: &DesktopId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ApplicationGroupName: "aPpLiCaTiOnGrOuPvAlUe", + DesktopName: "dEsKtOpVaLuE", + }, + }, + { + // 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.dEsKtOpViRtUaLiZaTiOn/aPpLiCaTiOnGrOuPs/aPpLiCaTiOnGrOuPvAlUe/dEsKtOpS/dEsKtOpVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDesktopIDInsensitively(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.ApplicationGroupName != v.Expected.ApplicationGroupName { + t.Fatalf("Expected %q but got %q for ApplicationGroupName", v.Expected.ApplicationGroupName, actual.ApplicationGroupName) + } + + if actual.DesktopName != v.Expected.DesktopName { + t.Fatalf("Expected %q but got %q for DesktopName", v.Expected.DesktopName, actual.DesktopName) + } + + } +} + +func TestSegmentsForDesktopId(t *testing.T) { + segments := DesktopId{}.Segments() + if len(segments) == 0 { + t.Fatalf("DesktopId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/desktop/method_get_autorest.go b/resource-manager/desktopvirtualization/2022-02-10-preview/desktop/method_get_autorest.go new file mode 100644 index 00000000000..23658f0ebe2 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/desktop/method_get_autorest.go @@ -0,0 +1,67 @@ +package desktop + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *Desktop +} + +// Get ... +func (c DesktopClient) Get(ctx context.Context, id DesktopId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "desktop.DesktopClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "desktop.DesktopClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "desktop.DesktopClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c DesktopClient) preparerForGet(ctx context.Context, id DesktopId) (*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 DesktopClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/desktop/method_list_autorest.go b/resource-manager/desktopvirtualization/2022-02-10-preview/desktop/method_list_autorest.go new file mode 100644 index 00000000000..145ff8981dd --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/desktop/method_list_autorest.go @@ -0,0 +1,186 @@ +package desktop + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + Model *[]Desktop + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) +} + +type ListCompleteResult struct { + Items []Desktop +} + +func (r ListOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// List ... +func (c DesktopClient) List(ctx context.Context, id ApplicationGroupId) (resp ListOperationResponse, err error) { + req, err := c.preparerForList(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "desktop.DesktopClient", "List", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "desktop.DesktopClient", "List", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForList(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "desktop.DesktopClient", "List", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// ListComplete retrieves all of the results into a single object +func (c DesktopClient) ListComplete(ctx context.Context, id ApplicationGroupId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, DesktopOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c DesktopClient) ListCompleteMatchingPredicate(ctx context.Context, id ApplicationGroupId, predicate DesktopOperationPredicate) (resp ListCompleteResult, err error) { + items := make([]Desktop, 0) + + page, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListCompleteResult{ + Items: items, + } + return out, nil +} + +// preparerForList prepares the List request. +func (c DesktopClient) preparerForList(ctx context.Context, id ApplicationGroupId) (*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/desktops", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListWithNextLink prepares the List request with the given nextLink token. +func (c DesktopClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForList handles the response to the List request. The method always +// closes the http.Response Body. +func (c DesktopClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { + type page struct { + Values []Desktop `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { + req, err := c.preparerForListWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "desktop.DesktopClient", "List", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "desktop.DesktopClient", "List", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "desktop.DesktopClient", "List", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/desktop/method_update_autorest.go b/resource-manager/desktopvirtualization/2022-02-10-preview/desktop/method_update_autorest.go new file mode 100644 index 00000000000..60d6fece536 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/desktop/method_update_autorest.go @@ -0,0 +1,68 @@ +package desktop + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + HttpResponse *http.Response + Model *Desktop +} + +// Update ... +func (c DesktopClient) Update(ctx context.Context, id DesktopId, input DesktopPatch) (result UpdateOperationResponse, err error) { + req, err := c.preparerForUpdate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "desktop.DesktopClient", "Update", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "desktop.DesktopClient", "Update", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForUpdate(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "desktop.DesktopClient", "Update", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForUpdate prepares the Update request. +func (c DesktopClient) preparerForUpdate(ctx context.Context, id DesktopId, input DesktopPatch) (*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 DesktopClient) responderForUpdate(resp *http.Response) (result UpdateOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/desktop/model_desktop.go b/resource-manager/desktopvirtualization/2022-02-10-preview/desktop/model_desktop.go new file mode 100644 index 00000000000..6d41ecc215e --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/desktop/model_desktop.go @@ -0,0 +1,16 @@ +package desktop + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Desktop struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *DesktopProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/desktop/model_desktoppatch.go b/resource-manager/desktopvirtualization/2022-02-10-preview/desktop/model_desktoppatch.go new file mode 100644 index 00000000000..1d7d1672159 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/desktop/model_desktoppatch.go @@ -0,0 +1,9 @@ +package desktop + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DesktopPatch struct { + Properties *DesktopPatchProperties `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/desktop/model_desktoppatchproperties.go b/resource-manager/desktopvirtualization/2022-02-10-preview/desktop/model_desktoppatchproperties.go new file mode 100644 index 00000000000..40b1a4577e1 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/desktop/model_desktoppatchproperties.go @@ -0,0 +1,9 @@ +package desktop + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DesktopPatchProperties struct { + Description *string `json:"description,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/desktop/model_desktopproperties.go b/resource-manager/desktopvirtualization/2022-02-10-preview/desktop/model_desktopproperties.go new file mode 100644 index 00000000000..2d961ead46c --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/desktop/model_desktopproperties.go @@ -0,0 +1,12 @@ +package desktop + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DesktopProperties struct { + Description *string `json:"description,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + IconContent *string `json:"iconContent,omitempty"` + IconHash *string `json:"iconHash,omitempty"` + ObjectId *string `json:"objectId,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/desktop/predicates.go b/resource-manager/desktopvirtualization/2022-02-10-preview/desktop/predicates.go new file mode 100644 index 00000000000..f8bbb1e357f --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/desktop/predicates.go @@ -0,0 +1,24 @@ +package desktop + +type DesktopOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p DesktopOperationPredicate) Matches(input Desktop) bool { + + if p.Id != nil && (input.Id == nil && *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil && *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil && *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/desktop/version.go b/resource-manager/desktopvirtualization/2022-02-10-preview/desktop/version.go new file mode 100644 index 00000000000..c70db4ebaaf --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/desktop/version.go @@ -0,0 +1,12 @@ +package desktop + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2022-02-10-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/desktop/%s", defaultApiVersion) +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/client.go b/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/client.go new file mode 100644 index 00000000000..adce757bb86 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/client.go @@ -0,0 +1,18 @@ +package hostpool + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type HostPoolClient struct { + Client autorest.Client + baseUri string +} + +func NewHostPoolClientWithBaseURI(endpoint string) HostPoolClient { + return HostPoolClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/constants.go b/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/constants.go new file mode 100644 index 00000000000..71675bb1e37 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/constants.go @@ -0,0 +1,433 @@ +package hostpool + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DayOfWeek string + +const ( + DayOfWeekFriday DayOfWeek = "Friday" + DayOfWeekMonday DayOfWeek = "Monday" + DayOfWeekSaturday DayOfWeek = "Saturday" + DayOfWeekSunday DayOfWeek = "Sunday" + DayOfWeekThursday DayOfWeek = "Thursday" + DayOfWeekTuesday DayOfWeek = "Tuesday" + DayOfWeekWednesday DayOfWeek = "Wednesday" +) + +func PossibleValuesForDayOfWeek() []string { + return []string{ + string(DayOfWeekFriday), + string(DayOfWeekMonday), + string(DayOfWeekSaturday), + string(DayOfWeekSunday), + string(DayOfWeekThursday), + string(DayOfWeekTuesday), + string(DayOfWeekWednesday), + } +} + +func parseDayOfWeek(input string) (*DayOfWeek, error) { + vals := map[string]DayOfWeek{ + "friday": DayOfWeekFriday, + "monday": DayOfWeekMonday, + "saturday": DayOfWeekSaturday, + "sunday": DayOfWeekSunday, + "thursday": DayOfWeekThursday, + "tuesday": DayOfWeekTuesday, + "wednesday": DayOfWeekWednesday, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DayOfWeek(input) + return &out, nil +} + +type HostPoolType string + +const ( + HostPoolTypeBYODesktop HostPoolType = "BYODesktop" + HostPoolTypePersonal HostPoolType = "Personal" + HostPoolTypePooled HostPoolType = "Pooled" +) + +func PossibleValuesForHostPoolType() []string { + return []string{ + string(HostPoolTypeBYODesktop), + string(HostPoolTypePersonal), + string(HostPoolTypePooled), + } +} + +func parseHostPoolType(input string) (*HostPoolType, error) { + vals := map[string]HostPoolType{ + "byodesktop": HostPoolTypeBYODesktop, + "personal": HostPoolTypePersonal, + "pooled": HostPoolTypePooled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := HostPoolType(input) + return &out, nil +} + +type HostpoolPublicNetworkAccess string + +const ( + HostpoolPublicNetworkAccessDisabled HostpoolPublicNetworkAccess = "Disabled" + HostpoolPublicNetworkAccessEnabled HostpoolPublicNetworkAccess = "Enabled" + HostpoolPublicNetworkAccessEnabledForClientsOnly HostpoolPublicNetworkAccess = "EnabledForClientsOnly" + HostpoolPublicNetworkAccessEnabledForSessionHostsOnly HostpoolPublicNetworkAccess = "EnabledForSessionHostsOnly" +) + +func PossibleValuesForHostpoolPublicNetworkAccess() []string { + return []string{ + string(HostpoolPublicNetworkAccessDisabled), + string(HostpoolPublicNetworkAccessEnabled), + string(HostpoolPublicNetworkAccessEnabledForClientsOnly), + string(HostpoolPublicNetworkAccessEnabledForSessionHostsOnly), + } +} + +func parseHostpoolPublicNetworkAccess(input string) (*HostpoolPublicNetworkAccess, error) { + vals := map[string]HostpoolPublicNetworkAccess{ + "disabled": HostpoolPublicNetworkAccessDisabled, + "enabled": HostpoolPublicNetworkAccessEnabled, + "enabledforclientsonly": HostpoolPublicNetworkAccessEnabledForClientsOnly, + "enabledforsessionhostsonly": HostpoolPublicNetworkAccessEnabledForSessionHostsOnly, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := HostpoolPublicNetworkAccess(input) + return &out, nil +} + +type LoadBalancerType string + +const ( + LoadBalancerTypeBreadthFirst LoadBalancerType = "BreadthFirst" + LoadBalancerTypeDepthFirst LoadBalancerType = "DepthFirst" + LoadBalancerTypePersistent LoadBalancerType = "Persistent" +) + +func PossibleValuesForLoadBalancerType() []string { + return []string{ + string(LoadBalancerTypeBreadthFirst), + string(LoadBalancerTypeDepthFirst), + string(LoadBalancerTypePersistent), + } +} + +func parseLoadBalancerType(input string) (*LoadBalancerType, error) { + vals := map[string]LoadBalancerType{ + "breadthfirst": LoadBalancerTypeBreadthFirst, + "depthfirst": LoadBalancerTypeDepthFirst, + "persistent": LoadBalancerTypePersistent, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := LoadBalancerType(input) + return &out, nil +} + +type Operation string + +const ( + OperationComplete Operation = "Complete" + OperationHide Operation = "Hide" + OperationRevoke Operation = "Revoke" + OperationStart Operation = "Start" + OperationUnhide Operation = "Unhide" +) + +func PossibleValuesForOperation() []string { + return []string{ + string(OperationComplete), + string(OperationHide), + string(OperationRevoke), + string(OperationStart), + string(OperationUnhide), + } +} + +func parseOperation(input string) (*Operation, error) { + vals := map[string]Operation{ + "complete": OperationComplete, + "hide": OperationHide, + "revoke": OperationRevoke, + "start": OperationStart, + "unhide": OperationUnhide, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Operation(input) + return &out, nil +} + +type PersonalDesktopAssignmentType string + +const ( + PersonalDesktopAssignmentTypeAutomatic PersonalDesktopAssignmentType = "Automatic" + PersonalDesktopAssignmentTypeDirect PersonalDesktopAssignmentType = "Direct" +) + +func PossibleValuesForPersonalDesktopAssignmentType() []string { + return []string{ + string(PersonalDesktopAssignmentTypeAutomatic), + string(PersonalDesktopAssignmentTypeDirect), + } +} + +func parsePersonalDesktopAssignmentType(input string) (*PersonalDesktopAssignmentType, error) { + vals := map[string]PersonalDesktopAssignmentType{ + "automatic": PersonalDesktopAssignmentTypeAutomatic, + "direct": PersonalDesktopAssignmentTypeDirect, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PersonalDesktopAssignmentType(input) + return &out, nil +} + +type PreferredAppGroupType string + +const ( + PreferredAppGroupTypeDesktop PreferredAppGroupType = "Desktop" + PreferredAppGroupTypeNone PreferredAppGroupType = "None" + PreferredAppGroupTypeRailApplications PreferredAppGroupType = "RailApplications" +) + +func PossibleValuesForPreferredAppGroupType() []string { + return []string{ + string(PreferredAppGroupTypeDesktop), + string(PreferredAppGroupTypeNone), + string(PreferredAppGroupTypeRailApplications), + } +} + +func parsePreferredAppGroupType(input string) (*PreferredAppGroupType, error) { + vals := map[string]PreferredAppGroupType{ + "desktop": PreferredAppGroupTypeDesktop, + "none": PreferredAppGroupTypeNone, + "railapplications": PreferredAppGroupTypeRailApplications, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PreferredAppGroupType(input) + return &out, nil +} + +type PrivateEndpointConnectionProvisioningState string + +const ( + PrivateEndpointConnectionProvisioningStateCreating PrivateEndpointConnectionProvisioningState = "Creating" + PrivateEndpointConnectionProvisioningStateDeleting PrivateEndpointConnectionProvisioningState = "Deleting" + PrivateEndpointConnectionProvisioningStateFailed PrivateEndpointConnectionProvisioningState = "Failed" + PrivateEndpointConnectionProvisioningStateSucceeded PrivateEndpointConnectionProvisioningState = "Succeeded" +) + +func PossibleValuesForPrivateEndpointConnectionProvisioningState() []string { + return []string{ + string(PrivateEndpointConnectionProvisioningStateCreating), + string(PrivateEndpointConnectionProvisioningStateDeleting), + string(PrivateEndpointConnectionProvisioningStateFailed), + string(PrivateEndpointConnectionProvisioningStateSucceeded), + } +} + +func parsePrivateEndpointConnectionProvisioningState(input string) (*PrivateEndpointConnectionProvisioningState, error) { + vals := map[string]PrivateEndpointConnectionProvisioningState{ + "creating": PrivateEndpointConnectionProvisioningStateCreating, + "deleting": PrivateEndpointConnectionProvisioningStateDeleting, + "failed": PrivateEndpointConnectionProvisioningStateFailed, + "succeeded": PrivateEndpointConnectionProvisioningStateSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PrivateEndpointConnectionProvisioningState(input) + return &out, nil +} + +type PrivateEndpointServiceConnectionStatus string + +const ( + PrivateEndpointServiceConnectionStatusApproved PrivateEndpointServiceConnectionStatus = "Approved" + PrivateEndpointServiceConnectionStatusPending PrivateEndpointServiceConnectionStatus = "Pending" + PrivateEndpointServiceConnectionStatusRejected PrivateEndpointServiceConnectionStatus = "Rejected" +) + +func PossibleValuesForPrivateEndpointServiceConnectionStatus() []string { + return []string{ + string(PrivateEndpointServiceConnectionStatusApproved), + string(PrivateEndpointServiceConnectionStatusPending), + string(PrivateEndpointServiceConnectionStatusRejected), + } +} + +func parsePrivateEndpointServiceConnectionStatus(input string) (*PrivateEndpointServiceConnectionStatus, error) { + vals := map[string]PrivateEndpointServiceConnectionStatus{ + "approved": PrivateEndpointServiceConnectionStatusApproved, + "pending": PrivateEndpointServiceConnectionStatusPending, + "rejected": PrivateEndpointServiceConnectionStatusRejected, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PrivateEndpointServiceConnectionStatus(input) + return &out, nil +} + +type RegistrationTokenOperation string + +const ( + RegistrationTokenOperationDelete RegistrationTokenOperation = "Delete" + RegistrationTokenOperationNone RegistrationTokenOperation = "None" + RegistrationTokenOperationUpdate RegistrationTokenOperation = "Update" +) + +func PossibleValuesForRegistrationTokenOperation() []string { + return []string{ + string(RegistrationTokenOperationDelete), + string(RegistrationTokenOperationNone), + string(RegistrationTokenOperationUpdate), + } +} + +func parseRegistrationTokenOperation(input string) (*RegistrationTokenOperation, error) { + vals := map[string]RegistrationTokenOperation{ + "delete": RegistrationTokenOperationDelete, + "none": RegistrationTokenOperationNone, + "update": RegistrationTokenOperationUpdate, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RegistrationTokenOperation(input) + return &out, nil +} + +type SSOSecretType string + +const ( + SSOSecretTypeCertificate SSOSecretType = "Certificate" + SSOSecretTypeCertificateInKeyVault SSOSecretType = "CertificateInKeyVault" + SSOSecretTypeSharedKey SSOSecretType = "SharedKey" + SSOSecretTypeSharedKeyInKeyVault SSOSecretType = "SharedKeyInKeyVault" +) + +func PossibleValuesForSSOSecretType() []string { + return []string{ + string(SSOSecretTypeCertificate), + string(SSOSecretTypeCertificateInKeyVault), + string(SSOSecretTypeSharedKey), + string(SSOSecretTypeSharedKeyInKeyVault), + } +} + +func parseSSOSecretType(input string) (*SSOSecretType, error) { + vals := map[string]SSOSecretType{ + "certificate": SSOSecretTypeCertificate, + "certificateinkeyvault": SSOSecretTypeCertificateInKeyVault, + "sharedkey": SSOSecretTypeSharedKey, + "sharedkeyinkeyvault": SSOSecretTypeSharedKeyInKeyVault, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SSOSecretType(input) + return &out, nil +} + +type SessionHostComponentUpdateType string + +const ( + SessionHostComponentUpdateTypeDefault SessionHostComponentUpdateType = "Default" + SessionHostComponentUpdateTypeScheduled SessionHostComponentUpdateType = "Scheduled" +) + +func PossibleValuesForSessionHostComponentUpdateType() []string { + return []string{ + string(SessionHostComponentUpdateTypeDefault), + string(SessionHostComponentUpdateTypeScheduled), + } +} + +func parseSessionHostComponentUpdateType(input string) (*SessionHostComponentUpdateType, error) { + vals := map[string]SessionHostComponentUpdateType{ + "default": SessionHostComponentUpdateTypeDefault, + "scheduled": SessionHostComponentUpdateTypeScheduled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SessionHostComponentUpdateType(input) + return &out, nil +} + +type SkuTier string + +const ( + SkuTierBasic SkuTier = "Basic" + SkuTierFree SkuTier = "Free" + SkuTierPremium SkuTier = "Premium" + SkuTierStandard SkuTier = "Standard" +) + +func PossibleValuesForSkuTier() []string { + return []string{ + string(SkuTierBasic), + string(SkuTierFree), + string(SkuTierPremium), + string(SkuTierStandard), + } +} + +func parseSkuTier(input string) (*SkuTier, error) { + vals := map[string]SkuTier{ + "basic": SkuTierBasic, + "free": SkuTierFree, + "premium": SkuTierPremium, + "standard": SkuTierStandard, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SkuTier(input) + return &out, nil +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/id_hostpool.go b/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/id_hostpool.go new file mode 100644 index 00000000000..61c82943024 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/id_hostpool.go @@ -0,0 +1,124 @@ +package hostpool + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = HostPoolId{} + +// HostPoolId is a struct representing the Resource ID for a Host Pool +type HostPoolId struct { + SubscriptionId string + ResourceGroupName string + HostPoolName string +} + +// NewHostPoolID returns a new HostPoolId struct +func NewHostPoolID(subscriptionId string, resourceGroupName string, hostPoolName string) HostPoolId { + return HostPoolId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + HostPoolName: hostPoolName, + } +} + +// ParseHostPoolID parses 'input' into a HostPoolId +func ParseHostPoolID(input string) (*HostPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(HostPoolId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := HostPoolId{} + + 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.HostPoolName, ok = parsed.Parsed["hostPoolName"]; !ok { + return nil, fmt.Errorf("the segment 'hostPoolName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseHostPoolIDInsensitively parses 'input' case-insensitively into a HostPoolId +// note: this method should only be used for API response data and not user input +func ParseHostPoolIDInsensitively(input string) (*HostPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(HostPoolId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := HostPoolId{} + + 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.HostPoolName, ok = parsed.Parsed["hostPoolName"]; !ok { + return nil, fmt.Errorf("the segment 'hostPoolName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateHostPoolID checks that 'input' can be parsed as a Host Pool ID +func ValidateHostPoolID(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 := ParseHostPoolID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Host Pool ID +func (id HostPoolId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DesktopVirtualization/hostPools/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.HostPoolName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Host Pool ID +func (id HostPoolId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftDesktopVirtualization", "Microsoft.DesktopVirtualization", "Microsoft.DesktopVirtualization"), + resourceids.StaticSegment("staticHostPools", "hostPools", "hostPools"), + resourceids.UserSpecifiedSegment("hostPoolName", "hostPoolValue"), + } +} + +// String returns a human-readable description of this Host Pool ID +func (id HostPoolId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Host Pool Name: %q", id.HostPoolName), + } + return fmt.Sprintf("Host Pool (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/id_hostpool_test.go b/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/id_hostpool_test.go new file mode 100644 index 00000000000..fb6c4a509c4 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/id_hostpool_test.go @@ -0,0 +1,279 @@ +package hostpool + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = HostPoolId{} + +func TestNewHostPoolID(t *testing.T) { + id := NewHostPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "hostPoolValue") + + 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.HostPoolName != "hostPoolValue" { + t.Fatalf("Expected %q but got %q for Segment 'HostPoolName'", id.HostPoolName, "hostPoolValue") + } +} + +func TestFormatHostPoolID(t *testing.T) { + actual := NewHostPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "hostPoolValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseHostPoolID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *HostPoolId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue", + Expected: &HostPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + HostPoolName: "hostPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseHostPoolID(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.HostPoolName != v.Expected.HostPoolName { + t.Fatalf("Expected %q but got %q for HostPoolName", v.Expected.HostPoolName, actual.HostPoolName) + } + + } +} + +func TestParseHostPoolIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *HostPoolId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue", + Expected: &HostPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + HostPoolName: "hostPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe", + Expected: &HostPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + HostPoolName: "hOsTpOoLvAlUe", + }, + }, + { + // 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.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseHostPoolIDInsensitively(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.HostPoolName != v.Expected.HostPoolName { + t.Fatalf("Expected %q but got %q for HostPoolName", v.Expected.HostPoolName, actual.HostPoolName) + } + + } +} + +func TestSegmentsForHostPoolId(t *testing.T) { + segments := HostPoolId{}.Segments() + if len(segments) == 0 { + t.Fatalf("HostPoolId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/method_createorupdate_autorest.go b/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/method_createorupdate_autorest.go new file mode 100644 index 00000000000..6ba8c24c258 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/method_createorupdate_autorest.go @@ -0,0 +1,68 @@ +package hostpool + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + Model *HostPool +} + +// CreateOrUpdate ... +func (c HostPoolClient) CreateOrUpdate(ctx context.Context, id HostPoolId, input HostPool) (result CreateOrUpdateOperationResponse, err error) { + req, err := c.preparerForCreateOrUpdate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "hostpool.HostPoolClient", "CreateOrUpdate", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "hostpool.HostPoolClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForCreateOrUpdate(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "hostpool.HostPoolClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForCreateOrUpdate prepares the CreateOrUpdate request. +func (c HostPoolClient) preparerForCreateOrUpdate(ctx context.Context, id HostPoolId, input HostPool) (*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)) +} + +// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always +// closes the http.Response Body. +func (c HostPoolClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/method_delete_autorest.go b/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/method_delete_autorest.go new file mode 100644 index 00000000000..4483478b8e4 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/method_delete_autorest.go @@ -0,0 +1,94 @@ +package hostpool + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response +} + +type DeleteOperationOptions struct { + Force *bool +} + +func DefaultDeleteOperationOptions() DeleteOperationOptions { + return DeleteOperationOptions{} +} + +func (o DeleteOperationOptions) toHeaders() map[string]interface{} { + out := make(map[string]interface{}) + + return out +} + +func (o DeleteOperationOptions) toQueryString() map[string]interface{} { + out := make(map[string]interface{}) + + if o.Force != nil { + out["force"] = *o.Force + } + + return out +} + +// Delete ... +func (c HostPoolClient) Delete(ctx context.Context, id HostPoolId, options DeleteOperationOptions) (result DeleteOperationResponse, err error) { + req, err := c.preparerForDelete(ctx, id, options) + if err != nil { + err = autorest.NewErrorWithError(err, "hostpool.HostPoolClient", "Delete", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "hostpool.HostPoolClient", "Delete", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForDelete(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "hostpool.HostPoolClient", "Delete", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForDelete prepares the Delete request. +func (c HostPoolClient) preparerForDelete(ctx context.Context, id HostPoolId, options DeleteOperationOptions) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + for k, v := range options.toQueryString() { + queryParameters[k] = autorest.Encode("query", v) + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsDelete(), + autorest.WithBaseURL(c.baseUri), + autorest.WithHeaders(options.toHeaders()), + 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 HostPoolClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/method_get_autorest.go b/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/method_get_autorest.go new file mode 100644 index 00000000000..c442f70a286 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/method_get_autorest.go @@ -0,0 +1,67 @@ +package hostpool + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *HostPool +} + +// Get ... +func (c HostPoolClient) Get(ctx context.Context, id HostPoolId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "hostpool.HostPoolClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "hostpool.HostPoolClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "hostpool.HostPoolClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c HostPoolClient) preparerForGet(ctx context.Context, id HostPoolId) (*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 HostPoolClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/method_list_autorest.go b/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/method_list_autorest.go new file mode 100644 index 00000000000..d776af10f11 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/method_list_autorest.go @@ -0,0 +1,187 @@ +package hostpool + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + Model *[]HostPool + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) +} + +type ListCompleteResult struct { + Items []HostPool +} + +func (r ListOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// List ... +func (c HostPoolClient) List(ctx context.Context, id commonids.SubscriptionId) (resp ListOperationResponse, err error) { + req, err := c.preparerForList(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "hostpool.HostPoolClient", "List", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "hostpool.HostPoolClient", "List", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForList(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "hostpool.HostPoolClient", "List", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// ListComplete retrieves all of the results into a single object +func (c HostPoolClient) ListComplete(ctx context.Context, id commonids.SubscriptionId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, HostPoolOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c HostPoolClient) ListCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate HostPoolOperationPredicate) (resp ListCompleteResult, err error) { + items := make([]HostPool, 0) + + page, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListCompleteResult{ + Items: items, + } + return out, nil +} + +// preparerForList prepares the List request. +func (c HostPoolClient) preparerForList(ctx context.Context, id commonids.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.DesktopVirtualization/hostPools", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListWithNextLink prepares the List request with the given nextLink token. +func (c HostPoolClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForList handles the response to the List request. The method always +// closes the http.Response Body. +func (c HostPoolClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { + type page struct { + Values []HostPool `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { + req, err := c.preparerForListWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "hostpool.HostPoolClient", "List", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "hostpool.HostPoolClient", "List", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "hostpool.HostPoolClient", "List", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/method_listbyresourcegroup_autorest.go b/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/method_listbyresourcegroup_autorest.go new file mode 100644 index 00000000000..10e2fdbcb63 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/method_listbyresourcegroup_autorest.go @@ -0,0 +1,187 @@ +package hostpool + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByResourceGroupOperationResponse struct { + HttpResponse *http.Response + Model *[]HostPool + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListByResourceGroupOperationResponse, error) +} + +type ListByResourceGroupCompleteResult struct { + Items []HostPool +} + +func (r ListByResourceGroupOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListByResourceGroupOperationResponse) LoadMore(ctx context.Context) (resp ListByResourceGroupOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// ListByResourceGroup ... +func (c HostPoolClient) ListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (resp ListByResourceGroupOperationResponse, err error) { + req, err := c.preparerForListByResourceGroup(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "hostpool.HostPoolClient", "ListByResourceGroup", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "hostpool.HostPoolClient", "ListByResourceGroup", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForListByResourceGroup(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "hostpool.HostPoolClient", "ListByResourceGroup", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// ListByResourceGroupComplete retrieves all of the results into a single object +func (c HostPoolClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (ListByResourceGroupCompleteResult, error) { + return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, HostPoolOperationPredicate{}) +} + +// ListByResourceGroupCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c HostPoolClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate HostPoolOperationPredicate) (resp ListByResourceGroupCompleteResult, err error) { + items := make([]HostPool, 0) + + page, err := c.ListByResourceGroup(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListByResourceGroupCompleteResult{ + Items: items, + } + return out, nil +} + +// preparerForListByResourceGroup prepares the ListByResourceGroup request. +func (c HostPoolClient) preparerForListByResourceGroup(ctx context.Context, id commonids.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.DesktopVirtualization/hostPools", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListByResourceGroupWithNextLink prepares the ListByResourceGroup request with the given nextLink token. +func (c HostPoolClient) preparerForListByResourceGroupWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForListByResourceGroup handles the response to the ListByResourceGroup request. The method always +// closes the http.Response Body. +func (c HostPoolClient) responderForListByResourceGroup(resp *http.Response) (result ListByResourceGroupOperationResponse, err error) { + type page struct { + Values []HostPool `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListByResourceGroupOperationResponse, err error) { + req, err := c.preparerForListByResourceGroupWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "hostpool.HostPoolClient", "ListByResourceGroup", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "hostpool.HostPoolClient", "ListByResourceGroup", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForListByResourceGroup(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "hostpool.HostPoolClient", "ListByResourceGroup", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/method_retrieveregistrationtoken_autorest.go b/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/method_retrieveregistrationtoken_autorest.go new file mode 100644 index 00000000000..9e3317f1807 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/method_retrieveregistrationtoken_autorest.go @@ -0,0 +1,68 @@ +package hostpool + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RetrieveRegistrationTokenOperationResponse struct { + HttpResponse *http.Response + Model *RegistrationInfo +} + +// RetrieveRegistrationToken ... +func (c HostPoolClient) RetrieveRegistrationToken(ctx context.Context, id HostPoolId) (result RetrieveRegistrationTokenOperationResponse, err error) { + req, err := c.preparerForRetrieveRegistrationToken(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "hostpool.HostPoolClient", "RetrieveRegistrationToken", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "hostpool.HostPoolClient", "RetrieveRegistrationToken", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForRetrieveRegistrationToken(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "hostpool.HostPoolClient", "RetrieveRegistrationToken", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForRetrieveRegistrationToken prepares the RetrieveRegistrationToken request. +func (c HostPoolClient) preparerForRetrieveRegistrationToken(ctx context.Context, id HostPoolId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/retrieveRegistrationToken", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForRetrieveRegistrationToken handles the response to the RetrieveRegistrationToken request. The method always +// closes the http.Response Body. +func (c HostPoolClient) responderForRetrieveRegistrationToken(resp *http.Response) (result RetrieveRegistrationTokenOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/method_update_autorest.go b/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/method_update_autorest.go new file mode 100644 index 00000000000..9de04a30cfc --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/method_update_autorest.go @@ -0,0 +1,68 @@ +package hostpool + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + HttpResponse *http.Response + Model *HostPool +} + +// Update ... +func (c HostPoolClient) Update(ctx context.Context, id HostPoolId, input HostPoolPatch) (result UpdateOperationResponse, err error) { + req, err := c.preparerForUpdate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "hostpool.HostPoolClient", "Update", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "hostpool.HostPoolClient", "Update", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForUpdate(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "hostpool.HostPoolClient", "Update", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForUpdate prepares the Update request. +func (c HostPoolClient) preparerForUpdate(ctx context.Context, id HostPoolId, input HostPoolPatch) (*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 HostPoolClient) responderForUpdate(resp *http.Response) (result UpdateOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/model_agentupdatepatchproperties.go b/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/model_agentupdatepatchproperties.go new file mode 100644 index 00000000000..7656dc349a5 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/model_agentupdatepatchproperties.go @@ -0,0 +1,11 @@ +package hostpool + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AgentUpdatePatchProperties struct { + MaintenanceWindowTimeZone *string `json:"maintenanceWindowTimeZone,omitempty"` + MaintenanceWindows *[]MaintenanceWindowPatchProperties `json:"maintenanceWindows,omitempty"` + Type *SessionHostComponentUpdateType `json:"type,omitempty"` + UseSessionHostLocalTime *bool `json:"useSessionHostLocalTime,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/model_agentupdateproperties.go b/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/model_agentupdateproperties.go new file mode 100644 index 00000000000..76ca245b1c8 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/model_agentupdateproperties.go @@ -0,0 +1,11 @@ +package hostpool + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AgentUpdateProperties struct { + MaintenanceWindowTimeZone *string `json:"maintenanceWindowTimeZone,omitempty"` + MaintenanceWindows *[]MaintenanceWindowProperties `json:"maintenanceWindows,omitempty"` + Type *SessionHostComponentUpdateType `json:"type,omitempty"` + UseSessionHostLocalTime *bool `json:"useSessionHostLocalTime,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/model_hostpool.go b/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/model_hostpool.go new file mode 100644 index 00000000000..e3d98e6ba0c --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/model_hostpool.go @@ -0,0 +1,25 @@ +package hostpool + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/identity" + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type HostPool struct { + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Identity *identity.SystemAssigned `json:"identity,omitempty"` + Kind *string `json:"kind,omitempty"` + Location *string `json:"location,omitempty"` + ManagedBy *string `json:"managedBy,omitempty"` + Name *string `json:"name,omitempty"` + Plan *Plan `json:"plan,omitempty"` + Properties HostPoolProperties `json:"properties"` + Sku *Sku `json:"sku,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/model_hostpoolpatch.go b/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/model_hostpoolpatch.go new file mode 100644 index 00000000000..6895ce28a7d --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/model_hostpoolpatch.go @@ -0,0 +1,12 @@ +package hostpool + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type HostPoolPatch struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *HostPoolPatchProperties `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/model_hostpoolpatchproperties.go b/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/model_hostpoolpatchproperties.go new file mode 100644 index 00000000000..53143efdbac --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/model_hostpoolpatchproperties.go @@ -0,0 +1,25 @@ +package hostpool + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type HostPoolPatchProperties struct { + AgentUpdate *AgentUpdatePatchProperties `json:"agentUpdate,omitempty"` + CustomRdpProperty *string `json:"customRdpProperty,omitempty"` + Description *string `json:"description,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + LoadBalancerType *LoadBalancerType `json:"loadBalancerType,omitempty"` + MaxSessionLimit *int64 `json:"maxSessionLimit,omitempty"` + PersonalDesktopAssignmentType *PersonalDesktopAssignmentType `json:"personalDesktopAssignmentType,omitempty"` + PreferredAppGroupType *PreferredAppGroupType `json:"preferredAppGroupType,omitempty"` + PublicNetworkAccess *HostpoolPublicNetworkAccess `json:"publicNetworkAccess,omitempty"` + RegistrationInfo *RegistrationInfoPatch `json:"registrationInfo,omitempty"` + Ring *int64 `json:"ring,omitempty"` + SsoClientId *string `json:"ssoClientId,omitempty"` + SsoClientSecretKeyVaultPath *string `json:"ssoClientSecretKeyVaultPath,omitempty"` + SsoSecretType *SSOSecretType `json:"ssoSecretType,omitempty"` + SsoadfsAuthority *string `json:"ssoadfsAuthority,omitempty"` + StartVMOnConnect *bool `json:"startVMOnConnect,omitempty"` + ValidationEnvironment *bool `json:"validationEnvironment,omitempty"` + VmTemplate *string `json:"vmTemplate,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/model_hostpoolproperties.go b/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/model_hostpoolproperties.go new file mode 100644 index 00000000000..22d8bc06955 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/model_hostpoolproperties.go @@ -0,0 +1,31 @@ +package hostpool + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type HostPoolProperties struct { + AgentUpdate *AgentUpdateProperties `json:"agentUpdate,omitempty"` + ApplicationGroupReferences *[]string `json:"applicationGroupReferences,omitempty"` + CloudPcResource *bool `json:"cloudPcResource,omitempty"` + CustomRdpProperty *string `json:"customRdpProperty,omitempty"` + Description *string `json:"description,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + HostPoolType HostPoolType `json:"hostPoolType"` + LoadBalancerType LoadBalancerType `json:"loadBalancerType"` + MaxSessionLimit *int64 `json:"maxSessionLimit,omitempty"` + MigrationRequest *MigrationRequestProperties `json:"migrationRequest,omitempty"` + ObjectId *string `json:"objectId,omitempty"` + PersonalDesktopAssignmentType *PersonalDesktopAssignmentType `json:"personalDesktopAssignmentType,omitempty"` + PreferredAppGroupType PreferredAppGroupType `json:"preferredAppGroupType"` + PrivateEndpointConnections *[]PrivateEndpointConnection `json:"privateEndpointConnections,omitempty"` + PublicNetworkAccess *HostpoolPublicNetworkAccess `json:"publicNetworkAccess,omitempty"` + RegistrationInfo *RegistrationInfo `json:"registrationInfo,omitempty"` + Ring *int64 `json:"ring,omitempty"` + SsoClientId *string `json:"ssoClientId,omitempty"` + SsoClientSecretKeyVaultPath *string `json:"ssoClientSecretKeyVaultPath,omitempty"` + SsoSecretType *SSOSecretType `json:"ssoSecretType,omitempty"` + SsoadfsAuthority *string `json:"ssoadfsAuthority,omitempty"` + StartVMOnConnect *bool `json:"startVMOnConnect,omitempty"` + ValidationEnvironment *bool `json:"validationEnvironment,omitempty"` + VmTemplate *string `json:"vmTemplate,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/model_maintenancewindowpatchproperties.go b/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/model_maintenancewindowpatchproperties.go new file mode 100644 index 00000000000..543fa9f8df4 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/model_maintenancewindowpatchproperties.go @@ -0,0 +1,9 @@ +package hostpool + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MaintenanceWindowPatchProperties struct { + DayOfWeek *DayOfWeek `json:"dayOfWeek,omitempty"` + Hour *int64 `json:"hour,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/model_maintenancewindowproperties.go b/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/model_maintenancewindowproperties.go new file mode 100644 index 00000000000..5e64a28986d --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/model_maintenancewindowproperties.go @@ -0,0 +1,9 @@ +package hostpool + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MaintenanceWindowProperties struct { + DayOfWeek *DayOfWeek `json:"dayOfWeek,omitempty"` + Hour *int64 `json:"hour,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/model_migrationrequestproperties.go b/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/model_migrationrequestproperties.go new file mode 100644 index 00000000000..2f6b968453d --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/model_migrationrequestproperties.go @@ -0,0 +1,9 @@ +package hostpool + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MigrationRequestProperties struct { + MigrationPath *string `json:"migrationPath,omitempty"` + Operation *Operation `json:"operation,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/model_plan.go b/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/model_plan.go new file mode 100644 index 00000000000..f81691c1b9a --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/model_plan.go @@ -0,0 +1,12 @@ +package hostpool + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Plan struct { + Name string `json:"name"` + Product string `json:"product"` + PromotionCode *string `json:"promotionCode,omitempty"` + Publisher string `json:"publisher"` + Version *string `json:"version,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/model_privateendpoint.go b/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/model_privateendpoint.go new file mode 100644 index 00000000000..43cd81d27a9 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/model_privateendpoint.go @@ -0,0 +1,8 @@ +package hostpool + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpoint struct { + Id *string `json:"id,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/model_privateendpointconnection.go b/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/model_privateendpointconnection.go new file mode 100644 index 00000000000..723ccff3904 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/model_privateendpointconnection.go @@ -0,0 +1,11 @@ +package hostpool + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnection struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PrivateEndpointConnectionProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/model_privateendpointconnectionproperties.go b/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/model_privateendpointconnectionproperties.go new file mode 100644 index 00000000000..afc75e86d71 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/model_privateendpointconnectionproperties.go @@ -0,0 +1,10 @@ +package hostpool + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionProperties struct { + PrivateEndpoint *PrivateEndpoint `json:"privateEndpoint,omitempty"` + PrivateLinkServiceConnectionState PrivateLinkServiceConnectionState `json:"privateLinkServiceConnectionState"` + ProvisioningState *PrivateEndpointConnectionProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/model_privatelinkserviceconnectionstate.go b/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/model_privatelinkserviceconnectionstate.go new file mode 100644 index 00000000000..b6a202ccf34 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/model_privatelinkserviceconnectionstate.go @@ -0,0 +1,10 @@ +package hostpool + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkServiceConnectionState struct { + ActionsRequired *string `json:"actionsRequired,omitempty"` + Description *string `json:"description,omitempty"` + Status *PrivateEndpointServiceConnectionStatus `json:"status,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/model_registrationinfo.go b/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/model_registrationinfo.go new file mode 100644 index 00000000000..ed356c7e596 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/model_registrationinfo.go @@ -0,0 +1,28 @@ +package hostpool + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RegistrationInfo struct { + ExpirationTime *string `json:"expirationTime,omitempty"` + RegistrationTokenOperation *RegistrationTokenOperation `json:"registrationTokenOperation,omitempty"` + Token *string `json:"token,omitempty"` +} + +func (o *RegistrationInfo) GetExpirationTimeAsTime() (*time.Time, error) { + if o.ExpirationTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ExpirationTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *RegistrationInfo) SetExpirationTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ExpirationTime = &formatted +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/model_registrationinfopatch.go b/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/model_registrationinfopatch.go new file mode 100644 index 00000000000..7340343045e --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/model_registrationinfopatch.go @@ -0,0 +1,27 @@ +package hostpool + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RegistrationInfoPatch struct { + ExpirationTime *string `json:"expirationTime,omitempty"` + RegistrationTokenOperation *RegistrationTokenOperation `json:"registrationTokenOperation,omitempty"` +} + +func (o *RegistrationInfoPatch) GetExpirationTimeAsTime() (*time.Time, error) { + if o.ExpirationTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ExpirationTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *RegistrationInfoPatch) SetExpirationTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ExpirationTime = &formatted +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/model_sku.go b/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/model_sku.go new file mode 100644 index 00000000000..26583f4fcea --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/model_sku.go @@ -0,0 +1,12 @@ +package hostpool + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Sku struct { + Capacity *int64 `json:"capacity,omitempty"` + Family *string `json:"family,omitempty"` + Name string `json:"name"` + Size *string `json:"size,omitempty"` + Tier *SkuTier `json:"tier,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/predicates.go b/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/predicates.go new file mode 100644 index 00000000000..27e04add212 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/predicates.go @@ -0,0 +1,44 @@ +package hostpool + +type HostPoolOperationPredicate struct { + Etag *string + Id *string + Kind *string + Location *string + ManagedBy *string + Name *string + Type *string +} + +func (p HostPoolOperationPredicate) Matches(input HostPool) bool { + + if p.Etag != nil && (input.Etag == nil && *p.Etag != *input.Etag) { + return false + } + + if p.Id != nil && (input.Id == nil && *p.Id != *input.Id) { + return false + } + + if p.Kind != nil && (input.Kind == nil && *p.Kind != *input.Kind) { + return false + } + + if p.Location != nil && (input.Location == nil && *p.Location != *input.Location) { + return false + } + + if p.ManagedBy != nil && (input.ManagedBy == nil && *p.ManagedBy != *input.ManagedBy) { + return false + } + + if p.Name != nil && (input.Name == nil && *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil && *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/version.go b/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/version.go new file mode 100644 index 00000000000..9bfcfbec469 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool/version.go @@ -0,0 +1,12 @@ +package hostpool + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2022-02-10-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/hostpool/%s", defaultApiVersion) +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/msiximage/client.go b/resource-manager/desktopvirtualization/2022-02-10-preview/msiximage/client.go new file mode 100644 index 00000000000..58c630f191a --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/msiximage/client.go @@ -0,0 +1,18 @@ +package msiximage + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MsixImageClient struct { + Client autorest.Client + baseUri string +} + +func NewMsixImageClientWithBaseURI(endpoint string) MsixImageClient { + return MsixImageClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/msiximage/id_hostpool.go b/resource-manager/desktopvirtualization/2022-02-10-preview/msiximage/id_hostpool.go new file mode 100644 index 00000000000..f1e2177bd07 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/msiximage/id_hostpool.go @@ -0,0 +1,124 @@ +package msiximage + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = HostPoolId{} + +// HostPoolId is a struct representing the Resource ID for a Host Pool +type HostPoolId struct { + SubscriptionId string + ResourceGroupName string + HostPoolName string +} + +// NewHostPoolID returns a new HostPoolId struct +func NewHostPoolID(subscriptionId string, resourceGroupName string, hostPoolName string) HostPoolId { + return HostPoolId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + HostPoolName: hostPoolName, + } +} + +// ParseHostPoolID parses 'input' into a HostPoolId +func ParseHostPoolID(input string) (*HostPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(HostPoolId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := HostPoolId{} + + 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.HostPoolName, ok = parsed.Parsed["hostPoolName"]; !ok { + return nil, fmt.Errorf("the segment 'hostPoolName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseHostPoolIDInsensitively parses 'input' case-insensitively into a HostPoolId +// note: this method should only be used for API response data and not user input +func ParseHostPoolIDInsensitively(input string) (*HostPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(HostPoolId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := HostPoolId{} + + 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.HostPoolName, ok = parsed.Parsed["hostPoolName"]; !ok { + return nil, fmt.Errorf("the segment 'hostPoolName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateHostPoolID checks that 'input' can be parsed as a Host Pool ID +func ValidateHostPoolID(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 := ParseHostPoolID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Host Pool ID +func (id HostPoolId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DesktopVirtualization/hostPools/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.HostPoolName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Host Pool ID +func (id HostPoolId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftDesktopVirtualization", "Microsoft.DesktopVirtualization", "Microsoft.DesktopVirtualization"), + resourceids.StaticSegment("staticHostPools", "hostPools", "hostPools"), + resourceids.UserSpecifiedSegment("hostPoolName", "hostPoolValue"), + } +} + +// String returns a human-readable description of this Host Pool ID +func (id HostPoolId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Host Pool Name: %q", id.HostPoolName), + } + return fmt.Sprintf("Host Pool (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/msiximage/id_hostpool_test.go b/resource-manager/desktopvirtualization/2022-02-10-preview/msiximage/id_hostpool_test.go new file mode 100644 index 00000000000..15fa27cd2cd --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/msiximage/id_hostpool_test.go @@ -0,0 +1,279 @@ +package msiximage + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = HostPoolId{} + +func TestNewHostPoolID(t *testing.T) { + id := NewHostPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "hostPoolValue") + + 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.HostPoolName != "hostPoolValue" { + t.Fatalf("Expected %q but got %q for Segment 'HostPoolName'", id.HostPoolName, "hostPoolValue") + } +} + +func TestFormatHostPoolID(t *testing.T) { + actual := NewHostPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "hostPoolValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseHostPoolID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *HostPoolId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue", + Expected: &HostPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + HostPoolName: "hostPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseHostPoolID(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.HostPoolName != v.Expected.HostPoolName { + t.Fatalf("Expected %q but got %q for HostPoolName", v.Expected.HostPoolName, actual.HostPoolName) + } + + } +} + +func TestParseHostPoolIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *HostPoolId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue", + Expected: &HostPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + HostPoolName: "hostPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe", + Expected: &HostPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + HostPoolName: "hOsTpOoLvAlUe", + }, + }, + { + // 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.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseHostPoolIDInsensitively(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.HostPoolName != v.Expected.HostPoolName { + t.Fatalf("Expected %q but got %q for HostPoolName", v.Expected.HostPoolName, actual.HostPoolName) + } + + } +} + +func TestSegmentsForHostPoolId(t *testing.T) { + segments := HostPoolId{}.Segments() + if len(segments) == 0 { + t.Fatalf("HostPoolId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/msiximage/method_expand_autorest.go b/resource-manager/desktopvirtualization/2022-02-10-preview/msiximage/method_expand_autorest.go new file mode 100644 index 00000000000..a5ed05244d3 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/msiximage/method_expand_autorest.go @@ -0,0 +1,187 @@ +package msiximage + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExpandOperationResponse struct { + HttpResponse *http.Response + Model *[]ExpandMsixImage + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ExpandOperationResponse, error) +} + +type ExpandCompleteResult struct { + Items []ExpandMsixImage +} + +func (r ExpandOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ExpandOperationResponse) LoadMore(ctx context.Context) (resp ExpandOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// Expand ... +func (c MsixImageClient) Expand(ctx context.Context, id HostPoolId, input MSIXImageURI) (resp ExpandOperationResponse, err error) { + req, err := c.preparerForExpand(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "msiximage.MsixImageClient", "Expand", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "msiximage.MsixImageClient", "Expand", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForExpand(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "msiximage.MsixImageClient", "Expand", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// ExpandComplete retrieves all of the results into a single object +func (c MsixImageClient) ExpandComplete(ctx context.Context, id HostPoolId, input MSIXImageURI) (ExpandCompleteResult, error) { + return c.ExpandCompleteMatchingPredicate(ctx, id, input, ExpandMsixImageOperationPredicate{}) +} + +// ExpandCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c MsixImageClient) ExpandCompleteMatchingPredicate(ctx context.Context, id HostPoolId, input MSIXImageURI, predicate ExpandMsixImageOperationPredicate) (resp ExpandCompleteResult, err error) { + items := make([]ExpandMsixImage, 0) + + page, err := c.Expand(ctx, id, input) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ExpandCompleteResult{ + Items: items, + } + return out, nil +} + +// preparerForExpand prepares the Expand request. +func (c MsixImageClient) preparerForExpand(ctx context.Context, id HostPoolId, input MSIXImageURI) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/expandMsixImage", id.ID())), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForExpandWithNextLink prepares the Expand request with the given nextLink token. +func (c MsixImageClient) preparerForExpandWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForExpand handles the response to the Expand request. The method always +// closes the http.Response Body. +func (c MsixImageClient) responderForExpand(resp *http.Response) (result ExpandOperationResponse, err error) { + type page struct { + Values []ExpandMsixImage `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ExpandOperationResponse, err error) { + req, err := c.preparerForExpandWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "msiximage.MsixImageClient", "Expand", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "msiximage.MsixImageClient", "Expand", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForExpand(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "msiximage.MsixImageClient", "Expand", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/msiximage/model_expandmsiximage.go b/resource-manager/desktopvirtualization/2022-02-10-preview/msiximage/model_expandmsiximage.go new file mode 100644 index 00000000000..8f231e46ec4 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/msiximage/model_expandmsiximage.go @@ -0,0 +1,11 @@ +package msiximage + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExpandMsixImage struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ExpandMsixImageProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/msiximage/model_expandmsiximageproperties.go b/resource-manager/desktopvirtualization/2022-02-10-preview/msiximage/model_expandmsiximageproperties.go new file mode 100644 index 00000000000..cc2cc78fdb2 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/msiximage/model_expandmsiximageproperties.go @@ -0,0 +1,38 @@ +package msiximage + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExpandMsixImageProperties struct { + DisplayName *string `json:"displayName,omitempty"` + ImagePath *string `json:"imagePath,omitempty"` + IsActive *bool `json:"isActive,omitempty"` + IsRegularRegistration *bool `json:"isRegularRegistration,omitempty"` + LastUpdated *string `json:"lastUpdated,omitempty"` + PackageAlias *string `json:"packageAlias,omitempty"` + PackageApplications *[]MsixPackageApplications `json:"packageApplications,omitempty"` + PackageDependencies *[]MsixPackageDependencies `json:"packageDependencies,omitempty"` + PackageFamilyName *string `json:"packageFamilyName,omitempty"` + PackageFullName *string `json:"packageFullName,omitempty"` + PackageName *string `json:"packageName,omitempty"` + PackageRelativePath *string `json:"packageRelativePath,omitempty"` + Version *string `json:"version,omitempty"` +} + +func (o *ExpandMsixImageProperties) GetLastUpdatedAsTime() (*time.Time, error) { + if o.LastUpdated == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastUpdated, "2006-01-02T15:04:05Z07:00") +} + +func (o *ExpandMsixImageProperties) SetLastUpdatedAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastUpdated = &formatted +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/msiximage/model_msiximageuri.go b/resource-manager/desktopvirtualization/2022-02-10-preview/msiximage/model_msiximageuri.go new file mode 100644 index 00000000000..d7ac653b01b --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/msiximage/model_msiximageuri.go @@ -0,0 +1,8 @@ +package msiximage + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MSIXImageURI struct { + Uri *string `json:"uri,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/msiximage/model_msixpackageapplications.go b/resource-manager/desktopvirtualization/2022-02-10-preview/msiximage/model_msixpackageapplications.go new file mode 100644 index 00000000000..372e033f8bb --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/msiximage/model_msixpackageapplications.go @@ -0,0 +1,14 @@ +package msiximage + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MsixPackageApplications struct { + AppId *string `json:"appId,omitempty"` + AppUserModelID *string `json:"appUserModelID,omitempty"` + Description *string `json:"description,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + IconImageName *string `json:"iconImageName,omitempty"` + RawIcon *string `json:"rawIcon,omitempty"` + RawPng *string `json:"rawPng,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/msiximage/model_msixpackagedependencies.go b/resource-manager/desktopvirtualization/2022-02-10-preview/msiximage/model_msixpackagedependencies.go new file mode 100644 index 00000000000..28c81df069c --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/msiximage/model_msixpackagedependencies.go @@ -0,0 +1,10 @@ +package msiximage + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MsixPackageDependencies struct { + DependencyName *string `json:"dependencyName,omitempty"` + MinVersion *string `json:"minVersion,omitempty"` + Publisher *string `json:"publisher,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/msiximage/predicates.go b/resource-manager/desktopvirtualization/2022-02-10-preview/msiximage/predicates.go new file mode 100644 index 00000000000..b281dec62eb --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/msiximage/predicates.go @@ -0,0 +1,24 @@ +package msiximage + +type ExpandMsixImageOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ExpandMsixImageOperationPredicate) Matches(input ExpandMsixImage) bool { + + if p.Id != nil && (input.Id == nil && *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil && *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil && *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/msiximage/version.go b/resource-manager/desktopvirtualization/2022-02-10-preview/msiximage/version.go new file mode 100644 index 00000000000..1593e2f1f91 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/msiximage/version.go @@ -0,0 +1,12 @@ +package msiximage + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2022-02-10-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/msiximage/%s", defaultApiVersion) +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/msixpackage/client.go b/resource-manager/desktopvirtualization/2022-02-10-preview/msixpackage/client.go new file mode 100644 index 00000000000..03a3db16d83 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/msixpackage/client.go @@ -0,0 +1,18 @@ +package msixpackage + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MSIXPackageClient struct { + Client autorest.Client + baseUri string +} + +func NewMSIXPackageClientWithBaseURI(endpoint string) MSIXPackageClient { + return MSIXPackageClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/msixpackage/id_hostpool.go b/resource-manager/desktopvirtualization/2022-02-10-preview/msixpackage/id_hostpool.go new file mode 100644 index 00000000000..459763c2c4b --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/msixpackage/id_hostpool.go @@ -0,0 +1,124 @@ +package msixpackage + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = HostPoolId{} + +// HostPoolId is a struct representing the Resource ID for a Host Pool +type HostPoolId struct { + SubscriptionId string + ResourceGroupName string + HostPoolName string +} + +// NewHostPoolID returns a new HostPoolId struct +func NewHostPoolID(subscriptionId string, resourceGroupName string, hostPoolName string) HostPoolId { + return HostPoolId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + HostPoolName: hostPoolName, + } +} + +// ParseHostPoolID parses 'input' into a HostPoolId +func ParseHostPoolID(input string) (*HostPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(HostPoolId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := HostPoolId{} + + 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.HostPoolName, ok = parsed.Parsed["hostPoolName"]; !ok { + return nil, fmt.Errorf("the segment 'hostPoolName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseHostPoolIDInsensitively parses 'input' case-insensitively into a HostPoolId +// note: this method should only be used for API response data and not user input +func ParseHostPoolIDInsensitively(input string) (*HostPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(HostPoolId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := HostPoolId{} + + 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.HostPoolName, ok = parsed.Parsed["hostPoolName"]; !ok { + return nil, fmt.Errorf("the segment 'hostPoolName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateHostPoolID checks that 'input' can be parsed as a Host Pool ID +func ValidateHostPoolID(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 := ParseHostPoolID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Host Pool ID +func (id HostPoolId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DesktopVirtualization/hostPools/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.HostPoolName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Host Pool ID +func (id HostPoolId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftDesktopVirtualization", "Microsoft.DesktopVirtualization", "Microsoft.DesktopVirtualization"), + resourceids.StaticSegment("staticHostPools", "hostPools", "hostPools"), + resourceids.UserSpecifiedSegment("hostPoolName", "hostPoolValue"), + } +} + +// String returns a human-readable description of this Host Pool ID +func (id HostPoolId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Host Pool Name: %q", id.HostPoolName), + } + return fmt.Sprintf("Host Pool (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/msixpackage/id_hostpool_test.go b/resource-manager/desktopvirtualization/2022-02-10-preview/msixpackage/id_hostpool_test.go new file mode 100644 index 00000000000..4ce0847bd3e --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/msixpackage/id_hostpool_test.go @@ -0,0 +1,279 @@ +package msixpackage + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = HostPoolId{} + +func TestNewHostPoolID(t *testing.T) { + id := NewHostPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "hostPoolValue") + + 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.HostPoolName != "hostPoolValue" { + t.Fatalf("Expected %q but got %q for Segment 'HostPoolName'", id.HostPoolName, "hostPoolValue") + } +} + +func TestFormatHostPoolID(t *testing.T) { + actual := NewHostPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "hostPoolValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseHostPoolID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *HostPoolId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue", + Expected: &HostPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + HostPoolName: "hostPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseHostPoolID(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.HostPoolName != v.Expected.HostPoolName { + t.Fatalf("Expected %q but got %q for HostPoolName", v.Expected.HostPoolName, actual.HostPoolName) + } + + } +} + +func TestParseHostPoolIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *HostPoolId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue", + Expected: &HostPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + HostPoolName: "hostPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe", + Expected: &HostPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + HostPoolName: "hOsTpOoLvAlUe", + }, + }, + { + // 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.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseHostPoolIDInsensitively(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.HostPoolName != v.Expected.HostPoolName { + t.Fatalf("Expected %q but got %q for HostPoolName", v.Expected.HostPoolName, actual.HostPoolName) + } + + } +} + +func TestSegmentsForHostPoolId(t *testing.T) { + segments := HostPoolId{}.Segments() + if len(segments) == 0 { + t.Fatalf("HostPoolId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/msixpackage/id_msixpackage.go b/resource-manager/desktopvirtualization/2022-02-10-preview/msixpackage/id_msixpackage.go new file mode 100644 index 00000000000..77408093011 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/msixpackage/id_msixpackage.go @@ -0,0 +1,137 @@ +package msixpackage + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = MsixPackageId{} + +// MsixPackageId is a struct representing the Resource ID for a Msix Package +type MsixPackageId struct { + SubscriptionId string + ResourceGroupName string + HostPoolName string + MsixPackageFullName string +} + +// NewMsixPackageID returns a new MsixPackageId struct +func NewMsixPackageID(subscriptionId string, resourceGroupName string, hostPoolName string, msixPackageFullName string) MsixPackageId { + return MsixPackageId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + HostPoolName: hostPoolName, + MsixPackageFullName: msixPackageFullName, + } +} + +// ParseMsixPackageID parses 'input' into a MsixPackageId +func ParseMsixPackageID(input string) (*MsixPackageId, error) { + parser := resourceids.NewParserFromResourceIdType(MsixPackageId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := MsixPackageId{} + + 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.HostPoolName, ok = parsed.Parsed["hostPoolName"]; !ok { + return nil, fmt.Errorf("the segment 'hostPoolName' was not found in the resource id %q", input) + } + + if id.MsixPackageFullName, ok = parsed.Parsed["msixPackageFullName"]; !ok { + return nil, fmt.Errorf("the segment 'msixPackageFullName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseMsixPackageIDInsensitively parses 'input' case-insensitively into a MsixPackageId +// note: this method should only be used for API response data and not user input +func ParseMsixPackageIDInsensitively(input string) (*MsixPackageId, error) { + parser := resourceids.NewParserFromResourceIdType(MsixPackageId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := MsixPackageId{} + + 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.HostPoolName, ok = parsed.Parsed["hostPoolName"]; !ok { + return nil, fmt.Errorf("the segment 'hostPoolName' was not found in the resource id %q", input) + } + + if id.MsixPackageFullName, ok = parsed.Parsed["msixPackageFullName"]; !ok { + return nil, fmt.Errorf("the segment 'msixPackageFullName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateMsixPackageID checks that 'input' can be parsed as a Msix Package ID +func ValidateMsixPackageID(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 := ParseMsixPackageID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Msix Package ID +func (id MsixPackageId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DesktopVirtualization/hostPools/%s/msixPackages/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.HostPoolName, id.MsixPackageFullName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Msix Package ID +func (id MsixPackageId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftDesktopVirtualization", "Microsoft.DesktopVirtualization", "Microsoft.DesktopVirtualization"), + resourceids.StaticSegment("staticHostPools", "hostPools", "hostPools"), + resourceids.UserSpecifiedSegment("hostPoolName", "hostPoolValue"), + resourceids.StaticSegment("staticMsixPackages", "msixPackages", "msixPackages"), + resourceids.UserSpecifiedSegment("msixPackageFullName", "msixPackageFullValue"), + } +} + +// String returns a human-readable description of this Msix Package ID +func (id MsixPackageId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Host Pool Name: %q", id.HostPoolName), + fmt.Sprintf("Msix Package Full Name: %q", id.MsixPackageFullName), + } + return fmt.Sprintf("Msix Package (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/msixpackage/id_msixpackage_test.go b/resource-manager/desktopvirtualization/2022-02-10-preview/msixpackage/id_msixpackage_test.go new file mode 100644 index 00000000000..e4060fd76cd --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/msixpackage/id_msixpackage_test.go @@ -0,0 +1,324 @@ +package msixpackage + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = MsixPackageId{} + +func TestNewMsixPackageID(t *testing.T) { + id := NewMsixPackageID("12345678-1234-9876-4563-123456789012", "example-resource-group", "hostPoolValue", "msixPackageFullValue") + + 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.HostPoolName != "hostPoolValue" { + t.Fatalf("Expected %q but got %q for Segment 'HostPoolName'", id.HostPoolName, "hostPoolValue") + } + + if id.MsixPackageFullName != "msixPackageFullValue" { + t.Fatalf("Expected %q but got %q for Segment 'MsixPackageFullName'", id.MsixPackageFullName, "msixPackageFullValue") + } +} + +func TestFormatMsixPackageID(t *testing.T) { + actual := NewMsixPackageID("12345678-1234-9876-4563-123456789012", "example-resource-group", "hostPoolValue", "msixPackageFullValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/msixPackages/msixPackageFullValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseMsixPackageID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *MsixPackageId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/msixPackages", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/msixPackages/msixPackageFullValue", + Expected: &MsixPackageId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + HostPoolName: "hostPoolValue", + MsixPackageFullName: "msixPackageFullValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/msixPackages/msixPackageFullValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseMsixPackageID(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.HostPoolName != v.Expected.HostPoolName { + t.Fatalf("Expected %q but got %q for HostPoolName", v.Expected.HostPoolName, actual.HostPoolName) + } + + if actual.MsixPackageFullName != v.Expected.MsixPackageFullName { + t.Fatalf("Expected %q but got %q for MsixPackageFullName", v.Expected.MsixPackageFullName, actual.MsixPackageFullName) + } + + } +} + +func TestParseMsixPackageIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *MsixPackageId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/msixPackages", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe/mSiXpAcKaGeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/msixPackages/msixPackageFullValue", + Expected: &MsixPackageId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + HostPoolName: "hostPoolValue", + MsixPackageFullName: "msixPackageFullValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/msixPackages/msixPackageFullValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe/mSiXpAcKaGeS/mSiXpAcKaGeFuLlVaLuE", + Expected: &MsixPackageId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + HostPoolName: "hOsTpOoLvAlUe", + MsixPackageFullName: "mSiXpAcKaGeFuLlVaLuE", + }, + }, + { + // 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.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe/mSiXpAcKaGeS/mSiXpAcKaGeFuLlVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseMsixPackageIDInsensitively(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.HostPoolName != v.Expected.HostPoolName { + t.Fatalf("Expected %q but got %q for HostPoolName", v.Expected.HostPoolName, actual.HostPoolName) + } + + if actual.MsixPackageFullName != v.Expected.MsixPackageFullName { + t.Fatalf("Expected %q but got %q for MsixPackageFullName", v.Expected.MsixPackageFullName, actual.MsixPackageFullName) + } + + } +} + +func TestSegmentsForMsixPackageId(t *testing.T) { + segments := MsixPackageId{}.Segments() + if len(segments) == 0 { + t.Fatalf("MsixPackageId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/msixpackage/method_createorupdate_autorest.go b/resource-manager/desktopvirtualization/2022-02-10-preview/msixpackage/method_createorupdate_autorest.go new file mode 100644 index 00000000000..86e8751d5a6 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/msixpackage/method_createorupdate_autorest.go @@ -0,0 +1,68 @@ +package msixpackage + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + Model *MSIXPackage +} + +// CreateOrUpdate ... +func (c MSIXPackageClient) CreateOrUpdate(ctx context.Context, id MsixPackageId, input MSIXPackage) (result CreateOrUpdateOperationResponse, err error) { + req, err := c.preparerForCreateOrUpdate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "msixpackage.MSIXPackageClient", "CreateOrUpdate", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "msixpackage.MSIXPackageClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForCreateOrUpdate(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "msixpackage.MSIXPackageClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForCreateOrUpdate prepares the CreateOrUpdate request. +func (c MSIXPackageClient) preparerForCreateOrUpdate(ctx context.Context, id MsixPackageId, input MSIXPackage) (*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)) +} + +// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always +// closes the http.Response Body. +func (c MSIXPackageClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/msixpackage/method_delete_autorest.go b/resource-manager/desktopvirtualization/2022-02-10-preview/msixpackage/method_delete_autorest.go new file mode 100644 index 00000000000..9441b3f334c --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/msixpackage/method_delete_autorest.go @@ -0,0 +1,65 @@ +package msixpackage + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response +} + +// Delete ... +func (c MSIXPackageClient) Delete(ctx context.Context, id MsixPackageId) (result DeleteOperationResponse, err error) { + req, err := c.preparerForDelete(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "msixpackage.MSIXPackageClient", "Delete", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "msixpackage.MSIXPackageClient", "Delete", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForDelete(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "msixpackage.MSIXPackageClient", "Delete", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForDelete prepares the Delete request. +func (c MSIXPackageClient) preparerForDelete(ctx context.Context, id MsixPackageId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + 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 MSIXPackageClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/msixpackage/method_get_autorest.go b/resource-manager/desktopvirtualization/2022-02-10-preview/msixpackage/method_get_autorest.go new file mode 100644 index 00000000000..7efbe5a56a1 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/msixpackage/method_get_autorest.go @@ -0,0 +1,67 @@ +package msixpackage + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *MSIXPackage +} + +// Get ... +func (c MSIXPackageClient) Get(ctx context.Context, id MsixPackageId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "msixpackage.MSIXPackageClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "msixpackage.MSIXPackageClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "msixpackage.MSIXPackageClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c MSIXPackageClient) preparerForGet(ctx context.Context, id MsixPackageId) (*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 MSIXPackageClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/msixpackage/method_list_autorest.go b/resource-manager/desktopvirtualization/2022-02-10-preview/msixpackage/method_list_autorest.go new file mode 100644 index 00000000000..7968f46e6cc --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/msixpackage/method_list_autorest.go @@ -0,0 +1,186 @@ +package msixpackage + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + Model *[]MSIXPackage + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) +} + +type ListCompleteResult struct { + Items []MSIXPackage +} + +func (r ListOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// List ... +func (c MSIXPackageClient) List(ctx context.Context, id HostPoolId) (resp ListOperationResponse, err error) { + req, err := c.preparerForList(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "msixpackage.MSIXPackageClient", "List", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "msixpackage.MSIXPackageClient", "List", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForList(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "msixpackage.MSIXPackageClient", "List", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// ListComplete retrieves all of the results into a single object +func (c MSIXPackageClient) ListComplete(ctx context.Context, id HostPoolId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, MSIXPackageOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c MSIXPackageClient) ListCompleteMatchingPredicate(ctx context.Context, id HostPoolId, predicate MSIXPackageOperationPredicate) (resp ListCompleteResult, err error) { + items := make([]MSIXPackage, 0) + + page, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListCompleteResult{ + Items: items, + } + return out, nil +} + +// preparerForList prepares the List request. +func (c MSIXPackageClient) preparerForList(ctx context.Context, id HostPoolId) (*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/msixPackages", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListWithNextLink prepares the List request with the given nextLink token. +func (c MSIXPackageClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForList handles the response to the List request. The method always +// closes the http.Response Body. +func (c MSIXPackageClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { + type page struct { + Values []MSIXPackage `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { + req, err := c.preparerForListWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "msixpackage.MSIXPackageClient", "List", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "msixpackage.MSIXPackageClient", "List", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "msixpackage.MSIXPackageClient", "List", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/msixpackage/method_update_autorest.go b/resource-manager/desktopvirtualization/2022-02-10-preview/msixpackage/method_update_autorest.go new file mode 100644 index 00000000000..21ac45d7460 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/msixpackage/method_update_autorest.go @@ -0,0 +1,68 @@ +package msixpackage + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + HttpResponse *http.Response + Model *MSIXPackage +} + +// Update ... +func (c MSIXPackageClient) Update(ctx context.Context, id MsixPackageId, input MSIXPackagePatch) (result UpdateOperationResponse, err error) { + req, err := c.preparerForUpdate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "msixpackage.MSIXPackageClient", "Update", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "msixpackage.MSIXPackageClient", "Update", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForUpdate(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "msixpackage.MSIXPackageClient", "Update", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForUpdate prepares the Update request. +func (c MSIXPackageClient) preparerForUpdate(ctx context.Context, id MsixPackageId, input MSIXPackagePatch) (*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 MSIXPackageClient) responderForUpdate(resp *http.Response) (result UpdateOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/msixpackage/model_msixpackage.go b/resource-manager/desktopvirtualization/2022-02-10-preview/msixpackage/model_msixpackage.go new file mode 100644 index 00000000000..a7059e786c9 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/msixpackage/model_msixpackage.go @@ -0,0 +1,16 @@ +package msixpackage + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MSIXPackage struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties MSIXPackageProperties `json:"properties"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/msixpackage/model_msixpackageapplications.go b/resource-manager/desktopvirtualization/2022-02-10-preview/msixpackage/model_msixpackageapplications.go new file mode 100644 index 00000000000..0496360e8a7 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/msixpackage/model_msixpackageapplications.go @@ -0,0 +1,14 @@ +package msixpackage + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MsixPackageApplications struct { + AppId *string `json:"appId,omitempty"` + AppUserModelID *string `json:"appUserModelID,omitempty"` + Description *string `json:"description,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + IconImageName *string `json:"iconImageName,omitempty"` + RawIcon *string `json:"rawIcon,omitempty"` + RawPng *string `json:"rawPng,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/msixpackage/model_msixpackagedependencies.go b/resource-manager/desktopvirtualization/2022-02-10-preview/msixpackage/model_msixpackagedependencies.go new file mode 100644 index 00000000000..c61fd291e93 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/msixpackage/model_msixpackagedependencies.go @@ -0,0 +1,10 @@ +package msixpackage + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MsixPackageDependencies struct { + DependencyName *string `json:"dependencyName,omitempty"` + MinVersion *string `json:"minVersion,omitempty"` + Publisher *string `json:"publisher,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/msixpackage/model_msixpackagepatch.go b/resource-manager/desktopvirtualization/2022-02-10-preview/msixpackage/model_msixpackagepatch.go new file mode 100644 index 00000000000..c2289a672ea --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/msixpackage/model_msixpackagepatch.go @@ -0,0 +1,11 @@ +package msixpackage + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MSIXPackagePatch struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *MSIXPackagePatchProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/msixpackage/model_msixpackagepatchproperties.go b/resource-manager/desktopvirtualization/2022-02-10-preview/msixpackage/model_msixpackagepatchproperties.go new file mode 100644 index 00000000000..3cef321c214 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/msixpackage/model_msixpackagepatchproperties.go @@ -0,0 +1,10 @@ +package msixpackage + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MSIXPackagePatchProperties struct { + DisplayName *string `json:"displayName,omitempty"` + IsActive *bool `json:"isActive,omitempty"` + IsRegularRegistration *bool `json:"isRegularRegistration,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/msixpackage/model_msixpackageproperties.go b/resource-manager/desktopvirtualization/2022-02-10-preview/msixpackage/model_msixpackageproperties.go new file mode 100644 index 00000000000..92b3d2ccd51 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/msixpackage/model_msixpackageproperties.go @@ -0,0 +1,36 @@ +package msixpackage + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MSIXPackageProperties struct { + DisplayName *string `json:"displayName,omitempty"` + ImagePath *string `json:"imagePath,omitempty"` + IsActive *bool `json:"isActive,omitempty"` + IsRegularRegistration *bool `json:"isRegularRegistration,omitempty"` + LastUpdated *string `json:"lastUpdated,omitempty"` + PackageApplications *[]MsixPackageApplications `json:"packageApplications,omitempty"` + PackageDependencies *[]MsixPackageDependencies `json:"packageDependencies,omitempty"` + PackageFamilyName *string `json:"packageFamilyName,omitempty"` + PackageName *string `json:"packageName,omitempty"` + PackageRelativePath *string `json:"packageRelativePath,omitempty"` + Version *string `json:"version,omitempty"` +} + +func (o *MSIXPackageProperties) GetLastUpdatedAsTime() (*time.Time, error) { + if o.LastUpdated == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastUpdated, "2006-01-02T15:04:05Z07:00") +} + +func (o *MSIXPackageProperties) SetLastUpdatedAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastUpdated = &formatted +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/msixpackage/predicates.go b/resource-manager/desktopvirtualization/2022-02-10-preview/msixpackage/predicates.go new file mode 100644 index 00000000000..881b67fa98b --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/msixpackage/predicates.go @@ -0,0 +1,24 @@ +package msixpackage + +type MSIXPackageOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p MSIXPackageOperationPredicate) Matches(input MSIXPackage) bool { + + if p.Id != nil && (input.Id == nil && *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil && *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil && *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/msixpackage/version.go b/resource-manager/desktopvirtualization/2022-02-10-preview/msixpackage/version.go new file mode 100644 index 00000000000..272cd7a04f5 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/msixpackage/version.go @@ -0,0 +1,12 @@ +package msixpackage + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2022-02-10-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/msixpackage/%s", defaultApiVersion) +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/client.go b/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/client.go new file mode 100644 index 00000000000..709f051f3c9 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/client.go @@ -0,0 +1,18 @@ +package privatelink + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkClient struct { + Client autorest.Client + baseUri string +} + +func NewPrivateLinkClientWithBaseURI(endpoint string) PrivateLinkClient { + return PrivateLinkClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/constants.go b/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/constants.go new file mode 100644 index 00000000000..4f84c23f74f --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/constants.go @@ -0,0 +1,71 @@ +package privatelink + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionProvisioningState string + +const ( + PrivateEndpointConnectionProvisioningStateCreating PrivateEndpointConnectionProvisioningState = "Creating" + PrivateEndpointConnectionProvisioningStateDeleting PrivateEndpointConnectionProvisioningState = "Deleting" + PrivateEndpointConnectionProvisioningStateFailed PrivateEndpointConnectionProvisioningState = "Failed" + PrivateEndpointConnectionProvisioningStateSucceeded PrivateEndpointConnectionProvisioningState = "Succeeded" +) + +func PossibleValuesForPrivateEndpointConnectionProvisioningState() []string { + return []string{ + string(PrivateEndpointConnectionProvisioningStateCreating), + string(PrivateEndpointConnectionProvisioningStateDeleting), + string(PrivateEndpointConnectionProvisioningStateFailed), + string(PrivateEndpointConnectionProvisioningStateSucceeded), + } +} + +func parsePrivateEndpointConnectionProvisioningState(input string) (*PrivateEndpointConnectionProvisioningState, error) { + vals := map[string]PrivateEndpointConnectionProvisioningState{ + "creating": PrivateEndpointConnectionProvisioningStateCreating, + "deleting": PrivateEndpointConnectionProvisioningStateDeleting, + "failed": PrivateEndpointConnectionProvisioningStateFailed, + "succeeded": PrivateEndpointConnectionProvisioningStateSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PrivateEndpointConnectionProvisioningState(input) + return &out, nil +} + +type PrivateEndpointServiceConnectionStatus string + +const ( + PrivateEndpointServiceConnectionStatusApproved PrivateEndpointServiceConnectionStatus = "Approved" + PrivateEndpointServiceConnectionStatusPending PrivateEndpointServiceConnectionStatus = "Pending" + PrivateEndpointServiceConnectionStatusRejected PrivateEndpointServiceConnectionStatus = "Rejected" +) + +func PossibleValuesForPrivateEndpointServiceConnectionStatus() []string { + return []string{ + string(PrivateEndpointServiceConnectionStatusApproved), + string(PrivateEndpointServiceConnectionStatusPending), + string(PrivateEndpointServiceConnectionStatusRejected), + } +} + +func parsePrivateEndpointServiceConnectionStatus(input string) (*PrivateEndpointServiceConnectionStatus, error) { + vals := map[string]PrivateEndpointServiceConnectionStatus{ + "approved": PrivateEndpointServiceConnectionStatusApproved, + "pending": PrivateEndpointServiceConnectionStatusPending, + "rejected": PrivateEndpointServiceConnectionStatusRejected, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PrivateEndpointServiceConnectionStatus(input) + return &out, nil +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/id_hostpool.go b/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/id_hostpool.go new file mode 100644 index 00000000000..a61d2058e8d --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/id_hostpool.go @@ -0,0 +1,124 @@ +package privatelink + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = HostPoolId{} + +// HostPoolId is a struct representing the Resource ID for a Host Pool +type HostPoolId struct { + SubscriptionId string + ResourceGroupName string + HostPoolName string +} + +// NewHostPoolID returns a new HostPoolId struct +func NewHostPoolID(subscriptionId string, resourceGroupName string, hostPoolName string) HostPoolId { + return HostPoolId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + HostPoolName: hostPoolName, + } +} + +// ParseHostPoolID parses 'input' into a HostPoolId +func ParseHostPoolID(input string) (*HostPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(HostPoolId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := HostPoolId{} + + 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.HostPoolName, ok = parsed.Parsed["hostPoolName"]; !ok { + return nil, fmt.Errorf("the segment 'hostPoolName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseHostPoolIDInsensitively parses 'input' case-insensitively into a HostPoolId +// note: this method should only be used for API response data and not user input +func ParseHostPoolIDInsensitively(input string) (*HostPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(HostPoolId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := HostPoolId{} + + 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.HostPoolName, ok = parsed.Parsed["hostPoolName"]; !ok { + return nil, fmt.Errorf("the segment 'hostPoolName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateHostPoolID checks that 'input' can be parsed as a Host Pool ID +func ValidateHostPoolID(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 := ParseHostPoolID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Host Pool ID +func (id HostPoolId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DesktopVirtualization/hostPools/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.HostPoolName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Host Pool ID +func (id HostPoolId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftDesktopVirtualization", "Microsoft.DesktopVirtualization", "Microsoft.DesktopVirtualization"), + resourceids.StaticSegment("staticHostPools", "hostPools", "hostPools"), + resourceids.UserSpecifiedSegment("hostPoolName", "hostPoolValue"), + } +} + +// String returns a human-readable description of this Host Pool ID +func (id HostPoolId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Host Pool Name: %q", id.HostPoolName), + } + return fmt.Sprintf("Host Pool (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/id_hostpool_test.go b/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/id_hostpool_test.go new file mode 100644 index 00000000000..826d59362f5 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/id_hostpool_test.go @@ -0,0 +1,279 @@ +package privatelink + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = HostPoolId{} + +func TestNewHostPoolID(t *testing.T) { + id := NewHostPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "hostPoolValue") + + 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.HostPoolName != "hostPoolValue" { + t.Fatalf("Expected %q but got %q for Segment 'HostPoolName'", id.HostPoolName, "hostPoolValue") + } +} + +func TestFormatHostPoolID(t *testing.T) { + actual := NewHostPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "hostPoolValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseHostPoolID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *HostPoolId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue", + Expected: &HostPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + HostPoolName: "hostPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseHostPoolID(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.HostPoolName != v.Expected.HostPoolName { + t.Fatalf("Expected %q but got %q for HostPoolName", v.Expected.HostPoolName, actual.HostPoolName) + } + + } +} + +func TestParseHostPoolIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *HostPoolId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue", + Expected: &HostPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + HostPoolName: "hostPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe", + Expected: &HostPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + HostPoolName: "hOsTpOoLvAlUe", + }, + }, + { + // 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.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseHostPoolIDInsensitively(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.HostPoolName != v.Expected.HostPoolName { + t.Fatalf("Expected %q but got %q for HostPoolName", v.Expected.HostPoolName, actual.HostPoolName) + } + + } +} + +func TestSegmentsForHostPoolId(t *testing.T) { + segments := HostPoolId{}.Segments() + if len(segments) == 0 { + t.Fatalf("HostPoolId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/id_privateendpointconnection.go b/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/id_privateendpointconnection.go new file mode 100644 index 00000000000..276becf2ed0 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/id_privateendpointconnection.go @@ -0,0 +1,137 @@ +package privatelink + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = PrivateEndpointConnectionId{} + +// PrivateEndpointConnectionId is a struct representing the Resource ID for a Private Endpoint Connection +type PrivateEndpointConnectionId struct { + SubscriptionId string + ResourceGroupName string + HostPoolName string + PrivateEndpointConnectionName string +} + +// NewPrivateEndpointConnectionID returns a new PrivateEndpointConnectionId struct +func NewPrivateEndpointConnectionID(subscriptionId string, resourceGroupName string, hostPoolName string, privateEndpointConnectionName string) PrivateEndpointConnectionId { + return PrivateEndpointConnectionId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + HostPoolName: hostPoolName, + PrivateEndpointConnectionName: privateEndpointConnectionName, + } +} + +// ParsePrivateEndpointConnectionID parses 'input' into a PrivateEndpointConnectionId +func ParsePrivateEndpointConnectionID(input string) (*PrivateEndpointConnectionId, error) { + parser := resourceids.NewParserFromResourceIdType(PrivateEndpointConnectionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := PrivateEndpointConnectionId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.HostPoolName, ok = parsed.Parsed["hostPoolName"]; !ok { + return nil, fmt.Errorf("the segment 'hostPoolName' was not found in the resource id %q", input) + } + + if id.PrivateEndpointConnectionName, ok = parsed.Parsed["privateEndpointConnectionName"]; !ok { + return nil, fmt.Errorf("the segment 'privateEndpointConnectionName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParsePrivateEndpointConnectionIDInsensitively parses 'input' case-insensitively into a PrivateEndpointConnectionId +// note: this method should only be used for API response data and not user input +func ParsePrivateEndpointConnectionIDInsensitively(input string) (*PrivateEndpointConnectionId, error) { + parser := resourceids.NewParserFromResourceIdType(PrivateEndpointConnectionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := PrivateEndpointConnectionId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.HostPoolName, ok = parsed.Parsed["hostPoolName"]; !ok { + return nil, fmt.Errorf("the segment 'hostPoolName' was not found in the resource id %q", input) + } + + if id.PrivateEndpointConnectionName, ok = parsed.Parsed["privateEndpointConnectionName"]; !ok { + return nil, fmt.Errorf("the segment 'privateEndpointConnectionName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidatePrivateEndpointConnectionID checks that 'input' can be parsed as a Private Endpoint Connection ID +func ValidatePrivateEndpointConnectionID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParsePrivateEndpointConnectionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Private Endpoint Connection ID +func (id PrivateEndpointConnectionId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DesktopVirtualization/hostPools/%s/privateEndpointConnections/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.HostPoolName, id.PrivateEndpointConnectionName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Private Endpoint Connection ID +func (id PrivateEndpointConnectionId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftDesktopVirtualization", "Microsoft.DesktopVirtualization", "Microsoft.DesktopVirtualization"), + resourceids.StaticSegment("staticHostPools", "hostPools", "hostPools"), + resourceids.UserSpecifiedSegment("hostPoolName", "hostPoolValue"), + resourceids.StaticSegment("staticPrivateEndpointConnections", "privateEndpointConnections", "privateEndpointConnections"), + resourceids.UserSpecifiedSegment("privateEndpointConnectionName", "privateEndpointConnectionValue"), + } +} + +// String returns a human-readable description of this Private Endpoint Connection ID +func (id PrivateEndpointConnectionId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Host Pool Name: %q", id.HostPoolName), + fmt.Sprintf("Private Endpoint Connection Name: %q", id.PrivateEndpointConnectionName), + } + return fmt.Sprintf("Private Endpoint Connection (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/id_privateendpointconnection_test.go b/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/id_privateendpointconnection_test.go new file mode 100644 index 00000000000..4a1968bb5cc --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/id_privateendpointconnection_test.go @@ -0,0 +1,324 @@ +package privatelink + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = PrivateEndpointConnectionId{} + +func TestNewPrivateEndpointConnectionID(t *testing.T) { + id := NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "hostPoolValue", "privateEndpointConnectionValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.HostPoolName != "hostPoolValue" { + t.Fatalf("Expected %q but got %q for Segment 'HostPoolName'", id.HostPoolName, "hostPoolValue") + } + + if id.PrivateEndpointConnectionName != "privateEndpointConnectionValue" { + t.Fatalf("Expected %q but got %q for Segment 'PrivateEndpointConnectionName'", id.PrivateEndpointConnectionName, "privateEndpointConnectionValue") + } +} + +func TestFormatPrivateEndpointConnectionID(t *testing.T) { + actual := NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "hostPoolValue", "privateEndpointConnectionValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/privateEndpointConnections/privateEndpointConnectionValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParsePrivateEndpointConnectionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateEndpointConnectionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/privateEndpointConnections", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/privateEndpointConnections/privateEndpointConnectionValue", + Expected: &PrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + HostPoolName: "hostPoolValue", + PrivateEndpointConnectionName: "privateEndpointConnectionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/privateEndpointConnections/privateEndpointConnectionValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateEndpointConnectionID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.HostPoolName != v.Expected.HostPoolName { + t.Fatalf("Expected %q but got %q for HostPoolName", v.Expected.HostPoolName, actual.HostPoolName) + } + + if actual.PrivateEndpointConnectionName != v.Expected.PrivateEndpointConnectionName { + t.Fatalf("Expected %q but got %q for PrivateEndpointConnectionName", v.Expected.PrivateEndpointConnectionName, actual.PrivateEndpointConnectionName) + } + + } +} + +func TestParsePrivateEndpointConnectionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateEndpointConnectionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/privateEndpointConnections", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe/pRiVaTeEnDpOiNtCoNnEcTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/privateEndpointConnections/privateEndpointConnectionValue", + Expected: &PrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + HostPoolName: "hostPoolValue", + PrivateEndpointConnectionName: "privateEndpointConnectionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/privateEndpointConnections/privateEndpointConnectionValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe/pRiVaTeEnDpOiNtCoNnEcTiOnS/pRiVaTeEnDpOiNtCoNnEcTiOnVaLuE", + Expected: &PrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + HostPoolName: "hOsTpOoLvAlUe", + PrivateEndpointConnectionName: "pRiVaTeEnDpOiNtCoNnEcTiOnVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe/pRiVaTeEnDpOiNtCoNnEcTiOnS/pRiVaTeEnDpOiNtCoNnEcTiOnVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateEndpointConnectionIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.HostPoolName != v.Expected.HostPoolName { + t.Fatalf("Expected %q but got %q for HostPoolName", v.Expected.HostPoolName, actual.HostPoolName) + } + + if actual.PrivateEndpointConnectionName != v.Expected.PrivateEndpointConnectionName { + t.Fatalf("Expected %q but got %q for PrivateEndpointConnectionName", v.Expected.PrivateEndpointConnectionName, actual.PrivateEndpointConnectionName) + } + + } +} + +func TestSegmentsForPrivateEndpointConnectionId(t *testing.T) { + segments := PrivateEndpointConnectionId{}.Segments() + if len(segments) == 0 { + t.Fatalf("PrivateEndpointConnectionId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/id_workspace.go b/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/id_workspace.go new file mode 100644 index 00000000000..ff0c3caccb3 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/id_workspace.go @@ -0,0 +1,124 @@ +package privatelink + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace +type WorkspaceId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string +} + +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, workspaceName string) WorkspaceId { + return WorkspaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + } +} + +// ParseWorkspaceID parses 'input' into a WorkspaceId +func ParseWorkspaceID(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(WorkspaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := WorkspaceId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.WorkspaceName, ok = parsed.Parsed["workspaceName"]; !ok { + return nil, fmt.Errorf("the segment 'workspaceName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(WorkspaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := WorkspaceId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.WorkspaceName, ok = parsed.Parsed["workspaceName"]; !ok { + return nil, fmt.Errorf("the segment 'workspaceName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DesktopVirtualization/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftDesktopVirtualization", "Microsoft.DesktopVirtualization", "Microsoft.DesktopVirtualization"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + } +} + +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/id_workspace_test.go b/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/id_workspace_test.go new file mode 100644 index 00000000000..b28649b2b1b --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/id_workspace_test.go @@ -0,0 +1,279 @@ +package privatelink + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = WorkspaceId{} + +func TestNewWorkspaceID(t *testing.T) { + id := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } +} + +func TestFormatWorkspaceID(t *testing.T) { + actual := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/workspaces/workspaceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/workspaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/workspaces/workspaceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestParseWorkspaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/wOrKsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/workspaces/workspaceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/wOrKsPaCeS/wOrKsPaCeVaLuE", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/wOrKsPaCeS/wOrKsPaCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestSegmentsForWorkspaceId(t *testing.T) { + segments := WorkspaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/id_workspaceprivateendpointconnection.go b/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/id_workspaceprivateendpointconnection.go new file mode 100644 index 00000000000..34bc71af20a --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/id_workspaceprivateendpointconnection.go @@ -0,0 +1,137 @@ +package privatelink + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = WorkspacePrivateEndpointConnectionId{} + +// WorkspacePrivateEndpointConnectionId is a struct representing the Resource ID for a Workspace Private Endpoint Connection +type WorkspacePrivateEndpointConnectionId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + PrivateEndpointConnectionName string +} + +// NewWorkspacePrivateEndpointConnectionID returns a new WorkspacePrivateEndpointConnectionId struct +func NewWorkspacePrivateEndpointConnectionID(subscriptionId string, resourceGroupName string, workspaceName string, privateEndpointConnectionName string) WorkspacePrivateEndpointConnectionId { + return WorkspacePrivateEndpointConnectionId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + PrivateEndpointConnectionName: privateEndpointConnectionName, + } +} + +// ParseWorkspacePrivateEndpointConnectionID parses 'input' into a WorkspacePrivateEndpointConnectionId +func ParseWorkspacePrivateEndpointConnectionID(input string) (*WorkspacePrivateEndpointConnectionId, error) { + parser := resourceids.NewParserFromResourceIdType(WorkspacePrivateEndpointConnectionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := WorkspacePrivateEndpointConnectionId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.WorkspaceName, ok = parsed.Parsed["workspaceName"]; !ok { + return nil, fmt.Errorf("the segment 'workspaceName' was not found in the resource id %q", input) + } + + if id.PrivateEndpointConnectionName, ok = parsed.Parsed["privateEndpointConnectionName"]; !ok { + return nil, fmt.Errorf("the segment 'privateEndpointConnectionName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseWorkspacePrivateEndpointConnectionIDInsensitively parses 'input' case-insensitively into a WorkspacePrivateEndpointConnectionId +// note: this method should only be used for API response data and not user input +func ParseWorkspacePrivateEndpointConnectionIDInsensitively(input string) (*WorkspacePrivateEndpointConnectionId, error) { + parser := resourceids.NewParserFromResourceIdType(WorkspacePrivateEndpointConnectionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := WorkspacePrivateEndpointConnectionId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.WorkspaceName, ok = parsed.Parsed["workspaceName"]; !ok { + return nil, fmt.Errorf("the segment 'workspaceName' was not found in the resource id %q", input) + } + + if id.PrivateEndpointConnectionName, ok = parsed.Parsed["privateEndpointConnectionName"]; !ok { + return nil, fmt.Errorf("the segment 'privateEndpointConnectionName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateWorkspacePrivateEndpointConnectionID checks that 'input' can be parsed as a Workspace Private Endpoint Connection ID +func ValidateWorkspacePrivateEndpointConnectionID(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 := ParseWorkspacePrivateEndpointConnectionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace Private Endpoint Connection ID +func (id WorkspacePrivateEndpointConnectionId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DesktopVirtualization/workspaces/%s/privateEndpointConnections/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.PrivateEndpointConnectionName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace Private Endpoint Connection ID +func (id WorkspacePrivateEndpointConnectionId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftDesktopVirtualization", "Microsoft.DesktopVirtualization", "Microsoft.DesktopVirtualization"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticPrivateEndpointConnections", "privateEndpointConnections", "privateEndpointConnections"), + resourceids.UserSpecifiedSegment("privateEndpointConnectionName", "privateEndpointConnectionValue"), + } +} + +// String returns a human-readable description of this Workspace Private Endpoint Connection ID +func (id WorkspacePrivateEndpointConnectionId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Private Endpoint Connection Name: %q", id.PrivateEndpointConnectionName), + } + return fmt.Sprintf("Workspace Private Endpoint Connection (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/id_workspaceprivateendpointconnection_test.go b/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/id_workspaceprivateendpointconnection_test.go new file mode 100644 index 00000000000..6de0e50b635 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/id_workspaceprivateendpointconnection_test.go @@ -0,0 +1,324 @@ +package privatelink + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = WorkspacePrivateEndpointConnectionId{} + +func TestNewWorkspacePrivateEndpointConnectionID(t *testing.T) { + id := NewWorkspacePrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "privateEndpointConnectionValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.PrivateEndpointConnectionName != "privateEndpointConnectionValue" { + t.Fatalf("Expected %q but got %q for Segment 'PrivateEndpointConnectionName'", id.PrivateEndpointConnectionName, "privateEndpointConnectionValue") + } +} + +func TestFormatWorkspacePrivateEndpointConnectionID(t *testing.T) { + actual := NewWorkspacePrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "privateEndpointConnectionValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/workspaces/workspaceValue/privateEndpointConnections/privateEndpointConnectionValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspacePrivateEndpointConnectionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspacePrivateEndpointConnectionId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/workspaces/workspaceValue/privateEndpointConnections", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/workspaces/workspaceValue/privateEndpointConnections/privateEndpointConnectionValue", + Expected: &WorkspacePrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + PrivateEndpointConnectionName: "privateEndpointConnectionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/workspaces/workspaceValue/privateEndpointConnections/privateEndpointConnectionValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspacePrivateEndpointConnectionID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.PrivateEndpointConnectionName != v.Expected.PrivateEndpointConnectionName { + t.Fatalf("Expected %q but got %q for PrivateEndpointConnectionName", v.Expected.PrivateEndpointConnectionName, actual.PrivateEndpointConnectionName) + } + + } +} + +func TestParseWorkspacePrivateEndpointConnectionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspacePrivateEndpointConnectionId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/workspaces/workspaceValue/privateEndpointConnections", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/wOrKsPaCeS/wOrKsPaCeVaLuE/pRiVaTeEnDpOiNtCoNnEcTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/workspaces/workspaceValue/privateEndpointConnections/privateEndpointConnectionValue", + Expected: &WorkspacePrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + PrivateEndpointConnectionName: "privateEndpointConnectionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/workspaces/workspaceValue/privateEndpointConnections/privateEndpointConnectionValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/wOrKsPaCeS/wOrKsPaCeVaLuE/pRiVaTeEnDpOiNtCoNnEcTiOnS/pRiVaTeEnDpOiNtCoNnEcTiOnVaLuE", + Expected: &WorkspacePrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + PrivateEndpointConnectionName: "pRiVaTeEnDpOiNtCoNnEcTiOnVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/wOrKsPaCeS/wOrKsPaCeVaLuE/pRiVaTeEnDpOiNtCoNnEcTiOnS/pRiVaTeEnDpOiNtCoNnEcTiOnVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspacePrivateEndpointConnectionIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.PrivateEndpointConnectionName != v.Expected.PrivateEndpointConnectionName { + t.Fatalf("Expected %q but got %q for PrivateEndpointConnectionName", v.Expected.PrivateEndpointConnectionName, actual.PrivateEndpointConnectionName) + } + + } +} + +func TestSegmentsForWorkspacePrivateEndpointConnectionId(t *testing.T) { + segments := WorkspacePrivateEndpointConnectionId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspacePrivateEndpointConnectionId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/method_privateendpointconnectionsdeletebyhostpool_autorest.go b/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/method_privateendpointconnectionsdeletebyhostpool_autorest.go new file mode 100644 index 00000000000..6e6d1f8b6fc --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/method_privateendpointconnectionsdeletebyhostpool_autorest.go @@ -0,0 +1,65 @@ +package privatelink + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionsDeleteByHostPoolOperationResponse struct { + HttpResponse *http.Response +} + +// PrivateEndpointConnectionsDeleteByHostPool ... +func (c PrivateLinkClient) PrivateEndpointConnectionsDeleteByHostPool(ctx context.Context, id PrivateEndpointConnectionId) (result PrivateEndpointConnectionsDeleteByHostPoolOperationResponse, err error) { + req, err := c.preparerForPrivateEndpointConnectionsDeleteByHostPool(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "PrivateEndpointConnectionsDeleteByHostPool", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "PrivateEndpointConnectionsDeleteByHostPool", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForPrivateEndpointConnectionsDeleteByHostPool(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "PrivateEndpointConnectionsDeleteByHostPool", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForPrivateEndpointConnectionsDeleteByHostPool prepares the PrivateEndpointConnectionsDeleteByHostPool request. +func (c PrivateLinkClient) preparerForPrivateEndpointConnectionsDeleteByHostPool(ctx context.Context, id PrivateEndpointConnectionId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsDelete(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForPrivateEndpointConnectionsDeleteByHostPool handles the response to the PrivateEndpointConnectionsDeleteByHostPool request. The method always +// closes the http.Response Body. +func (c PrivateLinkClient) responderForPrivateEndpointConnectionsDeleteByHostPool(resp *http.Response) (result PrivateEndpointConnectionsDeleteByHostPoolOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/method_privateendpointconnectionsdeletebyworkspace_autorest.go b/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/method_privateendpointconnectionsdeletebyworkspace_autorest.go new file mode 100644 index 00000000000..65890775649 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/method_privateendpointconnectionsdeletebyworkspace_autorest.go @@ -0,0 +1,65 @@ +package privatelink + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionsDeleteByWorkspaceOperationResponse struct { + HttpResponse *http.Response +} + +// PrivateEndpointConnectionsDeleteByWorkspace ... +func (c PrivateLinkClient) PrivateEndpointConnectionsDeleteByWorkspace(ctx context.Context, id WorkspacePrivateEndpointConnectionId) (result PrivateEndpointConnectionsDeleteByWorkspaceOperationResponse, err error) { + req, err := c.preparerForPrivateEndpointConnectionsDeleteByWorkspace(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "PrivateEndpointConnectionsDeleteByWorkspace", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "PrivateEndpointConnectionsDeleteByWorkspace", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForPrivateEndpointConnectionsDeleteByWorkspace(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "PrivateEndpointConnectionsDeleteByWorkspace", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForPrivateEndpointConnectionsDeleteByWorkspace prepares the PrivateEndpointConnectionsDeleteByWorkspace request. +func (c PrivateLinkClient) preparerForPrivateEndpointConnectionsDeleteByWorkspace(ctx context.Context, id WorkspacePrivateEndpointConnectionId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsDelete(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForPrivateEndpointConnectionsDeleteByWorkspace handles the response to the PrivateEndpointConnectionsDeleteByWorkspace request. The method always +// closes the http.Response Body. +func (c PrivateLinkClient) responderForPrivateEndpointConnectionsDeleteByWorkspace(resp *http.Response) (result PrivateEndpointConnectionsDeleteByWorkspaceOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/method_privateendpointconnectionsgetbyhostpool_autorest.go b/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/method_privateendpointconnectionsgetbyhostpool_autorest.go new file mode 100644 index 00000000000..b01928bc7c4 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/method_privateendpointconnectionsgetbyhostpool_autorest.go @@ -0,0 +1,67 @@ +package privatelink + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionsGetByHostPoolOperationResponse struct { + HttpResponse *http.Response + Model *PrivateEndpointConnectionWithSystemData +} + +// PrivateEndpointConnectionsGetByHostPool ... +func (c PrivateLinkClient) PrivateEndpointConnectionsGetByHostPool(ctx context.Context, id PrivateEndpointConnectionId) (result PrivateEndpointConnectionsGetByHostPoolOperationResponse, err error) { + req, err := c.preparerForPrivateEndpointConnectionsGetByHostPool(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "PrivateEndpointConnectionsGetByHostPool", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "PrivateEndpointConnectionsGetByHostPool", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForPrivateEndpointConnectionsGetByHostPool(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "PrivateEndpointConnectionsGetByHostPool", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForPrivateEndpointConnectionsGetByHostPool prepares the PrivateEndpointConnectionsGetByHostPool request. +func (c PrivateLinkClient) preparerForPrivateEndpointConnectionsGetByHostPool(ctx context.Context, id PrivateEndpointConnectionId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForPrivateEndpointConnectionsGetByHostPool handles the response to the PrivateEndpointConnectionsGetByHostPool request. The method always +// closes the http.Response Body. +func (c PrivateLinkClient) responderForPrivateEndpointConnectionsGetByHostPool(resp *http.Response) (result PrivateEndpointConnectionsGetByHostPoolOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/method_privateendpointconnectionsgetbyworkspace_autorest.go b/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/method_privateendpointconnectionsgetbyworkspace_autorest.go new file mode 100644 index 00000000000..7b551f8c1d3 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/method_privateendpointconnectionsgetbyworkspace_autorest.go @@ -0,0 +1,67 @@ +package privatelink + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionsGetByWorkspaceOperationResponse struct { + HttpResponse *http.Response + Model *PrivateEndpointConnectionWithSystemData +} + +// PrivateEndpointConnectionsGetByWorkspace ... +func (c PrivateLinkClient) PrivateEndpointConnectionsGetByWorkspace(ctx context.Context, id WorkspacePrivateEndpointConnectionId) (result PrivateEndpointConnectionsGetByWorkspaceOperationResponse, err error) { + req, err := c.preparerForPrivateEndpointConnectionsGetByWorkspace(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "PrivateEndpointConnectionsGetByWorkspace", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "PrivateEndpointConnectionsGetByWorkspace", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForPrivateEndpointConnectionsGetByWorkspace(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "PrivateEndpointConnectionsGetByWorkspace", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForPrivateEndpointConnectionsGetByWorkspace prepares the PrivateEndpointConnectionsGetByWorkspace request. +func (c PrivateLinkClient) preparerForPrivateEndpointConnectionsGetByWorkspace(ctx context.Context, id WorkspacePrivateEndpointConnectionId) (*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)) +} + +// responderForPrivateEndpointConnectionsGetByWorkspace handles the response to the PrivateEndpointConnectionsGetByWorkspace request. The method always +// closes the http.Response Body. +func (c PrivateLinkClient) responderForPrivateEndpointConnectionsGetByWorkspace(resp *http.Response) (result PrivateEndpointConnectionsGetByWorkspaceOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/method_privateendpointconnectionslistbyhostpool_autorest.go b/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/method_privateendpointconnectionslistbyhostpool_autorest.go new file mode 100644 index 00000000000..9e9856caea7 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/method_privateendpointconnectionslistbyhostpool_autorest.go @@ -0,0 +1,186 @@ +package privatelink + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionsListByHostPoolOperationResponse struct { + HttpResponse *http.Response + Model *[]PrivateEndpointConnectionWithSystemData + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (PrivateEndpointConnectionsListByHostPoolOperationResponse, error) +} + +type PrivateEndpointConnectionsListByHostPoolCompleteResult struct { + Items []PrivateEndpointConnectionWithSystemData +} + +func (r PrivateEndpointConnectionsListByHostPoolOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r PrivateEndpointConnectionsListByHostPoolOperationResponse) LoadMore(ctx context.Context) (resp PrivateEndpointConnectionsListByHostPoolOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// PrivateEndpointConnectionsListByHostPool ... +func (c PrivateLinkClient) PrivateEndpointConnectionsListByHostPool(ctx context.Context, id HostPoolId) (resp PrivateEndpointConnectionsListByHostPoolOperationResponse, err error) { + req, err := c.preparerForPrivateEndpointConnectionsListByHostPool(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "PrivateEndpointConnectionsListByHostPool", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "PrivateEndpointConnectionsListByHostPool", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForPrivateEndpointConnectionsListByHostPool(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "PrivateEndpointConnectionsListByHostPool", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// PrivateEndpointConnectionsListByHostPoolComplete retrieves all of the results into a single object +func (c PrivateLinkClient) PrivateEndpointConnectionsListByHostPoolComplete(ctx context.Context, id HostPoolId) (PrivateEndpointConnectionsListByHostPoolCompleteResult, error) { + return c.PrivateEndpointConnectionsListByHostPoolCompleteMatchingPredicate(ctx, id, PrivateEndpointConnectionWithSystemDataOperationPredicate{}) +} + +// PrivateEndpointConnectionsListByHostPoolCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c PrivateLinkClient) PrivateEndpointConnectionsListByHostPoolCompleteMatchingPredicate(ctx context.Context, id HostPoolId, predicate PrivateEndpointConnectionWithSystemDataOperationPredicate) (resp PrivateEndpointConnectionsListByHostPoolCompleteResult, err error) { + items := make([]PrivateEndpointConnectionWithSystemData, 0) + + page, err := c.PrivateEndpointConnectionsListByHostPool(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := PrivateEndpointConnectionsListByHostPoolCompleteResult{ + Items: items, + } + return out, nil +} + +// preparerForPrivateEndpointConnectionsListByHostPool prepares the PrivateEndpointConnectionsListByHostPool request. +func (c PrivateLinkClient) preparerForPrivateEndpointConnectionsListByHostPool(ctx context.Context, id HostPoolId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/privateEndpointConnections", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForPrivateEndpointConnectionsListByHostPoolWithNextLink prepares the PrivateEndpointConnectionsListByHostPool request with the given nextLink token. +func (c PrivateLinkClient) preparerForPrivateEndpointConnectionsListByHostPoolWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForPrivateEndpointConnectionsListByHostPool handles the response to the PrivateEndpointConnectionsListByHostPool request. The method always +// closes the http.Response Body. +func (c PrivateLinkClient) responderForPrivateEndpointConnectionsListByHostPool(resp *http.Response) (result PrivateEndpointConnectionsListByHostPoolOperationResponse, err error) { + type page struct { + Values []PrivateEndpointConnectionWithSystemData `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result PrivateEndpointConnectionsListByHostPoolOperationResponse, err error) { + req, err := c.preparerForPrivateEndpointConnectionsListByHostPoolWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "PrivateEndpointConnectionsListByHostPool", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "PrivateEndpointConnectionsListByHostPool", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForPrivateEndpointConnectionsListByHostPool(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "PrivateEndpointConnectionsListByHostPool", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/method_privateendpointconnectionslistbyworkspace_autorest.go b/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/method_privateendpointconnectionslistbyworkspace_autorest.go new file mode 100644 index 00000000000..15c4ed3e145 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/method_privateendpointconnectionslistbyworkspace_autorest.go @@ -0,0 +1,186 @@ +package privatelink + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionsListByWorkspaceOperationResponse struct { + HttpResponse *http.Response + Model *[]PrivateEndpointConnectionWithSystemData + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (PrivateEndpointConnectionsListByWorkspaceOperationResponse, error) +} + +type PrivateEndpointConnectionsListByWorkspaceCompleteResult struct { + Items []PrivateEndpointConnectionWithSystemData +} + +func (r PrivateEndpointConnectionsListByWorkspaceOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r PrivateEndpointConnectionsListByWorkspaceOperationResponse) LoadMore(ctx context.Context) (resp PrivateEndpointConnectionsListByWorkspaceOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// PrivateEndpointConnectionsListByWorkspace ... +func (c PrivateLinkClient) PrivateEndpointConnectionsListByWorkspace(ctx context.Context, id WorkspaceId) (resp PrivateEndpointConnectionsListByWorkspaceOperationResponse, err error) { + req, err := c.preparerForPrivateEndpointConnectionsListByWorkspace(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "PrivateEndpointConnectionsListByWorkspace", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "PrivateEndpointConnectionsListByWorkspace", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForPrivateEndpointConnectionsListByWorkspace(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "PrivateEndpointConnectionsListByWorkspace", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// PrivateEndpointConnectionsListByWorkspaceComplete retrieves all of the results into a single object +func (c PrivateLinkClient) PrivateEndpointConnectionsListByWorkspaceComplete(ctx context.Context, id WorkspaceId) (PrivateEndpointConnectionsListByWorkspaceCompleteResult, error) { + return c.PrivateEndpointConnectionsListByWorkspaceCompleteMatchingPredicate(ctx, id, PrivateEndpointConnectionWithSystemDataOperationPredicate{}) +} + +// PrivateEndpointConnectionsListByWorkspaceCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c PrivateLinkClient) PrivateEndpointConnectionsListByWorkspaceCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate PrivateEndpointConnectionWithSystemDataOperationPredicate) (resp PrivateEndpointConnectionsListByWorkspaceCompleteResult, err error) { + items := make([]PrivateEndpointConnectionWithSystemData, 0) + + page, err := c.PrivateEndpointConnectionsListByWorkspace(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := PrivateEndpointConnectionsListByWorkspaceCompleteResult{ + Items: items, + } + return out, nil +} + +// preparerForPrivateEndpointConnectionsListByWorkspace prepares the PrivateEndpointConnectionsListByWorkspace request. +func (c PrivateLinkClient) preparerForPrivateEndpointConnectionsListByWorkspace(ctx context.Context, id WorkspaceId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/privateEndpointConnections", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForPrivateEndpointConnectionsListByWorkspaceWithNextLink prepares the PrivateEndpointConnectionsListByWorkspace request with the given nextLink token. +func (c PrivateLinkClient) preparerForPrivateEndpointConnectionsListByWorkspaceWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForPrivateEndpointConnectionsListByWorkspace handles the response to the PrivateEndpointConnectionsListByWorkspace request. The method always +// closes the http.Response Body. +func (c PrivateLinkClient) responderForPrivateEndpointConnectionsListByWorkspace(resp *http.Response) (result PrivateEndpointConnectionsListByWorkspaceOperationResponse, err error) { + type page struct { + Values []PrivateEndpointConnectionWithSystemData `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result PrivateEndpointConnectionsListByWorkspaceOperationResponse, err error) { + req, err := c.preparerForPrivateEndpointConnectionsListByWorkspaceWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "PrivateEndpointConnectionsListByWorkspace", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "PrivateEndpointConnectionsListByWorkspace", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForPrivateEndpointConnectionsListByWorkspace(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "PrivateEndpointConnectionsListByWorkspace", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/method_privateendpointconnectionsupdatebyhostpool_autorest.go b/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/method_privateendpointconnectionsupdatebyhostpool_autorest.go new file mode 100644 index 00000000000..80b60d57329 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/method_privateendpointconnectionsupdatebyhostpool_autorest.go @@ -0,0 +1,68 @@ +package privatelink + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionsUpdateByHostPoolOperationResponse struct { + HttpResponse *http.Response + Model *PrivateEndpointConnectionWithSystemData +} + +// PrivateEndpointConnectionsUpdateByHostPool ... +func (c PrivateLinkClient) PrivateEndpointConnectionsUpdateByHostPool(ctx context.Context, id PrivateEndpointConnectionId, input PrivateEndpointConnection) (result PrivateEndpointConnectionsUpdateByHostPoolOperationResponse, err error) { + req, err := c.preparerForPrivateEndpointConnectionsUpdateByHostPool(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "PrivateEndpointConnectionsUpdateByHostPool", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "PrivateEndpointConnectionsUpdateByHostPool", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForPrivateEndpointConnectionsUpdateByHostPool(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "PrivateEndpointConnectionsUpdateByHostPool", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForPrivateEndpointConnectionsUpdateByHostPool prepares the PrivateEndpointConnectionsUpdateByHostPool request. +func (c PrivateLinkClient) preparerForPrivateEndpointConnectionsUpdateByHostPool(ctx context.Context, id PrivateEndpointConnectionId, input PrivateEndpointConnection) (*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)) +} + +// responderForPrivateEndpointConnectionsUpdateByHostPool handles the response to the PrivateEndpointConnectionsUpdateByHostPool request. The method always +// closes the http.Response Body. +func (c PrivateLinkClient) responderForPrivateEndpointConnectionsUpdateByHostPool(resp *http.Response) (result PrivateEndpointConnectionsUpdateByHostPoolOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/method_privateendpointconnectionsupdatebyworkspace_autorest.go b/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/method_privateendpointconnectionsupdatebyworkspace_autorest.go new file mode 100644 index 00000000000..dbb9c1b196c --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/method_privateendpointconnectionsupdatebyworkspace_autorest.go @@ -0,0 +1,68 @@ +package privatelink + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionsUpdateByWorkspaceOperationResponse struct { + HttpResponse *http.Response + Model *PrivateEndpointConnectionWithSystemData +} + +// PrivateEndpointConnectionsUpdateByWorkspace ... +func (c PrivateLinkClient) PrivateEndpointConnectionsUpdateByWorkspace(ctx context.Context, id WorkspacePrivateEndpointConnectionId, input PrivateEndpointConnection) (result PrivateEndpointConnectionsUpdateByWorkspaceOperationResponse, err error) { + req, err := c.preparerForPrivateEndpointConnectionsUpdateByWorkspace(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "PrivateEndpointConnectionsUpdateByWorkspace", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "PrivateEndpointConnectionsUpdateByWorkspace", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForPrivateEndpointConnectionsUpdateByWorkspace(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "PrivateEndpointConnectionsUpdateByWorkspace", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForPrivateEndpointConnectionsUpdateByWorkspace prepares the PrivateEndpointConnectionsUpdateByWorkspace request. +func (c PrivateLinkClient) preparerForPrivateEndpointConnectionsUpdateByWorkspace(ctx context.Context, id WorkspacePrivateEndpointConnectionId, input PrivateEndpointConnection) (*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)) +} + +// responderForPrivateEndpointConnectionsUpdateByWorkspace handles the response to the PrivateEndpointConnectionsUpdateByWorkspace request. The method always +// closes the http.Response Body. +func (c PrivateLinkClient) responderForPrivateEndpointConnectionsUpdateByWorkspace(resp *http.Response) (result PrivateEndpointConnectionsUpdateByWorkspaceOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/method_resourceslistbyhostpool_autorest.go b/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/method_resourceslistbyhostpool_autorest.go new file mode 100644 index 00000000000..bc69c62e590 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/method_resourceslistbyhostpool_autorest.go @@ -0,0 +1,186 @@ +package privatelink + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourcesListByHostPoolOperationResponse struct { + HttpResponse *http.Response + Model *[]PrivateLinkResource + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ResourcesListByHostPoolOperationResponse, error) +} + +type ResourcesListByHostPoolCompleteResult struct { + Items []PrivateLinkResource +} + +func (r ResourcesListByHostPoolOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ResourcesListByHostPoolOperationResponse) LoadMore(ctx context.Context) (resp ResourcesListByHostPoolOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// ResourcesListByHostPool ... +func (c PrivateLinkClient) ResourcesListByHostPool(ctx context.Context, id HostPoolId) (resp ResourcesListByHostPoolOperationResponse, err error) { + req, err := c.preparerForResourcesListByHostPool(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "ResourcesListByHostPool", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "ResourcesListByHostPool", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForResourcesListByHostPool(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "ResourcesListByHostPool", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// ResourcesListByHostPoolComplete retrieves all of the results into a single object +func (c PrivateLinkClient) ResourcesListByHostPoolComplete(ctx context.Context, id HostPoolId) (ResourcesListByHostPoolCompleteResult, error) { + return c.ResourcesListByHostPoolCompleteMatchingPredicate(ctx, id, PrivateLinkResourceOperationPredicate{}) +} + +// ResourcesListByHostPoolCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c PrivateLinkClient) ResourcesListByHostPoolCompleteMatchingPredicate(ctx context.Context, id HostPoolId, predicate PrivateLinkResourceOperationPredicate) (resp ResourcesListByHostPoolCompleteResult, err error) { + items := make([]PrivateLinkResource, 0) + + page, err := c.ResourcesListByHostPool(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ResourcesListByHostPoolCompleteResult{ + Items: items, + } + return out, nil +} + +// preparerForResourcesListByHostPool prepares the ResourcesListByHostPool request. +func (c PrivateLinkClient) preparerForResourcesListByHostPool(ctx context.Context, id HostPoolId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/privateLinkResources", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForResourcesListByHostPoolWithNextLink prepares the ResourcesListByHostPool request with the given nextLink token. +func (c PrivateLinkClient) preparerForResourcesListByHostPoolWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForResourcesListByHostPool handles the response to the ResourcesListByHostPool request. The method always +// closes the http.Response Body. +func (c PrivateLinkClient) responderForResourcesListByHostPool(resp *http.Response) (result ResourcesListByHostPoolOperationResponse, err error) { + type page struct { + Values []PrivateLinkResource `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ResourcesListByHostPoolOperationResponse, err error) { + req, err := c.preparerForResourcesListByHostPoolWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "ResourcesListByHostPool", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "ResourcesListByHostPool", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForResourcesListByHostPool(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "ResourcesListByHostPool", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/method_resourceslistbyworkspace_autorest.go b/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/method_resourceslistbyworkspace_autorest.go new file mode 100644 index 00000000000..4a18343954d --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/method_resourceslistbyworkspace_autorest.go @@ -0,0 +1,186 @@ +package privatelink + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourcesListByWorkspaceOperationResponse struct { + HttpResponse *http.Response + Model *[]PrivateLinkResource + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ResourcesListByWorkspaceOperationResponse, error) +} + +type ResourcesListByWorkspaceCompleteResult struct { + Items []PrivateLinkResource +} + +func (r ResourcesListByWorkspaceOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ResourcesListByWorkspaceOperationResponse) LoadMore(ctx context.Context) (resp ResourcesListByWorkspaceOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// ResourcesListByWorkspace ... +func (c PrivateLinkClient) ResourcesListByWorkspace(ctx context.Context, id WorkspaceId) (resp ResourcesListByWorkspaceOperationResponse, err error) { + req, err := c.preparerForResourcesListByWorkspace(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "ResourcesListByWorkspace", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "ResourcesListByWorkspace", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForResourcesListByWorkspace(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "ResourcesListByWorkspace", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// ResourcesListByWorkspaceComplete retrieves all of the results into a single object +func (c PrivateLinkClient) ResourcesListByWorkspaceComplete(ctx context.Context, id WorkspaceId) (ResourcesListByWorkspaceCompleteResult, error) { + return c.ResourcesListByWorkspaceCompleteMatchingPredicate(ctx, id, PrivateLinkResourceOperationPredicate{}) +} + +// ResourcesListByWorkspaceCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c PrivateLinkClient) ResourcesListByWorkspaceCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate PrivateLinkResourceOperationPredicate) (resp ResourcesListByWorkspaceCompleteResult, err error) { + items := make([]PrivateLinkResource, 0) + + page, err := c.ResourcesListByWorkspace(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ResourcesListByWorkspaceCompleteResult{ + Items: items, + } + return out, nil +} + +// preparerForResourcesListByWorkspace prepares the ResourcesListByWorkspace request. +func (c PrivateLinkClient) preparerForResourcesListByWorkspace(ctx context.Context, id WorkspaceId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/privateLinkResources", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForResourcesListByWorkspaceWithNextLink prepares the ResourcesListByWorkspace request with the given nextLink token. +func (c PrivateLinkClient) preparerForResourcesListByWorkspaceWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForResourcesListByWorkspace handles the response to the ResourcesListByWorkspace request. The method always +// closes the http.Response Body. +func (c PrivateLinkClient) responderForResourcesListByWorkspace(resp *http.Response) (result ResourcesListByWorkspaceOperationResponse, err error) { + type page struct { + Values []PrivateLinkResource `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ResourcesListByWorkspaceOperationResponse, err error) { + req, err := c.preparerForResourcesListByWorkspaceWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "ResourcesListByWorkspace", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "ResourcesListByWorkspace", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForResourcesListByWorkspace(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelink.PrivateLinkClient", "ResourcesListByWorkspace", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/model_privateendpoint.go b/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/model_privateendpoint.go new file mode 100644 index 00000000000..774ed3c3a08 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/model_privateendpoint.go @@ -0,0 +1,8 @@ +package privatelink + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpoint struct { + Id *string `json:"id,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/model_privateendpointconnection.go b/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/model_privateendpointconnection.go new file mode 100644 index 00000000000..3989160769c --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/model_privateendpointconnection.go @@ -0,0 +1,11 @@ +package privatelink + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnection struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PrivateEndpointConnectionProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/model_privateendpointconnectionproperties.go b/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/model_privateendpointconnectionproperties.go new file mode 100644 index 00000000000..5ee2038e7a0 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/model_privateendpointconnectionproperties.go @@ -0,0 +1,10 @@ +package privatelink + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionProperties struct { + PrivateEndpoint *PrivateEndpoint `json:"privateEndpoint,omitempty"` + PrivateLinkServiceConnectionState PrivateLinkServiceConnectionState `json:"privateLinkServiceConnectionState"` + ProvisioningState *PrivateEndpointConnectionProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/model_privateendpointconnectionwithsystemdata.go b/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/model_privateendpointconnectionwithsystemdata.go new file mode 100644 index 00000000000..3d794ce90fc --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/model_privateendpointconnectionwithsystemdata.go @@ -0,0 +1,16 @@ +package privatelink + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionWithSystemData struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PrivateEndpointConnectionProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/model_privatelinkresource.go b/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/model_privatelinkresource.go new file mode 100644 index 00000000000..fea04be7686 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/model_privatelinkresource.go @@ -0,0 +1,11 @@ +package privatelink + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkResource struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PrivateLinkResourceProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/model_privatelinkresourceproperties.go b/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/model_privatelinkresourceproperties.go new file mode 100644 index 00000000000..36abe10fd9a --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/model_privatelinkresourceproperties.go @@ -0,0 +1,10 @@ +package privatelink + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkResourceProperties struct { + GroupId *string `json:"groupId,omitempty"` + RequiredMembers *[]string `json:"requiredMembers,omitempty"` + RequiredZoneNames *[]string `json:"requiredZoneNames,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/model_privatelinkserviceconnectionstate.go b/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/model_privatelinkserviceconnectionstate.go new file mode 100644 index 00000000000..774b4fe4675 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/model_privatelinkserviceconnectionstate.go @@ -0,0 +1,10 @@ +package privatelink + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkServiceConnectionState struct { + ActionsRequired *string `json:"actionsRequired,omitempty"` + Description *string `json:"description,omitempty"` + Status *PrivateEndpointServiceConnectionStatus `json:"status,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/predicates.go b/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/predicates.go new file mode 100644 index 00000000000..571dd914686 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/predicates.go @@ -0,0 +1,47 @@ +package privatelink + +type PrivateEndpointConnectionWithSystemDataOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p PrivateEndpointConnectionWithSystemDataOperationPredicate) Matches(input PrivateEndpointConnectionWithSystemData) bool { + + if p.Id != nil && (input.Id == nil && *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil && *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil && *p.Type != *input.Type) { + return false + } + + return true +} + +type PrivateLinkResourceOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p PrivateLinkResourceOperationPredicate) Matches(input PrivateLinkResource) bool { + + if p.Id != nil && (input.Id == nil && *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil && *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil && *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/version.go b/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/version.go new file mode 100644 index 00000000000..95a9d87bb72 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/privatelink/version.go @@ -0,0 +1,12 @@ +package privatelink + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2022-02-10-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/privatelink/%s", defaultApiVersion) +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/client.go b/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/client.go new file mode 100644 index 00000000000..eaee7bdef15 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/client.go @@ -0,0 +1,18 @@ +package scalingplan + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ScalingPlanClient struct { + Client autorest.Client + baseUri string +} + +func NewScalingPlanClientWithBaseURI(endpoint string) ScalingPlanClient { + return ScalingPlanClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/constants.go b/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/constants.go new file mode 100644 index 00000000000..9a7fcbb8a5e --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/constants.go @@ -0,0 +1,164 @@ +package scalingplan + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DaysOfWeek string + +const ( + DaysOfWeekFriday DaysOfWeek = "Friday" + DaysOfWeekMonday DaysOfWeek = "Monday" + DaysOfWeekSaturday DaysOfWeek = "Saturday" + DaysOfWeekSunday DaysOfWeek = "Sunday" + DaysOfWeekThursday DaysOfWeek = "Thursday" + DaysOfWeekTuesday DaysOfWeek = "Tuesday" + DaysOfWeekWednesday DaysOfWeek = "Wednesday" +) + +func PossibleValuesForDaysOfWeek() []string { + return []string{ + string(DaysOfWeekFriday), + string(DaysOfWeekMonday), + string(DaysOfWeekSaturday), + string(DaysOfWeekSunday), + string(DaysOfWeekThursday), + string(DaysOfWeekTuesday), + string(DaysOfWeekWednesday), + } +} + +func parseDaysOfWeek(input string) (*DaysOfWeek, error) { + vals := map[string]DaysOfWeek{ + "friday": DaysOfWeekFriday, + "monday": DaysOfWeekMonday, + "saturday": DaysOfWeekSaturday, + "sunday": DaysOfWeekSunday, + "thursday": DaysOfWeekThursday, + "tuesday": DaysOfWeekTuesday, + "wednesday": DaysOfWeekWednesday, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DaysOfWeek(input) + return &out, nil +} + +type ScalingHostPoolType string + +const ( + ScalingHostPoolTypePooled ScalingHostPoolType = "Pooled" +) + +func PossibleValuesForScalingHostPoolType() []string { + return []string{ + string(ScalingHostPoolTypePooled), + } +} + +func parseScalingHostPoolType(input string) (*ScalingHostPoolType, error) { + vals := map[string]ScalingHostPoolType{ + "pooled": ScalingHostPoolTypePooled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ScalingHostPoolType(input) + return &out, nil +} + +type SessionHostLoadBalancingAlgorithm string + +const ( + SessionHostLoadBalancingAlgorithmBreadthFirst SessionHostLoadBalancingAlgorithm = "BreadthFirst" + SessionHostLoadBalancingAlgorithmDepthFirst SessionHostLoadBalancingAlgorithm = "DepthFirst" +) + +func PossibleValuesForSessionHostLoadBalancingAlgorithm() []string { + return []string{ + string(SessionHostLoadBalancingAlgorithmBreadthFirst), + string(SessionHostLoadBalancingAlgorithmDepthFirst), + } +} + +func parseSessionHostLoadBalancingAlgorithm(input string) (*SessionHostLoadBalancingAlgorithm, error) { + vals := map[string]SessionHostLoadBalancingAlgorithm{ + "breadthfirst": SessionHostLoadBalancingAlgorithmBreadthFirst, + "depthfirst": SessionHostLoadBalancingAlgorithmDepthFirst, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SessionHostLoadBalancingAlgorithm(input) + return &out, nil +} + +type SkuTier string + +const ( + SkuTierBasic SkuTier = "Basic" + SkuTierFree SkuTier = "Free" + SkuTierPremium SkuTier = "Premium" + SkuTierStandard SkuTier = "Standard" +) + +func PossibleValuesForSkuTier() []string { + return []string{ + string(SkuTierBasic), + string(SkuTierFree), + string(SkuTierPremium), + string(SkuTierStandard), + } +} + +func parseSkuTier(input string) (*SkuTier, error) { + vals := map[string]SkuTier{ + "basic": SkuTierBasic, + "free": SkuTierFree, + "premium": SkuTierPremium, + "standard": SkuTierStandard, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SkuTier(input) + return &out, nil +} + +type StopHostsWhen string + +const ( + StopHostsWhenZeroActiveSessions StopHostsWhen = "ZeroActiveSessions" + StopHostsWhenZeroSessions StopHostsWhen = "ZeroSessions" +) + +func PossibleValuesForStopHostsWhen() []string { + return []string{ + string(StopHostsWhenZeroActiveSessions), + string(StopHostsWhenZeroSessions), + } +} + +func parseStopHostsWhen(input string) (*StopHostsWhen, error) { + vals := map[string]StopHostsWhen{ + "zeroactivesessions": StopHostsWhenZeroActiveSessions, + "zerosessions": StopHostsWhenZeroSessions, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := StopHostsWhen(input) + return &out, nil +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/id_hostpool.go b/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/id_hostpool.go new file mode 100644 index 00000000000..403b28434e0 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/id_hostpool.go @@ -0,0 +1,124 @@ +package scalingplan + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = HostPoolId{} + +// HostPoolId is a struct representing the Resource ID for a Host Pool +type HostPoolId struct { + SubscriptionId string + ResourceGroupName string + HostPoolName string +} + +// NewHostPoolID returns a new HostPoolId struct +func NewHostPoolID(subscriptionId string, resourceGroupName string, hostPoolName string) HostPoolId { + return HostPoolId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + HostPoolName: hostPoolName, + } +} + +// ParseHostPoolID parses 'input' into a HostPoolId +func ParseHostPoolID(input string) (*HostPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(HostPoolId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := HostPoolId{} + + 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.HostPoolName, ok = parsed.Parsed["hostPoolName"]; !ok { + return nil, fmt.Errorf("the segment 'hostPoolName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseHostPoolIDInsensitively parses 'input' case-insensitively into a HostPoolId +// note: this method should only be used for API response data and not user input +func ParseHostPoolIDInsensitively(input string) (*HostPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(HostPoolId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := HostPoolId{} + + 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.HostPoolName, ok = parsed.Parsed["hostPoolName"]; !ok { + return nil, fmt.Errorf("the segment 'hostPoolName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateHostPoolID checks that 'input' can be parsed as a Host Pool ID +func ValidateHostPoolID(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 := ParseHostPoolID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Host Pool ID +func (id HostPoolId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DesktopVirtualization/hostPools/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.HostPoolName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Host Pool ID +func (id HostPoolId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftDesktopVirtualization", "Microsoft.DesktopVirtualization", "Microsoft.DesktopVirtualization"), + resourceids.StaticSegment("staticHostPools", "hostPools", "hostPools"), + resourceids.UserSpecifiedSegment("hostPoolName", "hostPoolValue"), + } +} + +// String returns a human-readable description of this Host Pool ID +func (id HostPoolId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Host Pool Name: %q", id.HostPoolName), + } + return fmt.Sprintf("Host Pool (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/id_hostpool_test.go b/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/id_hostpool_test.go new file mode 100644 index 00000000000..dbb4a3bfecd --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/id_hostpool_test.go @@ -0,0 +1,279 @@ +package scalingplan + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = HostPoolId{} + +func TestNewHostPoolID(t *testing.T) { + id := NewHostPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "hostPoolValue") + + 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.HostPoolName != "hostPoolValue" { + t.Fatalf("Expected %q but got %q for Segment 'HostPoolName'", id.HostPoolName, "hostPoolValue") + } +} + +func TestFormatHostPoolID(t *testing.T) { + actual := NewHostPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "hostPoolValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseHostPoolID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *HostPoolId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue", + Expected: &HostPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + HostPoolName: "hostPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseHostPoolID(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.HostPoolName != v.Expected.HostPoolName { + t.Fatalf("Expected %q but got %q for HostPoolName", v.Expected.HostPoolName, actual.HostPoolName) + } + + } +} + +func TestParseHostPoolIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *HostPoolId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue", + Expected: &HostPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + HostPoolName: "hostPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe", + Expected: &HostPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + HostPoolName: "hOsTpOoLvAlUe", + }, + }, + { + // 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.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseHostPoolIDInsensitively(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.HostPoolName != v.Expected.HostPoolName { + t.Fatalf("Expected %q but got %q for HostPoolName", v.Expected.HostPoolName, actual.HostPoolName) + } + + } +} + +func TestSegmentsForHostPoolId(t *testing.T) { + segments := HostPoolId{}.Segments() + if len(segments) == 0 { + t.Fatalf("HostPoolId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/id_scalingplan.go b/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/id_scalingplan.go new file mode 100644 index 00000000000..7ab8c80a40c --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/id_scalingplan.go @@ -0,0 +1,124 @@ +package scalingplan + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = ScalingPlanId{} + +// ScalingPlanId is a struct representing the Resource ID for a Scaling Plan +type ScalingPlanId struct { + SubscriptionId string + ResourceGroupName string + ScalingPlanName string +} + +// NewScalingPlanID returns a new ScalingPlanId struct +func NewScalingPlanID(subscriptionId string, resourceGroupName string, scalingPlanName string) ScalingPlanId { + return ScalingPlanId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ScalingPlanName: scalingPlanName, + } +} + +// ParseScalingPlanID parses 'input' into a ScalingPlanId +func ParseScalingPlanID(input string) (*ScalingPlanId, error) { + parser := resourceids.NewParserFromResourceIdType(ScalingPlanId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ScalingPlanId{} + + 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.ScalingPlanName, ok = parsed.Parsed["scalingPlanName"]; !ok { + return nil, fmt.Errorf("the segment 'scalingPlanName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseScalingPlanIDInsensitively parses 'input' case-insensitively into a ScalingPlanId +// note: this method should only be used for API response data and not user input +func ParseScalingPlanIDInsensitively(input string) (*ScalingPlanId, error) { + parser := resourceids.NewParserFromResourceIdType(ScalingPlanId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ScalingPlanId{} + + 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.ScalingPlanName, ok = parsed.Parsed["scalingPlanName"]; !ok { + return nil, fmt.Errorf("the segment 'scalingPlanName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateScalingPlanID checks that 'input' can be parsed as a Scaling Plan ID +func ValidateScalingPlanID(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 := ParseScalingPlanID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Scaling Plan ID +func (id ScalingPlanId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DesktopVirtualization/scalingPlans/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ScalingPlanName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Scaling Plan ID +func (id ScalingPlanId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftDesktopVirtualization", "Microsoft.DesktopVirtualization", "Microsoft.DesktopVirtualization"), + resourceids.StaticSegment("staticScalingPlans", "scalingPlans", "scalingPlans"), + resourceids.UserSpecifiedSegment("scalingPlanName", "scalingPlanValue"), + } +} + +// String returns a human-readable description of this Scaling Plan ID +func (id ScalingPlanId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Scaling Plan Name: %q", id.ScalingPlanName), + } + return fmt.Sprintf("Scaling Plan (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/id_scalingplan_test.go b/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/id_scalingplan_test.go new file mode 100644 index 00000000000..c0b5504527d --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/id_scalingplan_test.go @@ -0,0 +1,279 @@ +package scalingplan + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = ScalingPlanId{} + +func TestNewScalingPlanID(t *testing.T) { + id := NewScalingPlanID("12345678-1234-9876-4563-123456789012", "example-resource-group", "scalingPlanValue") + + 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.ScalingPlanName != "scalingPlanValue" { + t.Fatalf("Expected %q but got %q for Segment 'ScalingPlanName'", id.ScalingPlanName, "scalingPlanValue") + } +} + +func TestFormatScalingPlanID(t *testing.T) { + actual := NewScalingPlanID("12345678-1234-9876-4563-123456789012", "example-resource-group", "scalingPlanValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/scalingPlans/scalingPlanValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseScalingPlanID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ScalingPlanId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/scalingPlans", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/scalingPlans/scalingPlanValue", + Expected: &ScalingPlanId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ScalingPlanName: "scalingPlanValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/scalingPlans/scalingPlanValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseScalingPlanID(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.ScalingPlanName != v.Expected.ScalingPlanName { + t.Fatalf("Expected %q but got %q for ScalingPlanName", v.Expected.ScalingPlanName, actual.ScalingPlanName) + } + + } +} + +func TestParseScalingPlanIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ScalingPlanId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/scalingPlans", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/sCaLiNgPlAnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/scalingPlans/scalingPlanValue", + Expected: &ScalingPlanId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ScalingPlanName: "scalingPlanValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/scalingPlans/scalingPlanValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/sCaLiNgPlAnS/sCaLiNgPlAnVaLuE", + Expected: &ScalingPlanId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ScalingPlanName: "sCaLiNgPlAnVaLuE", + }, + }, + { + // 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.dEsKtOpViRtUaLiZaTiOn/sCaLiNgPlAnS/sCaLiNgPlAnVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseScalingPlanIDInsensitively(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.ScalingPlanName != v.Expected.ScalingPlanName { + t.Fatalf("Expected %q but got %q for ScalingPlanName", v.Expected.ScalingPlanName, actual.ScalingPlanName) + } + + } +} + +func TestSegmentsForScalingPlanId(t *testing.T) { + segments := ScalingPlanId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ScalingPlanId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/method_create_autorest.go b/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/method_create_autorest.go new file mode 100644 index 00000000000..8841c6898fd --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/method_create_autorest.go @@ -0,0 +1,68 @@ +package scalingplan + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOperationResponse struct { + HttpResponse *http.Response + Model *ScalingPlan +} + +// Create ... +func (c ScalingPlanClient) Create(ctx context.Context, id ScalingPlanId, input ScalingPlan) (result CreateOperationResponse, err error) { + req, err := c.preparerForCreate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "scalingplan.ScalingPlanClient", "Create", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "scalingplan.ScalingPlanClient", "Create", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForCreate(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "scalingplan.ScalingPlanClient", "Create", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForCreate prepares the Create request. +func (c ScalingPlanClient) preparerForCreate(ctx context.Context, id ScalingPlanId, input ScalingPlan) (*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 ScalingPlanClient) responderForCreate(resp *http.Response) (result CreateOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/method_delete_autorest.go b/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/method_delete_autorest.go new file mode 100644 index 00000000000..75755b5784c --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/method_delete_autorest.go @@ -0,0 +1,65 @@ +package scalingplan + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response +} + +// Delete ... +func (c ScalingPlanClient) Delete(ctx context.Context, id ScalingPlanId) (result DeleteOperationResponse, err error) { + req, err := c.preparerForDelete(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "scalingplan.ScalingPlanClient", "Delete", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "scalingplan.ScalingPlanClient", "Delete", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForDelete(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "scalingplan.ScalingPlanClient", "Delete", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForDelete prepares the Delete request. +func (c ScalingPlanClient) preparerForDelete(ctx context.Context, id ScalingPlanId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + 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 ScalingPlanClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/method_get_autorest.go b/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/method_get_autorest.go new file mode 100644 index 00000000000..5550e0d3eb9 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/method_get_autorest.go @@ -0,0 +1,67 @@ +package scalingplan + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *ScalingPlan +} + +// Get ... +func (c ScalingPlanClient) Get(ctx context.Context, id ScalingPlanId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "scalingplan.ScalingPlanClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "scalingplan.ScalingPlanClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "scalingplan.ScalingPlanClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c ScalingPlanClient) preparerForGet(ctx context.Context, id ScalingPlanId) (*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 ScalingPlanClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/method_listbyhostpool_autorest.go b/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/method_listbyhostpool_autorest.go new file mode 100644 index 00000000000..b60add783d3 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/method_listbyhostpool_autorest.go @@ -0,0 +1,186 @@ +package scalingplan + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByHostPoolOperationResponse struct { + HttpResponse *http.Response + Model *[]ScalingPlan + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListByHostPoolOperationResponse, error) +} + +type ListByHostPoolCompleteResult struct { + Items []ScalingPlan +} + +func (r ListByHostPoolOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListByHostPoolOperationResponse) LoadMore(ctx context.Context) (resp ListByHostPoolOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// ListByHostPool ... +func (c ScalingPlanClient) ListByHostPool(ctx context.Context, id HostPoolId) (resp ListByHostPoolOperationResponse, err error) { + req, err := c.preparerForListByHostPool(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "scalingplan.ScalingPlanClient", "ListByHostPool", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "scalingplan.ScalingPlanClient", "ListByHostPool", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForListByHostPool(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "scalingplan.ScalingPlanClient", "ListByHostPool", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// ListByHostPoolComplete retrieves all of the results into a single object +func (c ScalingPlanClient) ListByHostPoolComplete(ctx context.Context, id HostPoolId) (ListByHostPoolCompleteResult, error) { + return c.ListByHostPoolCompleteMatchingPredicate(ctx, id, ScalingPlanOperationPredicate{}) +} + +// ListByHostPoolCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c ScalingPlanClient) ListByHostPoolCompleteMatchingPredicate(ctx context.Context, id HostPoolId, predicate ScalingPlanOperationPredicate) (resp ListByHostPoolCompleteResult, err error) { + items := make([]ScalingPlan, 0) + + page, err := c.ListByHostPool(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListByHostPoolCompleteResult{ + Items: items, + } + return out, nil +} + +// preparerForListByHostPool prepares the ListByHostPool request. +func (c ScalingPlanClient) preparerForListByHostPool(ctx context.Context, id HostPoolId) (*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/scalingPlans", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListByHostPoolWithNextLink prepares the ListByHostPool request with the given nextLink token. +func (c ScalingPlanClient) preparerForListByHostPoolWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForListByHostPool handles the response to the ListByHostPool request. The method always +// closes the http.Response Body. +func (c ScalingPlanClient) responderForListByHostPool(resp *http.Response) (result ListByHostPoolOperationResponse, err error) { + type page struct { + Values []ScalingPlan `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListByHostPoolOperationResponse, err error) { + req, err := c.preparerForListByHostPoolWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "scalingplan.ScalingPlanClient", "ListByHostPool", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "scalingplan.ScalingPlanClient", "ListByHostPool", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForListByHostPool(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "scalingplan.ScalingPlanClient", "ListByHostPool", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/method_listbyresourcegroup_autorest.go b/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/method_listbyresourcegroup_autorest.go new file mode 100644 index 00000000000..81cad260899 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/method_listbyresourcegroup_autorest.go @@ -0,0 +1,187 @@ +package scalingplan + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByResourceGroupOperationResponse struct { + HttpResponse *http.Response + Model *[]ScalingPlan + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListByResourceGroupOperationResponse, error) +} + +type ListByResourceGroupCompleteResult struct { + Items []ScalingPlan +} + +func (r ListByResourceGroupOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListByResourceGroupOperationResponse) LoadMore(ctx context.Context) (resp ListByResourceGroupOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// ListByResourceGroup ... +func (c ScalingPlanClient) ListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (resp ListByResourceGroupOperationResponse, err error) { + req, err := c.preparerForListByResourceGroup(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "scalingplan.ScalingPlanClient", "ListByResourceGroup", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "scalingplan.ScalingPlanClient", "ListByResourceGroup", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForListByResourceGroup(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "scalingplan.ScalingPlanClient", "ListByResourceGroup", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// ListByResourceGroupComplete retrieves all of the results into a single object +func (c ScalingPlanClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (ListByResourceGroupCompleteResult, error) { + return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, ScalingPlanOperationPredicate{}) +} + +// ListByResourceGroupCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c ScalingPlanClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate ScalingPlanOperationPredicate) (resp ListByResourceGroupCompleteResult, err error) { + items := make([]ScalingPlan, 0) + + page, err := c.ListByResourceGroup(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListByResourceGroupCompleteResult{ + Items: items, + } + return out, nil +} + +// preparerForListByResourceGroup prepares the ListByResourceGroup request. +func (c ScalingPlanClient) preparerForListByResourceGroup(ctx context.Context, id commonids.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.DesktopVirtualization/scalingPlans", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListByResourceGroupWithNextLink prepares the ListByResourceGroup request with the given nextLink token. +func (c ScalingPlanClient) preparerForListByResourceGroupWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForListByResourceGroup handles the response to the ListByResourceGroup request. The method always +// closes the http.Response Body. +func (c ScalingPlanClient) responderForListByResourceGroup(resp *http.Response) (result ListByResourceGroupOperationResponse, err error) { + type page struct { + Values []ScalingPlan `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListByResourceGroupOperationResponse, err error) { + req, err := c.preparerForListByResourceGroupWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "scalingplan.ScalingPlanClient", "ListByResourceGroup", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "scalingplan.ScalingPlanClient", "ListByResourceGroup", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForListByResourceGroup(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "scalingplan.ScalingPlanClient", "ListByResourceGroup", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/method_listbysubscription_autorest.go b/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/method_listbysubscription_autorest.go new file mode 100644 index 00000000000..aa6c7049d5a --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/method_listbysubscription_autorest.go @@ -0,0 +1,187 @@ +package scalingplan + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListBySubscriptionOperationResponse struct { + HttpResponse *http.Response + Model *[]ScalingPlan + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListBySubscriptionOperationResponse, error) +} + +type ListBySubscriptionCompleteResult struct { + Items []ScalingPlan +} + +func (r ListBySubscriptionOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListBySubscriptionOperationResponse) LoadMore(ctx context.Context) (resp ListBySubscriptionOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// ListBySubscription ... +func (c ScalingPlanClient) ListBySubscription(ctx context.Context, id commonids.SubscriptionId) (resp ListBySubscriptionOperationResponse, err error) { + req, err := c.preparerForListBySubscription(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "scalingplan.ScalingPlanClient", "ListBySubscription", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "scalingplan.ScalingPlanClient", "ListBySubscription", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForListBySubscription(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "scalingplan.ScalingPlanClient", "ListBySubscription", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// ListBySubscriptionComplete retrieves all of the results into a single object +func (c ScalingPlanClient) ListBySubscriptionComplete(ctx context.Context, id commonids.SubscriptionId) (ListBySubscriptionCompleteResult, error) { + return c.ListBySubscriptionCompleteMatchingPredicate(ctx, id, ScalingPlanOperationPredicate{}) +} + +// ListBySubscriptionCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c ScalingPlanClient) ListBySubscriptionCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate ScalingPlanOperationPredicate) (resp ListBySubscriptionCompleteResult, err error) { + items := make([]ScalingPlan, 0) + + page, err := c.ListBySubscription(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListBySubscriptionCompleteResult{ + Items: items, + } + return out, nil +} + +// preparerForListBySubscription prepares the ListBySubscription request. +func (c ScalingPlanClient) preparerForListBySubscription(ctx context.Context, id commonids.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.DesktopVirtualization/scalingPlans", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListBySubscriptionWithNextLink prepares the ListBySubscription request with the given nextLink token. +func (c ScalingPlanClient) preparerForListBySubscriptionWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForListBySubscription handles the response to the ListBySubscription request. The method always +// closes the http.Response Body. +func (c ScalingPlanClient) responderForListBySubscription(resp *http.Response) (result ListBySubscriptionOperationResponse, err error) { + type page struct { + Values []ScalingPlan `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListBySubscriptionOperationResponse, err error) { + req, err := c.preparerForListBySubscriptionWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "scalingplan.ScalingPlanClient", "ListBySubscription", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "scalingplan.ScalingPlanClient", "ListBySubscription", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForListBySubscription(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "scalingplan.ScalingPlanClient", "ListBySubscription", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/method_update_autorest.go b/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/method_update_autorest.go new file mode 100644 index 00000000000..1a91bb11694 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/method_update_autorest.go @@ -0,0 +1,68 @@ +package scalingplan + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + HttpResponse *http.Response + Model *ScalingPlan +} + +// Update ... +func (c ScalingPlanClient) Update(ctx context.Context, id ScalingPlanId, input ScalingPlanPatch) (result UpdateOperationResponse, err error) { + req, err := c.preparerForUpdate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "scalingplan.ScalingPlanClient", "Update", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "scalingplan.ScalingPlanClient", "Update", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForUpdate(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "scalingplan.ScalingPlanClient", "Update", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForUpdate prepares the Update request. +func (c ScalingPlanClient) preparerForUpdate(ctx context.Context, id ScalingPlanId, input ScalingPlanPatch) (*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 ScalingPlanClient) responderForUpdate(resp *http.Response) (result UpdateOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/model_plan.go b/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/model_plan.go new file mode 100644 index 00000000000..07296ec4765 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/model_plan.go @@ -0,0 +1,12 @@ +package scalingplan + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Plan struct { + Name string `json:"name"` + Product string `json:"product"` + PromotionCode *string `json:"promotionCode,omitempty"` + Publisher string `json:"publisher"` + Version *string `json:"version,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/model_scalinghostpoolreference.go b/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/model_scalinghostpoolreference.go new file mode 100644 index 00000000000..0bd8fd048bb --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/model_scalinghostpoolreference.go @@ -0,0 +1,9 @@ +package scalingplan + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ScalingHostPoolReference struct { + HostPoolArmPath *string `json:"hostPoolArmPath,omitempty"` + ScalingPlanEnabled *bool `json:"scalingPlanEnabled,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/model_scalingplan.go b/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/model_scalingplan.go new file mode 100644 index 00000000000..8b59d34339e --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/model_scalingplan.go @@ -0,0 +1,25 @@ +package scalingplan + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/identity" + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ScalingPlan struct { + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Identity *identity.SystemAssigned `json:"identity,omitempty"` + Kind *string `json:"kind,omitempty"` + Location *string `json:"location,omitempty"` + ManagedBy *string `json:"managedBy,omitempty"` + Name *string `json:"name,omitempty"` + Plan *Plan `json:"plan,omitempty"` + Properties *ScalingPlanProperties `json:"properties,omitempty"` + Sku *Sku `json:"sku,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/model_scalingplanpatch.go b/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/model_scalingplanpatch.go new file mode 100644 index 00000000000..642647709fe --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/model_scalingplanpatch.go @@ -0,0 +1,9 @@ +package scalingplan + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ScalingPlanPatch struct { + Properties *ScalingPlanPatchProperties `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/model_scalingplanpatchproperties.go b/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/model_scalingplanpatchproperties.go new file mode 100644 index 00000000000..393a26bb413 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/model_scalingplanpatchproperties.go @@ -0,0 +1,13 @@ +package scalingplan + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ScalingPlanPatchProperties struct { + Description *string `json:"description,omitempty"` + ExclusionTag *string `json:"exclusionTag,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + HostPoolReferences *[]ScalingHostPoolReference `json:"hostPoolReferences,omitempty"` + Schedules *[]ScalingSchedule `json:"schedules,omitempty"` + TimeZone *string `json:"timeZone,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/model_scalingplanproperties.go b/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/model_scalingplanproperties.go new file mode 100644 index 00000000000..520ed16aa9a --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/model_scalingplanproperties.go @@ -0,0 +1,15 @@ +package scalingplan + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ScalingPlanProperties struct { + Description *string `json:"description,omitempty"` + ExclusionTag *string `json:"exclusionTag,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + HostPoolReferences *[]ScalingHostPoolReference `json:"hostPoolReferences,omitempty"` + HostPoolType *ScalingHostPoolType `json:"hostPoolType,omitempty"` + ObjectId *string `json:"objectId,omitempty"` + Schedules *[]ScalingSchedule `json:"schedules,omitempty"` + TimeZone *string `json:"timeZone,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/model_scalingschedule.go b/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/model_scalingschedule.go new file mode 100644 index 00000000000..313ed8bdf13 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/model_scalingschedule.go @@ -0,0 +1,25 @@ +package scalingplan + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ScalingSchedule struct { + DaysOfWeek *[]DaysOfWeek `json:"daysOfWeek,omitempty"` + Name *string `json:"name,omitempty"` + OffPeakLoadBalancingAlgorithm *SessionHostLoadBalancingAlgorithm `json:"offPeakLoadBalancingAlgorithm,omitempty"` + OffPeakStartTime *Time `json:"offPeakStartTime,omitempty"` + PeakLoadBalancingAlgorithm *SessionHostLoadBalancingAlgorithm `json:"peakLoadBalancingAlgorithm,omitempty"` + PeakStartTime *Time `json:"peakStartTime,omitempty"` + RampDownCapacityThresholdPct *int64 `json:"rampDownCapacityThresholdPct,omitempty"` + RampDownForceLogoffUsers *bool `json:"rampDownForceLogoffUsers,omitempty"` + RampDownLoadBalancingAlgorithm *SessionHostLoadBalancingAlgorithm `json:"rampDownLoadBalancingAlgorithm,omitempty"` + RampDownMinimumHostsPct *int64 `json:"rampDownMinimumHostsPct,omitempty"` + RampDownNotificationMessage *string `json:"rampDownNotificationMessage,omitempty"` + RampDownStartTime *Time `json:"rampDownStartTime,omitempty"` + RampDownStopHostsWhen *StopHostsWhen `json:"rampDownStopHostsWhen,omitempty"` + RampDownWaitTimeMinutes *int64 `json:"rampDownWaitTimeMinutes,omitempty"` + RampUpCapacityThresholdPct *int64 `json:"rampUpCapacityThresholdPct,omitempty"` + RampUpLoadBalancingAlgorithm *SessionHostLoadBalancingAlgorithm `json:"rampUpLoadBalancingAlgorithm,omitempty"` + RampUpMinimumHostsPct *int64 `json:"rampUpMinimumHostsPct,omitempty"` + RampUpStartTime *Time `json:"rampUpStartTime,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/model_sku.go b/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/model_sku.go new file mode 100644 index 00000000000..364fdaef1a0 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/model_sku.go @@ -0,0 +1,12 @@ +package scalingplan + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Sku struct { + Capacity *int64 `json:"capacity,omitempty"` + Family *string `json:"family,omitempty"` + Name string `json:"name"` + Size *string `json:"size,omitempty"` + Tier *SkuTier `json:"tier,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/model_time.go b/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/model_time.go new file mode 100644 index 00000000000..f9e8b6f4484 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/model_time.go @@ -0,0 +1,9 @@ +package scalingplan + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Time struct { + Hour int64 `json:"hour"` + Minute int64 `json:"minute"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/predicates.go b/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/predicates.go new file mode 100644 index 00000000000..7633debe906 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/predicates.go @@ -0,0 +1,44 @@ +package scalingplan + +type ScalingPlanOperationPredicate struct { + Etag *string + Id *string + Kind *string + Location *string + ManagedBy *string + Name *string + Type *string +} + +func (p ScalingPlanOperationPredicate) Matches(input ScalingPlan) bool { + + if p.Etag != nil && (input.Etag == nil && *p.Etag != *input.Etag) { + return false + } + + if p.Id != nil && (input.Id == nil && *p.Id != *input.Id) { + return false + } + + if p.Kind != nil && (input.Kind == nil && *p.Kind != *input.Kind) { + return false + } + + if p.Location != nil && (input.Location == nil && *p.Location != *input.Location) { + return false + } + + if p.ManagedBy != nil && (input.ManagedBy == nil && *p.ManagedBy != *input.ManagedBy) { + return false + } + + if p.Name != nil && (input.Name == nil && *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil && *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/version.go b/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/version.go new file mode 100644 index 00000000000..2e79c42b774 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/scalingplan/version.go @@ -0,0 +1,12 @@ +package scalingplan + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2022-02-10-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/scalingplan/%s", defaultApiVersion) +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/sessionhost/client.go b/resource-manager/desktopvirtualization/2022-02-10-preview/sessionhost/client.go new file mode 100644 index 00000000000..69a79d045fe --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/sessionhost/client.go @@ -0,0 +1,18 @@ +package sessionhost + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SessionHostClient struct { + Client autorest.Client + baseUri string +} + +func NewSessionHostClientWithBaseURI(endpoint string) SessionHostClient { + return SessionHostClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/sessionhost/constants.go b/resource-manager/desktopvirtualization/2022-02-10-preview/sessionhost/constants.go new file mode 100644 index 00000000000..ef4b007d663 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/sessionhost/constants.go @@ -0,0 +1,190 @@ +package sessionhost + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type HealthCheckName string + +const ( + HealthCheckNameAppAttachHealthCheck HealthCheckName = "AppAttachHealthCheck" + HealthCheckNameDomainJoinedCheck HealthCheckName = "DomainJoinedCheck" + HealthCheckNameDomainReachable HealthCheckName = "DomainReachable" + HealthCheckNameDomainTrustCheck HealthCheckName = "DomainTrustCheck" + HealthCheckNameFSLogixHealthCheck HealthCheckName = "FSLogixHealthCheck" + HealthCheckNameMetaDataServiceCheck HealthCheckName = "MetaDataServiceCheck" + HealthCheckNameMonitoringAgentCheck HealthCheckName = "MonitoringAgentCheck" + HealthCheckNameSupportedEncryptionCheck HealthCheckName = "SupportedEncryptionCheck" + HealthCheckNameSxSStackListenerCheck HealthCheckName = "SxSStackListenerCheck" + HealthCheckNameUrlsAccessibleCheck HealthCheckName = "UrlsAccessibleCheck" + HealthCheckNameWebRTCRedirectorCheck HealthCheckName = "WebRTCRedirectorCheck" +) + +func PossibleValuesForHealthCheckName() []string { + return []string{ + string(HealthCheckNameAppAttachHealthCheck), + string(HealthCheckNameDomainJoinedCheck), + string(HealthCheckNameDomainReachable), + string(HealthCheckNameDomainTrustCheck), + string(HealthCheckNameFSLogixHealthCheck), + string(HealthCheckNameMetaDataServiceCheck), + string(HealthCheckNameMonitoringAgentCheck), + string(HealthCheckNameSupportedEncryptionCheck), + string(HealthCheckNameSxSStackListenerCheck), + string(HealthCheckNameUrlsAccessibleCheck), + string(HealthCheckNameWebRTCRedirectorCheck), + } +} + +func parseHealthCheckName(input string) (*HealthCheckName, error) { + vals := map[string]HealthCheckName{ + "appattachhealthcheck": HealthCheckNameAppAttachHealthCheck, + "domainjoinedcheck": HealthCheckNameDomainJoinedCheck, + "domainreachable": HealthCheckNameDomainReachable, + "domaintrustcheck": HealthCheckNameDomainTrustCheck, + "fslogixhealthcheck": HealthCheckNameFSLogixHealthCheck, + "metadataservicecheck": HealthCheckNameMetaDataServiceCheck, + "monitoringagentcheck": HealthCheckNameMonitoringAgentCheck, + "supportedencryptioncheck": HealthCheckNameSupportedEncryptionCheck, + "sxsstacklistenercheck": HealthCheckNameSxSStackListenerCheck, + "urlsaccessiblecheck": HealthCheckNameUrlsAccessibleCheck, + "webrtcredirectorcheck": HealthCheckNameWebRTCRedirectorCheck, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := HealthCheckName(input) + return &out, nil +} + +type HealthCheckResult string + +const ( + HealthCheckResultHealthCheckFailed HealthCheckResult = "HealthCheckFailed" + HealthCheckResultHealthCheckSucceeded HealthCheckResult = "HealthCheckSucceeded" + HealthCheckResultSessionHostShutdown HealthCheckResult = "SessionHostShutdown" + HealthCheckResultUnknown HealthCheckResult = "Unknown" +) + +func PossibleValuesForHealthCheckResult() []string { + return []string{ + string(HealthCheckResultHealthCheckFailed), + string(HealthCheckResultHealthCheckSucceeded), + string(HealthCheckResultSessionHostShutdown), + string(HealthCheckResultUnknown), + } +} + +func parseHealthCheckResult(input string) (*HealthCheckResult, error) { + vals := map[string]HealthCheckResult{ + "healthcheckfailed": HealthCheckResultHealthCheckFailed, + "healthchecksucceeded": HealthCheckResultHealthCheckSucceeded, + "sessionhostshutdown": HealthCheckResultSessionHostShutdown, + "unknown": HealthCheckResultUnknown, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := HealthCheckResult(input) + return &out, nil +} + +type Status string + +const ( + StatusAvailable Status = "Available" + StatusDisconnected Status = "Disconnected" + StatusDomainTrustRelationshipLost Status = "DomainTrustRelationshipLost" + StatusFSLogixNotHealthy Status = "FSLogixNotHealthy" + StatusNeedsAssistance Status = "NeedsAssistance" + StatusNoHeartbeat Status = "NoHeartbeat" + StatusNotJoinedToDomain Status = "NotJoinedToDomain" + StatusShutdown Status = "Shutdown" + StatusSxSStackListenerNotReady Status = "SxSStackListenerNotReady" + StatusUnavailable Status = "Unavailable" + StatusUpgradeFailed Status = "UpgradeFailed" + StatusUpgrading Status = "Upgrading" +) + +func PossibleValuesForStatus() []string { + return []string{ + string(StatusAvailable), + string(StatusDisconnected), + string(StatusDomainTrustRelationshipLost), + string(StatusFSLogixNotHealthy), + string(StatusNeedsAssistance), + string(StatusNoHeartbeat), + string(StatusNotJoinedToDomain), + string(StatusShutdown), + string(StatusSxSStackListenerNotReady), + string(StatusUnavailable), + string(StatusUpgradeFailed), + string(StatusUpgrading), + } +} + +func parseStatus(input string) (*Status, error) { + vals := map[string]Status{ + "available": StatusAvailable, + "disconnected": StatusDisconnected, + "domaintrustrelationshiplost": StatusDomainTrustRelationshipLost, + "fslogixnothealthy": StatusFSLogixNotHealthy, + "needsassistance": StatusNeedsAssistance, + "noheartbeat": StatusNoHeartbeat, + "notjoinedtodomain": StatusNotJoinedToDomain, + "shutdown": StatusShutdown, + "sxsstacklistenernotready": StatusSxSStackListenerNotReady, + "unavailable": StatusUnavailable, + "upgradefailed": StatusUpgradeFailed, + "upgrading": StatusUpgrading, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Status(input) + return &out, nil +} + +type UpdateState string + +const ( + UpdateStateFailed UpdateState = "Failed" + UpdateStateInitial UpdateState = "Initial" + UpdateStatePending UpdateState = "Pending" + UpdateStateStarted UpdateState = "Started" + UpdateStateSucceeded UpdateState = "Succeeded" +) + +func PossibleValuesForUpdateState() []string { + return []string{ + string(UpdateStateFailed), + string(UpdateStateInitial), + string(UpdateStatePending), + string(UpdateStateStarted), + string(UpdateStateSucceeded), + } +} + +func parseUpdateState(input string) (*UpdateState, error) { + vals := map[string]UpdateState{ + "failed": UpdateStateFailed, + "initial": UpdateStateInitial, + "pending": UpdateStatePending, + "started": UpdateStateStarted, + "succeeded": UpdateStateSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := UpdateState(input) + return &out, nil +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/sessionhost/id_hostpool.go b/resource-manager/desktopvirtualization/2022-02-10-preview/sessionhost/id_hostpool.go new file mode 100644 index 00000000000..b42dea32fb0 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/sessionhost/id_hostpool.go @@ -0,0 +1,124 @@ +package sessionhost + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = HostPoolId{} + +// HostPoolId is a struct representing the Resource ID for a Host Pool +type HostPoolId struct { + SubscriptionId string + ResourceGroupName string + HostPoolName string +} + +// NewHostPoolID returns a new HostPoolId struct +func NewHostPoolID(subscriptionId string, resourceGroupName string, hostPoolName string) HostPoolId { + return HostPoolId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + HostPoolName: hostPoolName, + } +} + +// ParseHostPoolID parses 'input' into a HostPoolId +func ParseHostPoolID(input string) (*HostPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(HostPoolId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := HostPoolId{} + + 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.HostPoolName, ok = parsed.Parsed["hostPoolName"]; !ok { + return nil, fmt.Errorf("the segment 'hostPoolName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseHostPoolIDInsensitively parses 'input' case-insensitively into a HostPoolId +// note: this method should only be used for API response data and not user input +func ParseHostPoolIDInsensitively(input string) (*HostPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(HostPoolId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := HostPoolId{} + + 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.HostPoolName, ok = parsed.Parsed["hostPoolName"]; !ok { + return nil, fmt.Errorf("the segment 'hostPoolName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateHostPoolID checks that 'input' can be parsed as a Host Pool ID +func ValidateHostPoolID(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 := ParseHostPoolID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Host Pool ID +func (id HostPoolId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DesktopVirtualization/hostPools/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.HostPoolName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Host Pool ID +func (id HostPoolId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftDesktopVirtualization", "Microsoft.DesktopVirtualization", "Microsoft.DesktopVirtualization"), + resourceids.StaticSegment("staticHostPools", "hostPools", "hostPools"), + resourceids.UserSpecifiedSegment("hostPoolName", "hostPoolValue"), + } +} + +// String returns a human-readable description of this Host Pool ID +func (id HostPoolId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Host Pool Name: %q", id.HostPoolName), + } + return fmt.Sprintf("Host Pool (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/sessionhost/id_hostpool_test.go b/resource-manager/desktopvirtualization/2022-02-10-preview/sessionhost/id_hostpool_test.go new file mode 100644 index 00000000000..32838d09b91 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/sessionhost/id_hostpool_test.go @@ -0,0 +1,279 @@ +package sessionhost + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = HostPoolId{} + +func TestNewHostPoolID(t *testing.T) { + id := NewHostPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "hostPoolValue") + + 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.HostPoolName != "hostPoolValue" { + t.Fatalf("Expected %q but got %q for Segment 'HostPoolName'", id.HostPoolName, "hostPoolValue") + } +} + +func TestFormatHostPoolID(t *testing.T) { + actual := NewHostPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "hostPoolValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseHostPoolID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *HostPoolId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue", + Expected: &HostPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + HostPoolName: "hostPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseHostPoolID(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.HostPoolName != v.Expected.HostPoolName { + t.Fatalf("Expected %q but got %q for HostPoolName", v.Expected.HostPoolName, actual.HostPoolName) + } + + } +} + +func TestParseHostPoolIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *HostPoolId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue", + Expected: &HostPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + HostPoolName: "hostPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe", + Expected: &HostPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + HostPoolName: "hOsTpOoLvAlUe", + }, + }, + { + // 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.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseHostPoolIDInsensitively(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.HostPoolName != v.Expected.HostPoolName { + t.Fatalf("Expected %q but got %q for HostPoolName", v.Expected.HostPoolName, actual.HostPoolName) + } + + } +} + +func TestSegmentsForHostPoolId(t *testing.T) { + segments := HostPoolId{}.Segments() + if len(segments) == 0 { + t.Fatalf("HostPoolId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/sessionhost/id_sessionhost.go b/resource-manager/desktopvirtualization/2022-02-10-preview/sessionhost/id_sessionhost.go new file mode 100644 index 00000000000..cd3fe90122c --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/sessionhost/id_sessionhost.go @@ -0,0 +1,137 @@ +package sessionhost + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = SessionHostId{} + +// SessionHostId is a struct representing the Resource ID for a Session Host +type SessionHostId struct { + SubscriptionId string + ResourceGroupName string + HostPoolName string + SessionHostName string +} + +// NewSessionHostID returns a new SessionHostId struct +func NewSessionHostID(subscriptionId string, resourceGroupName string, hostPoolName string, sessionHostName string) SessionHostId { + return SessionHostId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + HostPoolName: hostPoolName, + SessionHostName: sessionHostName, + } +} + +// ParseSessionHostID parses 'input' into a SessionHostId +func ParseSessionHostID(input string) (*SessionHostId, error) { + parser := resourceids.NewParserFromResourceIdType(SessionHostId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := SessionHostId{} + + 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.HostPoolName, ok = parsed.Parsed["hostPoolName"]; !ok { + return nil, fmt.Errorf("the segment 'hostPoolName' was not found in the resource id %q", input) + } + + if id.SessionHostName, ok = parsed.Parsed["sessionHostName"]; !ok { + return nil, fmt.Errorf("the segment 'sessionHostName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseSessionHostIDInsensitively parses 'input' case-insensitively into a SessionHostId +// note: this method should only be used for API response data and not user input +func ParseSessionHostIDInsensitively(input string) (*SessionHostId, error) { + parser := resourceids.NewParserFromResourceIdType(SessionHostId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := SessionHostId{} + + 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.HostPoolName, ok = parsed.Parsed["hostPoolName"]; !ok { + return nil, fmt.Errorf("the segment 'hostPoolName' was not found in the resource id %q", input) + } + + if id.SessionHostName, ok = parsed.Parsed["sessionHostName"]; !ok { + return nil, fmt.Errorf("the segment 'sessionHostName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateSessionHostID checks that 'input' can be parsed as a Session Host ID +func ValidateSessionHostID(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 := ParseSessionHostID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Session Host ID +func (id SessionHostId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DesktopVirtualization/hostPools/%s/sessionHosts/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.HostPoolName, id.SessionHostName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Session Host ID +func (id SessionHostId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftDesktopVirtualization", "Microsoft.DesktopVirtualization", "Microsoft.DesktopVirtualization"), + resourceids.StaticSegment("staticHostPools", "hostPools", "hostPools"), + resourceids.UserSpecifiedSegment("hostPoolName", "hostPoolValue"), + resourceids.StaticSegment("staticSessionHosts", "sessionHosts", "sessionHosts"), + resourceids.UserSpecifiedSegment("sessionHostName", "sessionHostValue"), + } +} + +// String returns a human-readable description of this Session Host ID +func (id SessionHostId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Host Pool Name: %q", id.HostPoolName), + fmt.Sprintf("Session Host Name: %q", id.SessionHostName), + } + return fmt.Sprintf("Session Host (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/sessionhost/id_sessionhost_test.go b/resource-manager/desktopvirtualization/2022-02-10-preview/sessionhost/id_sessionhost_test.go new file mode 100644 index 00000000000..3e279eebe25 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/sessionhost/id_sessionhost_test.go @@ -0,0 +1,324 @@ +package sessionhost + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = SessionHostId{} + +func TestNewSessionHostID(t *testing.T) { + id := NewSessionHostID("12345678-1234-9876-4563-123456789012", "example-resource-group", "hostPoolValue", "sessionHostValue") + + 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.HostPoolName != "hostPoolValue" { + t.Fatalf("Expected %q but got %q for Segment 'HostPoolName'", id.HostPoolName, "hostPoolValue") + } + + if id.SessionHostName != "sessionHostValue" { + t.Fatalf("Expected %q but got %q for Segment 'SessionHostName'", id.SessionHostName, "sessionHostValue") + } +} + +func TestFormatSessionHostID(t *testing.T) { + actual := NewSessionHostID("12345678-1234-9876-4563-123456789012", "example-resource-group", "hostPoolValue", "sessionHostValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/sessionHosts/sessionHostValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseSessionHostID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SessionHostId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/sessionHosts", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/sessionHosts/sessionHostValue", + Expected: &SessionHostId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + HostPoolName: "hostPoolValue", + SessionHostName: "sessionHostValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/sessionHosts/sessionHostValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSessionHostID(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.HostPoolName != v.Expected.HostPoolName { + t.Fatalf("Expected %q but got %q for HostPoolName", v.Expected.HostPoolName, actual.HostPoolName) + } + + if actual.SessionHostName != v.Expected.SessionHostName { + t.Fatalf("Expected %q but got %q for SessionHostName", v.Expected.SessionHostName, actual.SessionHostName) + } + + } +} + +func TestParseSessionHostIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SessionHostId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/sessionHosts", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe/sEsSiOnHoStS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/sessionHosts/sessionHostValue", + Expected: &SessionHostId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + HostPoolName: "hostPoolValue", + SessionHostName: "sessionHostValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/sessionHosts/sessionHostValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe/sEsSiOnHoStS/sEsSiOnHoStVaLuE", + Expected: &SessionHostId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + HostPoolName: "hOsTpOoLvAlUe", + SessionHostName: "sEsSiOnHoStVaLuE", + }, + }, + { + // 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.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe/sEsSiOnHoStS/sEsSiOnHoStVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSessionHostIDInsensitively(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.HostPoolName != v.Expected.HostPoolName { + t.Fatalf("Expected %q but got %q for HostPoolName", v.Expected.HostPoolName, actual.HostPoolName) + } + + if actual.SessionHostName != v.Expected.SessionHostName { + t.Fatalf("Expected %q but got %q for SessionHostName", v.Expected.SessionHostName, actual.SessionHostName) + } + + } +} + +func TestSegmentsForSessionHostId(t *testing.T) { + segments := SessionHostId{}.Segments() + if len(segments) == 0 { + t.Fatalf("SessionHostId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/sessionhost/method_delete_autorest.go b/resource-manager/desktopvirtualization/2022-02-10-preview/sessionhost/method_delete_autorest.go new file mode 100644 index 00000000000..3eb9fdf7cf7 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/sessionhost/method_delete_autorest.go @@ -0,0 +1,94 @@ +package sessionhost + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response +} + +type DeleteOperationOptions struct { + Force *bool +} + +func DefaultDeleteOperationOptions() DeleteOperationOptions { + return DeleteOperationOptions{} +} + +func (o DeleteOperationOptions) toHeaders() map[string]interface{} { + out := make(map[string]interface{}) + + return out +} + +func (o DeleteOperationOptions) toQueryString() map[string]interface{} { + out := make(map[string]interface{}) + + if o.Force != nil { + out["force"] = *o.Force + } + + return out +} + +// Delete ... +func (c SessionHostClient) Delete(ctx context.Context, id SessionHostId, options DeleteOperationOptions) (result DeleteOperationResponse, err error) { + req, err := c.preparerForDelete(ctx, id, options) + if err != nil { + err = autorest.NewErrorWithError(err, "sessionhost.SessionHostClient", "Delete", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "sessionhost.SessionHostClient", "Delete", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForDelete(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "sessionhost.SessionHostClient", "Delete", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForDelete prepares the Delete request. +func (c SessionHostClient) preparerForDelete(ctx context.Context, id SessionHostId, options DeleteOperationOptions) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + for k, v := range options.toQueryString() { + queryParameters[k] = autorest.Encode("query", v) + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsDelete(), + autorest.WithBaseURL(c.baseUri), + autorest.WithHeaders(options.toHeaders()), + 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 SessionHostClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/sessionhost/method_get_autorest.go b/resource-manager/desktopvirtualization/2022-02-10-preview/sessionhost/method_get_autorest.go new file mode 100644 index 00000000000..e28f5b328c6 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/sessionhost/method_get_autorest.go @@ -0,0 +1,67 @@ +package sessionhost + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *SessionHost +} + +// Get ... +func (c SessionHostClient) Get(ctx context.Context, id SessionHostId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "sessionhost.SessionHostClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "sessionhost.SessionHostClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "sessionhost.SessionHostClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c SessionHostClient) preparerForGet(ctx context.Context, id SessionHostId) (*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 SessionHostClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/sessionhost/method_list_autorest.go b/resource-manager/desktopvirtualization/2022-02-10-preview/sessionhost/method_list_autorest.go new file mode 100644 index 00000000000..5d42759afa6 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/sessionhost/method_list_autorest.go @@ -0,0 +1,186 @@ +package sessionhost + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + Model *[]SessionHost + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) +} + +type ListCompleteResult struct { + Items []SessionHost +} + +func (r ListOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// List ... +func (c SessionHostClient) List(ctx context.Context, id HostPoolId) (resp ListOperationResponse, err error) { + req, err := c.preparerForList(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "sessionhost.SessionHostClient", "List", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "sessionhost.SessionHostClient", "List", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForList(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "sessionhost.SessionHostClient", "List", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// ListComplete retrieves all of the results into a single object +func (c SessionHostClient) ListComplete(ctx context.Context, id HostPoolId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, SessionHostOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c SessionHostClient) ListCompleteMatchingPredicate(ctx context.Context, id HostPoolId, predicate SessionHostOperationPredicate) (resp ListCompleteResult, err error) { + items := make([]SessionHost, 0) + + page, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListCompleteResult{ + Items: items, + } + return out, nil +} + +// preparerForList prepares the List request. +func (c SessionHostClient) preparerForList(ctx context.Context, id HostPoolId) (*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/sessionHosts", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListWithNextLink prepares the List request with the given nextLink token. +func (c SessionHostClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForList handles the response to the List request. The method always +// closes the http.Response Body. +func (c SessionHostClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { + type page struct { + Values []SessionHost `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { + req, err := c.preparerForListWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "sessionhost.SessionHostClient", "List", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "sessionhost.SessionHostClient", "List", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "sessionhost.SessionHostClient", "List", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/sessionhost/method_update_autorest.go b/resource-manager/desktopvirtualization/2022-02-10-preview/sessionhost/method_update_autorest.go new file mode 100644 index 00000000000..8036bc4eb72 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/sessionhost/method_update_autorest.go @@ -0,0 +1,97 @@ +package sessionhost + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + HttpResponse *http.Response + Model *SessionHost +} + +type UpdateOperationOptions struct { + Force *bool +} + +func DefaultUpdateOperationOptions() UpdateOperationOptions { + return UpdateOperationOptions{} +} + +func (o UpdateOperationOptions) toHeaders() map[string]interface{} { + out := make(map[string]interface{}) + + return out +} + +func (o UpdateOperationOptions) toQueryString() map[string]interface{} { + out := make(map[string]interface{}) + + if o.Force != nil { + out["force"] = *o.Force + } + + return out +} + +// Update ... +func (c SessionHostClient) Update(ctx context.Context, id SessionHostId, input SessionHostPatch, options UpdateOperationOptions) (result UpdateOperationResponse, err error) { + req, err := c.preparerForUpdate(ctx, id, input, options) + if err != nil { + err = autorest.NewErrorWithError(err, "sessionhost.SessionHostClient", "Update", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "sessionhost.SessionHostClient", "Update", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForUpdate(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "sessionhost.SessionHostClient", "Update", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForUpdate prepares the Update request. +func (c SessionHostClient) preparerForUpdate(ctx context.Context, id SessionHostId, input SessionHostPatch, options UpdateOperationOptions) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + for k, v := range options.toQueryString() { + queryParameters[k] = autorest.Encode("query", v) + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPatch(), + autorest.WithBaseURL(c.baseUri), + autorest.WithHeaders(options.toHeaders()), + 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 SessionHostClient) responderForUpdate(resp *http.Response) (result UpdateOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/sessionhost/model_sessionhost.go b/resource-manager/desktopvirtualization/2022-02-10-preview/sessionhost/model_sessionhost.go new file mode 100644 index 00000000000..6a59b593c4c --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/sessionhost/model_sessionhost.go @@ -0,0 +1,16 @@ +package sessionhost + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SessionHost struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *SessionHostProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/sessionhost/model_sessionhosthealthcheckfailuredetails.go b/resource-manager/desktopvirtualization/2022-02-10-preview/sessionhost/model_sessionhosthealthcheckfailuredetails.go new file mode 100644 index 00000000000..e2430e721a2 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/sessionhost/model_sessionhosthealthcheckfailuredetails.go @@ -0,0 +1,28 @@ +package sessionhost + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SessionHostHealthCheckFailureDetails struct { + ErrorCode *int64 `json:"errorCode,omitempty"` + LastHealthCheckDateTime *string `json:"lastHealthCheckDateTime,omitempty"` + Message *string `json:"message,omitempty"` +} + +func (o *SessionHostHealthCheckFailureDetails) GetLastHealthCheckDateTimeAsTime() (*time.Time, error) { + if o.LastHealthCheckDateTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastHealthCheckDateTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *SessionHostHealthCheckFailureDetails) SetLastHealthCheckDateTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastHealthCheckDateTime = &formatted +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/sessionhost/model_sessionhosthealthcheckreport.go b/resource-manager/desktopvirtualization/2022-02-10-preview/sessionhost/model_sessionhosthealthcheckreport.go new file mode 100644 index 00000000000..6545cf0a038 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/sessionhost/model_sessionhosthealthcheckreport.go @@ -0,0 +1,10 @@ +package sessionhost + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SessionHostHealthCheckReport struct { + AdditionalFailureDetails *SessionHostHealthCheckFailureDetails `json:"additionalFailureDetails,omitempty"` + HealthCheckName *HealthCheckName `json:"healthCheckName,omitempty"` + HealthCheckResult *HealthCheckResult `json:"healthCheckResult,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/sessionhost/model_sessionhostpatch.go b/resource-manager/desktopvirtualization/2022-02-10-preview/sessionhost/model_sessionhostpatch.go new file mode 100644 index 00000000000..f8fa6a57624 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/sessionhost/model_sessionhostpatch.go @@ -0,0 +1,11 @@ +package sessionhost + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SessionHostPatch struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *SessionHostPatchProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/sessionhost/model_sessionhostpatchproperties.go b/resource-manager/desktopvirtualization/2022-02-10-preview/sessionhost/model_sessionhostpatchproperties.go new file mode 100644 index 00000000000..d4286285575 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/sessionhost/model_sessionhostpatchproperties.go @@ -0,0 +1,10 @@ +package sessionhost + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SessionHostPatchProperties struct { + AllowNewSession *bool `json:"allowNewSession,omitempty"` + AssignedUser *string `json:"assignedUser,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/sessionhost/model_sessionhostproperties.go b/resource-manager/desktopvirtualization/2022-02-10-preview/sessionhost/model_sessionhostproperties.go new file mode 100644 index 00000000000..76792b5d7f4 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/sessionhost/model_sessionhostproperties.go @@ -0,0 +1,66 @@ +package sessionhost + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SessionHostProperties struct { + AgentVersion *string `json:"agentVersion,omitempty"` + AllowNewSession *bool `json:"allowNewSession,omitempty"` + AssignedUser *string `json:"assignedUser,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + LastHeartBeat *string `json:"lastHeartBeat,omitempty"` + LastUpdateTime *string `json:"lastUpdateTime,omitempty"` + ObjectId *string `json:"objectId,omitempty"` + OsVersion *string `json:"osVersion,omitempty"` + ResourceId *string `json:"resourceId,omitempty"` + SessionHostHealthCheckResults *[]SessionHostHealthCheckReport `json:"sessionHostHealthCheckResults,omitempty"` + Sessions *int64 `json:"sessions,omitempty"` + Status *Status `json:"status,omitempty"` + StatusTimestamp *string `json:"statusTimestamp,omitempty"` + SxSStackVersion *string `json:"sxSStackVersion,omitempty"` + UpdateErrorMessage *string `json:"updateErrorMessage,omitempty"` + UpdateState *UpdateState `json:"updateState,omitempty"` + VirtualMachineId *string `json:"virtualMachineId,omitempty"` +} + +func (o *SessionHostProperties) GetLastHeartBeatAsTime() (*time.Time, error) { + if o.LastHeartBeat == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastHeartBeat, "2006-01-02T15:04:05Z07:00") +} + +func (o *SessionHostProperties) SetLastHeartBeatAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastHeartBeat = &formatted +} + +func (o *SessionHostProperties) GetLastUpdateTimeAsTime() (*time.Time, error) { + if o.LastUpdateTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastUpdateTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *SessionHostProperties) SetLastUpdateTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastUpdateTime = &formatted +} + +func (o *SessionHostProperties) GetStatusTimestampAsTime() (*time.Time, error) { + if o.StatusTimestamp == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StatusTimestamp, "2006-01-02T15:04:05Z07:00") +} + +func (o *SessionHostProperties) SetStatusTimestampAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StatusTimestamp = &formatted +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/sessionhost/predicates.go b/resource-manager/desktopvirtualization/2022-02-10-preview/sessionhost/predicates.go new file mode 100644 index 00000000000..e1112a03be0 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/sessionhost/predicates.go @@ -0,0 +1,24 @@ +package sessionhost + +type SessionHostOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p SessionHostOperationPredicate) Matches(input SessionHost) bool { + + if p.Id != nil && (input.Id == nil && *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil && *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil && *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/sessionhost/version.go b/resource-manager/desktopvirtualization/2022-02-10-preview/sessionhost/version.go new file mode 100644 index 00000000000..083d3bb712a --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/sessionhost/version.go @@ -0,0 +1,12 @@ +package sessionhost + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2022-02-10-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/sessionhost/%s", defaultApiVersion) +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/startmenuitem/client.go b/resource-manager/desktopvirtualization/2022-02-10-preview/startmenuitem/client.go new file mode 100644 index 00000000000..4747b663da8 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/startmenuitem/client.go @@ -0,0 +1,18 @@ +package startmenuitem + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StartMenuItemClient struct { + Client autorest.Client + baseUri string +} + +func NewStartMenuItemClientWithBaseURI(endpoint string) StartMenuItemClient { + return StartMenuItemClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/startmenuitem/id_applicationgroup.go b/resource-manager/desktopvirtualization/2022-02-10-preview/startmenuitem/id_applicationgroup.go new file mode 100644 index 00000000000..fed7e31f354 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/startmenuitem/id_applicationgroup.go @@ -0,0 +1,124 @@ +package startmenuitem + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = ApplicationGroupId{} + +// ApplicationGroupId is a struct representing the Resource ID for a Application Group +type ApplicationGroupId struct { + SubscriptionId string + ResourceGroupName string + ApplicationGroupName string +} + +// NewApplicationGroupID returns a new ApplicationGroupId struct +func NewApplicationGroupID(subscriptionId string, resourceGroupName string, applicationGroupName string) ApplicationGroupId { + return ApplicationGroupId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ApplicationGroupName: applicationGroupName, + } +} + +// ParseApplicationGroupID parses 'input' into a ApplicationGroupId +func ParseApplicationGroupID(input string) (*ApplicationGroupId, error) { + parser := resourceids.NewParserFromResourceIdType(ApplicationGroupId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ApplicationGroupId{} + + 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.ApplicationGroupName, ok = parsed.Parsed["applicationGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'applicationGroupName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseApplicationGroupIDInsensitively parses 'input' case-insensitively into a ApplicationGroupId +// note: this method should only be used for API response data and not user input +func ParseApplicationGroupIDInsensitively(input string) (*ApplicationGroupId, error) { + parser := resourceids.NewParserFromResourceIdType(ApplicationGroupId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ApplicationGroupId{} + + 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.ApplicationGroupName, ok = parsed.Parsed["applicationGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'applicationGroupName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateApplicationGroupID checks that 'input' can be parsed as a Application Group ID +func ValidateApplicationGroupID(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 := ParseApplicationGroupID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Application Group ID +func (id ApplicationGroupId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DesktopVirtualization/applicationGroups/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ApplicationGroupName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Application Group ID +func (id ApplicationGroupId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftDesktopVirtualization", "Microsoft.DesktopVirtualization", "Microsoft.DesktopVirtualization"), + resourceids.StaticSegment("staticApplicationGroups", "applicationGroups", "applicationGroups"), + resourceids.UserSpecifiedSegment("applicationGroupName", "applicationGroupValue"), + } +} + +// String returns a human-readable description of this Application Group ID +func (id ApplicationGroupId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Application Group Name: %q", id.ApplicationGroupName), + } + return fmt.Sprintf("Application Group (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/startmenuitem/id_applicationgroup_test.go b/resource-manager/desktopvirtualization/2022-02-10-preview/startmenuitem/id_applicationgroup_test.go new file mode 100644 index 00000000000..918a617083d --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/startmenuitem/id_applicationgroup_test.go @@ -0,0 +1,279 @@ +package startmenuitem + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = ApplicationGroupId{} + +func TestNewApplicationGroupID(t *testing.T) { + id := NewApplicationGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "applicationGroupValue") + + 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.ApplicationGroupName != "applicationGroupValue" { + t.Fatalf("Expected %q but got %q for Segment 'ApplicationGroupName'", id.ApplicationGroupName, "applicationGroupValue") + } +} + +func TestFormatApplicationGroupID(t *testing.T) { + actual := NewApplicationGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "applicationGroupValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseApplicationGroupID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApplicationGroupId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue", + Expected: &ApplicationGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ApplicationGroupName: "applicationGroupValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApplicationGroupID(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.ApplicationGroupName != v.Expected.ApplicationGroupName { + t.Fatalf("Expected %q but got %q for ApplicationGroupName", v.Expected.ApplicationGroupName, actual.ApplicationGroupName) + } + + } +} + +func TestParseApplicationGroupIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApplicationGroupId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/aPpLiCaTiOnGrOuPs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue", + Expected: &ApplicationGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ApplicationGroupName: "applicationGroupValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/applicationGroups/applicationGroupValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/aPpLiCaTiOnGrOuPs/aPpLiCaTiOnGrOuPvAlUe", + Expected: &ApplicationGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ApplicationGroupName: "aPpLiCaTiOnGrOuPvAlUe", + }, + }, + { + // 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.dEsKtOpViRtUaLiZaTiOn/aPpLiCaTiOnGrOuPs/aPpLiCaTiOnGrOuPvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApplicationGroupIDInsensitively(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.ApplicationGroupName != v.Expected.ApplicationGroupName { + t.Fatalf("Expected %q but got %q for ApplicationGroupName", v.Expected.ApplicationGroupName, actual.ApplicationGroupName) + } + + } +} + +func TestSegmentsForApplicationGroupId(t *testing.T) { + segments := ApplicationGroupId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ApplicationGroupId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/startmenuitem/method_list_autorest.go b/resource-manager/desktopvirtualization/2022-02-10-preview/startmenuitem/method_list_autorest.go new file mode 100644 index 00000000000..360dbd9437e --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/startmenuitem/method_list_autorest.go @@ -0,0 +1,186 @@ +package startmenuitem + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + Model *[]StartMenuItem + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) +} + +type ListCompleteResult struct { + Items []StartMenuItem +} + +func (r ListOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// List ... +func (c StartMenuItemClient) List(ctx context.Context, id ApplicationGroupId) (resp ListOperationResponse, err error) { + req, err := c.preparerForList(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "startmenuitem.StartMenuItemClient", "List", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "startmenuitem.StartMenuItemClient", "List", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForList(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "startmenuitem.StartMenuItemClient", "List", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// ListComplete retrieves all of the results into a single object +func (c StartMenuItemClient) ListComplete(ctx context.Context, id ApplicationGroupId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, StartMenuItemOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c StartMenuItemClient) ListCompleteMatchingPredicate(ctx context.Context, id ApplicationGroupId, predicate StartMenuItemOperationPredicate) (resp ListCompleteResult, err error) { + items := make([]StartMenuItem, 0) + + page, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListCompleteResult{ + Items: items, + } + return out, nil +} + +// preparerForList prepares the List request. +func (c StartMenuItemClient) preparerForList(ctx context.Context, id ApplicationGroupId) (*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/startMenuItems", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListWithNextLink prepares the List request with the given nextLink token. +func (c StartMenuItemClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForList handles the response to the List request. The method always +// closes the http.Response Body. +func (c StartMenuItemClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { + type page struct { + Values []StartMenuItem `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { + req, err := c.preparerForListWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "startmenuitem.StartMenuItemClient", "List", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "startmenuitem.StartMenuItemClient", "List", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "startmenuitem.StartMenuItemClient", "List", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/startmenuitem/model_startmenuitem.go b/resource-manager/desktopvirtualization/2022-02-10-preview/startmenuitem/model_startmenuitem.go new file mode 100644 index 00000000000..966f16fd06f --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/startmenuitem/model_startmenuitem.go @@ -0,0 +1,11 @@ +package startmenuitem + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StartMenuItem struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *StartMenuItemProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/startmenuitem/model_startmenuitemproperties.go b/resource-manager/desktopvirtualization/2022-02-10-preview/startmenuitem/model_startmenuitemproperties.go new file mode 100644 index 00000000000..53a69769271 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/startmenuitem/model_startmenuitemproperties.go @@ -0,0 +1,12 @@ +package startmenuitem + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StartMenuItemProperties struct { + AppAlias *string `json:"appAlias,omitempty"` + CommandLineArguments *string `json:"commandLineArguments,omitempty"` + FilePath *string `json:"filePath,omitempty"` + IconIndex *int64 `json:"iconIndex,omitempty"` + IconPath *string `json:"iconPath,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/startmenuitem/predicates.go b/resource-manager/desktopvirtualization/2022-02-10-preview/startmenuitem/predicates.go new file mode 100644 index 00000000000..e1ee24542dd --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/startmenuitem/predicates.go @@ -0,0 +1,24 @@ +package startmenuitem + +type StartMenuItemOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p StartMenuItemOperationPredicate) Matches(input StartMenuItem) bool { + + if p.Id != nil && (input.Id == nil && *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil && *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil && *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/startmenuitem/version.go b/resource-manager/desktopvirtualization/2022-02-10-preview/startmenuitem/version.go new file mode 100644 index 00000000000..8fd996cf77f --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/startmenuitem/version.go @@ -0,0 +1,12 @@ +package startmenuitem + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2022-02-10-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/startmenuitem/%s", defaultApiVersion) +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/usersession/client.go b/resource-manager/desktopvirtualization/2022-02-10-preview/usersession/client.go new file mode 100644 index 00000000000..3f58916e0ce --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/usersession/client.go @@ -0,0 +1,18 @@ +package usersession + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UserSessionClient struct { + Client autorest.Client + baseUri string +} + +func NewUserSessionClientWithBaseURI(endpoint string) UserSessionClient { + return UserSessionClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/usersession/constants.go b/resource-manager/desktopvirtualization/2022-02-10-preview/usersession/constants.go new file mode 100644 index 00000000000..7a32115a7e0 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/usersession/constants.go @@ -0,0 +1,74 @@ +package usersession + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApplicationType string + +const ( + ApplicationTypeDesktop ApplicationType = "Desktop" + ApplicationTypeRemoteApp ApplicationType = "RemoteApp" +) + +func PossibleValuesForApplicationType() []string { + return []string{ + string(ApplicationTypeDesktop), + string(ApplicationTypeRemoteApp), + } +} + +func parseApplicationType(input string) (*ApplicationType, error) { + vals := map[string]ApplicationType{ + "desktop": ApplicationTypeDesktop, + "remoteapp": ApplicationTypeRemoteApp, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ApplicationType(input) + return &out, nil +} + +type SessionState string + +const ( + SessionStateActive SessionState = "Active" + SessionStateDisconnected SessionState = "Disconnected" + SessionStateLogOff SessionState = "LogOff" + SessionStatePending SessionState = "Pending" + SessionStateUnknown SessionState = "Unknown" + SessionStateUserProfileDiskMounted SessionState = "UserProfileDiskMounted" +) + +func PossibleValuesForSessionState() []string { + return []string{ + string(SessionStateActive), + string(SessionStateDisconnected), + string(SessionStateLogOff), + string(SessionStatePending), + string(SessionStateUnknown), + string(SessionStateUserProfileDiskMounted), + } +} + +func parseSessionState(input string) (*SessionState, error) { + vals := map[string]SessionState{ + "active": SessionStateActive, + "disconnected": SessionStateDisconnected, + "logoff": SessionStateLogOff, + "pending": SessionStatePending, + "unknown": SessionStateUnknown, + "userprofilediskmounted": SessionStateUserProfileDiskMounted, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SessionState(input) + return &out, nil +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/usersession/id_hostpool.go b/resource-manager/desktopvirtualization/2022-02-10-preview/usersession/id_hostpool.go new file mode 100644 index 00000000000..b67dbb68b32 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/usersession/id_hostpool.go @@ -0,0 +1,124 @@ +package usersession + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = HostPoolId{} + +// HostPoolId is a struct representing the Resource ID for a Host Pool +type HostPoolId struct { + SubscriptionId string + ResourceGroupName string + HostPoolName string +} + +// NewHostPoolID returns a new HostPoolId struct +func NewHostPoolID(subscriptionId string, resourceGroupName string, hostPoolName string) HostPoolId { + return HostPoolId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + HostPoolName: hostPoolName, + } +} + +// ParseHostPoolID parses 'input' into a HostPoolId +func ParseHostPoolID(input string) (*HostPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(HostPoolId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := HostPoolId{} + + 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.HostPoolName, ok = parsed.Parsed["hostPoolName"]; !ok { + return nil, fmt.Errorf("the segment 'hostPoolName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseHostPoolIDInsensitively parses 'input' case-insensitively into a HostPoolId +// note: this method should only be used for API response data and not user input +func ParseHostPoolIDInsensitively(input string) (*HostPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(HostPoolId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := HostPoolId{} + + 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.HostPoolName, ok = parsed.Parsed["hostPoolName"]; !ok { + return nil, fmt.Errorf("the segment 'hostPoolName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateHostPoolID checks that 'input' can be parsed as a Host Pool ID +func ValidateHostPoolID(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 := ParseHostPoolID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Host Pool ID +func (id HostPoolId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DesktopVirtualization/hostPools/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.HostPoolName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Host Pool ID +func (id HostPoolId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftDesktopVirtualization", "Microsoft.DesktopVirtualization", "Microsoft.DesktopVirtualization"), + resourceids.StaticSegment("staticHostPools", "hostPools", "hostPools"), + resourceids.UserSpecifiedSegment("hostPoolName", "hostPoolValue"), + } +} + +// String returns a human-readable description of this Host Pool ID +func (id HostPoolId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Host Pool Name: %q", id.HostPoolName), + } + return fmt.Sprintf("Host Pool (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/usersession/id_hostpool_test.go b/resource-manager/desktopvirtualization/2022-02-10-preview/usersession/id_hostpool_test.go new file mode 100644 index 00000000000..afec4ae73df --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/usersession/id_hostpool_test.go @@ -0,0 +1,279 @@ +package usersession + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = HostPoolId{} + +func TestNewHostPoolID(t *testing.T) { + id := NewHostPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "hostPoolValue") + + 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.HostPoolName != "hostPoolValue" { + t.Fatalf("Expected %q but got %q for Segment 'HostPoolName'", id.HostPoolName, "hostPoolValue") + } +} + +func TestFormatHostPoolID(t *testing.T) { + actual := NewHostPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "hostPoolValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseHostPoolID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *HostPoolId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue", + Expected: &HostPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + HostPoolName: "hostPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseHostPoolID(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.HostPoolName != v.Expected.HostPoolName { + t.Fatalf("Expected %q but got %q for HostPoolName", v.Expected.HostPoolName, actual.HostPoolName) + } + + } +} + +func TestParseHostPoolIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *HostPoolId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue", + Expected: &HostPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + HostPoolName: "hostPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe", + Expected: &HostPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + HostPoolName: "hOsTpOoLvAlUe", + }, + }, + { + // 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.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseHostPoolIDInsensitively(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.HostPoolName != v.Expected.HostPoolName { + t.Fatalf("Expected %q but got %q for HostPoolName", v.Expected.HostPoolName, actual.HostPoolName) + } + + } +} + +func TestSegmentsForHostPoolId(t *testing.T) { + segments := HostPoolId{}.Segments() + if len(segments) == 0 { + t.Fatalf("HostPoolId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/usersession/id_sessionhost.go b/resource-manager/desktopvirtualization/2022-02-10-preview/usersession/id_sessionhost.go new file mode 100644 index 00000000000..88169aaadb0 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/usersession/id_sessionhost.go @@ -0,0 +1,137 @@ +package usersession + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = SessionHostId{} + +// SessionHostId is a struct representing the Resource ID for a Session Host +type SessionHostId struct { + SubscriptionId string + ResourceGroupName string + HostPoolName string + SessionHostName string +} + +// NewSessionHostID returns a new SessionHostId struct +func NewSessionHostID(subscriptionId string, resourceGroupName string, hostPoolName string, sessionHostName string) SessionHostId { + return SessionHostId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + HostPoolName: hostPoolName, + SessionHostName: sessionHostName, + } +} + +// ParseSessionHostID parses 'input' into a SessionHostId +func ParseSessionHostID(input string) (*SessionHostId, error) { + parser := resourceids.NewParserFromResourceIdType(SessionHostId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := SessionHostId{} + + 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.HostPoolName, ok = parsed.Parsed["hostPoolName"]; !ok { + return nil, fmt.Errorf("the segment 'hostPoolName' was not found in the resource id %q", input) + } + + if id.SessionHostName, ok = parsed.Parsed["sessionHostName"]; !ok { + return nil, fmt.Errorf("the segment 'sessionHostName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseSessionHostIDInsensitively parses 'input' case-insensitively into a SessionHostId +// note: this method should only be used for API response data and not user input +func ParseSessionHostIDInsensitively(input string) (*SessionHostId, error) { + parser := resourceids.NewParserFromResourceIdType(SessionHostId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := SessionHostId{} + + 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.HostPoolName, ok = parsed.Parsed["hostPoolName"]; !ok { + return nil, fmt.Errorf("the segment 'hostPoolName' was not found in the resource id %q", input) + } + + if id.SessionHostName, ok = parsed.Parsed["sessionHostName"]; !ok { + return nil, fmt.Errorf("the segment 'sessionHostName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateSessionHostID checks that 'input' can be parsed as a Session Host ID +func ValidateSessionHostID(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 := ParseSessionHostID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Session Host ID +func (id SessionHostId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DesktopVirtualization/hostPools/%s/sessionHosts/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.HostPoolName, id.SessionHostName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Session Host ID +func (id SessionHostId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftDesktopVirtualization", "Microsoft.DesktopVirtualization", "Microsoft.DesktopVirtualization"), + resourceids.StaticSegment("staticHostPools", "hostPools", "hostPools"), + resourceids.UserSpecifiedSegment("hostPoolName", "hostPoolValue"), + resourceids.StaticSegment("staticSessionHosts", "sessionHosts", "sessionHosts"), + resourceids.UserSpecifiedSegment("sessionHostName", "sessionHostValue"), + } +} + +// String returns a human-readable description of this Session Host ID +func (id SessionHostId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Host Pool Name: %q", id.HostPoolName), + fmt.Sprintf("Session Host Name: %q", id.SessionHostName), + } + return fmt.Sprintf("Session Host (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/usersession/id_sessionhost_test.go b/resource-manager/desktopvirtualization/2022-02-10-preview/usersession/id_sessionhost_test.go new file mode 100644 index 00000000000..2ae17d1d252 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/usersession/id_sessionhost_test.go @@ -0,0 +1,324 @@ +package usersession + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = SessionHostId{} + +func TestNewSessionHostID(t *testing.T) { + id := NewSessionHostID("12345678-1234-9876-4563-123456789012", "example-resource-group", "hostPoolValue", "sessionHostValue") + + 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.HostPoolName != "hostPoolValue" { + t.Fatalf("Expected %q but got %q for Segment 'HostPoolName'", id.HostPoolName, "hostPoolValue") + } + + if id.SessionHostName != "sessionHostValue" { + t.Fatalf("Expected %q but got %q for Segment 'SessionHostName'", id.SessionHostName, "sessionHostValue") + } +} + +func TestFormatSessionHostID(t *testing.T) { + actual := NewSessionHostID("12345678-1234-9876-4563-123456789012", "example-resource-group", "hostPoolValue", "sessionHostValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/sessionHosts/sessionHostValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseSessionHostID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SessionHostId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/sessionHosts", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/sessionHosts/sessionHostValue", + Expected: &SessionHostId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + HostPoolName: "hostPoolValue", + SessionHostName: "sessionHostValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/sessionHosts/sessionHostValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSessionHostID(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.HostPoolName != v.Expected.HostPoolName { + t.Fatalf("Expected %q but got %q for HostPoolName", v.Expected.HostPoolName, actual.HostPoolName) + } + + if actual.SessionHostName != v.Expected.SessionHostName { + t.Fatalf("Expected %q but got %q for SessionHostName", v.Expected.SessionHostName, actual.SessionHostName) + } + + } +} + +func TestParseSessionHostIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SessionHostId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/sessionHosts", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe/sEsSiOnHoStS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/sessionHosts/sessionHostValue", + Expected: &SessionHostId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + HostPoolName: "hostPoolValue", + SessionHostName: "sessionHostValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/sessionHosts/sessionHostValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe/sEsSiOnHoStS/sEsSiOnHoStVaLuE", + Expected: &SessionHostId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + HostPoolName: "hOsTpOoLvAlUe", + SessionHostName: "sEsSiOnHoStVaLuE", + }, + }, + { + // 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.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe/sEsSiOnHoStS/sEsSiOnHoStVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSessionHostIDInsensitively(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.HostPoolName != v.Expected.HostPoolName { + t.Fatalf("Expected %q but got %q for HostPoolName", v.Expected.HostPoolName, actual.HostPoolName) + } + + if actual.SessionHostName != v.Expected.SessionHostName { + t.Fatalf("Expected %q but got %q for SessionHostName", v.Expected.SessionHostName, actual.SessionHostName) + } + + } +} + +func TestSegmentsForSessionHostId(t *testing.T) { + segments := SessionHostId{}.Segments() + if len(segments) == 0 { + t.Fatalf("SessionHostId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/usersession/id_usersession.go b/resource-manager/desktopvirtualization/2022-02-10-preview/usersession/id_usersession.go new file mode 100644 index 00000000000..f595f47205e --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/usersession/id_usersession.go @@ -0,0 +1,150 @@ +package usersession + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = UserSessionId{} + +// UserSessionId is a struct representing the Resource ID for a User Session +type UserSessionId struct { + SubscriptionId string + ResourceGroupName string + HostPoolName string + SessionHostName string + UserSessionId string +} + +// NewUserSessionID returns a new UserSessionId struct +func NewUserSessionID(subscriptionId string, resourceGroupName string, hostPoolName string, sessionHostName string, userSessionId string) UserSessionId { + return UserSessionId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + HostPoolName: hostPoolName, + SessionHostName: sessionHostName, + UserSessionId: userSessionId, + } +} + +// ParseUserSessionID parses 'input' into a UserSessionId +func ParseUserSessionID(input string) (*UserSessionId, error) { + parser := resourceids.NewParserFromResourceIdType(UserSessionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := UserSessionId{} + + 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.HostPoolName, ok = parsed.Parsed["hostPoolName"]; !ok { + return nil, fmt.Errorf("the segment 'hostPoolName' was not found in the resource id %q", input) + } + + if id.SessionHostName, ok = parsed.Parsed["sessionHostName"]; !ok { + return nil, fmt.Errorf("the segment 'sessionHostName' was not found in the resource id %q", input) + } + + if id.UserSessionId, ok = parsed.Parsed["userSessionId"]; !ok { + return nil, fmt.Errorf("the segment 'userSessionId' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseUserSessionIDInsensitively parses 'input' case-insensitively into a UserSessionId +// note: this method should only be used for API response data and not user input +func ParseUserSessionIDInsensitively(input string) (*UserSessionId, error) { + parser := resourceids.NewParserFromResourceIdType(UserSessionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := UserSessionId{} + + 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.HostPoolName, ok = parsed.Parsed["hostPoolName"]; !ok { + return nil, fmt.Errorf("the segment 'hostPoolName' was not found in the resource id %q", input) + } + + if id.SessionHostName, ok = parsed.Parsed["sessionHostName"]; !ok { + return nil, fmt.Errorf("the segment 'sessionHostName' was not found in the resource id %q", input) + } + + if id.UserSessionId, ok = parsed.Parsed["userSessionId"]; !ok { + return nil, fmt.Errorf("the segment 'userSessionId' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateUserSessionID checks that 'input' can be parsed as a User Session ID +func ValidateUserSessionID(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 := ParseUserSessionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted User Session ID +func (id UserSessionId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DesktopVirtualization/hostPools/%s/sessionHosts/%s/userSessions/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.HostPoolName, id.SessionHostName, id.UserSessionId) +} + +// Segments returns a slice of Resource ID Segments which comprise this User Session ID +func (id UserSessionId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftDesktopVirtualization", "Microsoft.DesktopVirtualization", "Microsoft.DesktopVirtualization"), + resourceids.StaticSegment("staticHostPools", "hostPools", "hostPools"), + resourceids.UserSpecifiedSegment("hostPoolName", "hostPoolValue"), + resourceids.StaticSegment("staticSessionHosts", "sessionHosts", "sessionHosts"), + resourceids.UserSpecifiedSegment("sessionHostName", "sessionHostValue"), + resourceids.StaticSegment("staticUserSessions", "userSessions", "userSessions"), + resourceids.UserSpecifiedSegment("userSessionId", "userSessionIdValue"), + } +} + +// String returns a human-readable description of this User Session ID +func (id UserSessionId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Host Pool Name: %q", id.HostPoolName), + fmt.Sprintf("Session Host Name: %q", id.SessionHostName), + fmt.Sprintf("User Session: %q", id.UserSessionId), + } + return fmt.Sprintf("User Session (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/usersession/id_usersession_test.go b/resource-manager/desktopvirtualization/2022-02-10-preview/usersession/id_usersession_test.go new file mode 100644 index 00000000000..9dbe9ec4b86 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/usersession/id_usersession_test.go @@ -0,0 +1,369 @@ +package usersession + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = UserSessionId{} + +func TestNewUserSessionID(t *testing.T) { + id := NewUserSessionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "hostPoolValue", "sessionHostValue", "userSessionIdValue") + + 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.HostPoolName != "hostPoolValue" { + t.Fatalf("Expected %q but got %q for Segment 'HostPoolName'", id.HostPoolName, "hostPoolValue") + } + + if id.SessionHostName != "sessionHostValue" { + t.Fatalf("Expected %q but got %q for Segment 'SessionHostName'", id.SessionHostName, "sessionHostValue") + } + + if id.UserSessionId != "userSessionIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'UserSessionId'", id.UserSessionId, "userSessionIdValue") + } +} + +func TestFormatUserSessionID(t *testing.T) { + actual := NewUserSessionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "hostPoolValue", "sessionHostValue", "userSessionIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/sessionHosts/sessionHostValue/userSessions/userSessionIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseUserSessionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *UserSessionId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/sessionHosts", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/sessionHosts/sessionHostValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/sessionHosts/sessionHostValue/userSessions", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/sessionHosts/sessionHostValue/userSessions/userSessionIdValue", + Expected: &UserSessionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + HostPoolName: "hostPoolValue", + SessionHostName: "sessionHostValue", + UserSessionId: "userSessionIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/sessionHosts/sessionHostValue/userSessions/userSessionIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseUserSessionID(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.HostPoolName != v.Expected.HostPoolName { + t.Fatalf("Expected %q but got %q for HostPoolName", v.Expected.HostPoolName, actual.HostPoolName) + } + + if actual.SessionHostName != v.Expected.SessionHostName { + t.Fatalf("Expected %q but got %q for SessionHostName", v.Expected.SessionHostName, actual.SessionHostName) + } + + if actual.UserSessionId != v.Expected.UserSessionId { + t.Fatalf("Expected %q but got %q for UserSessionId", v.Expected.UserSessionId, actual.UserSessionId) + } + + } +} + +func TestParseUserSessionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *UserSessionId + }{ + { + // 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.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/sessionHosts", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe/sEsSiOnHoStS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/sessionHosts/sessionHostValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe/sEsSiOnHoStS/sEsSiOnHoStVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/sessionHosts/sessionHostValue/userSessions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe/sEsSiOnHoStS/sEsSiOnHoStVaLuE/uSeRsEsSiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/sessionHosts/sessionHostValue/userSessions/userSessionIdValue", + Expected: &UserSessionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + HostPoolName: "hostPoolValue", + SessionHostName: "sessionHostValue", + UserSessionId: "userSessionIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/hostPools/hostPoolValue/sessionHosts/sessionHostValue/userSessions/userSessionIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe/sEsSiOnHoStS/sEsSiOnHoStVaLuE/uSeRsEsSiOnS/uSeRsEsSiOnIdVaLuE", + Expected: &UserSessionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + HostPoolName: "hOsTpOoLvAlUe", + SessionHostName: "sEsSiOnHoStVaLuE", + UserSessionId: "uSeRsEsSiOnIdVaLuE", + }, + }, + { + // 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.dEsKtOpViRtUaLiZaTiOn/hOsTpOoLs/hOsTpOoLvAlUe/sEsSiOnHoStS/sEsSiOnHoStVaLuE/uSeRsEsSiOnS/uSeRsEsSiOnIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseUserSessionIDInsensitively(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.HostPoolName != v.Expected.HostPoolName { + t.Fatalf("Expected %q but got %q for HostPoolName", v.Expected.HostPoolName, actual.HostPoolName) + } + + if actual.SessionHostName != v.Expected.SessionHostName { + t.Fatalf("Expected %q but got %q for SessionHostName", v.Expected.SessionHostName, actual.SessionHostName) + } + + if actual.UserSessionId != v.Expected.UserSessionId { + t.Fatalf("Expected %q but got %q for UserSessionId", v.Expected.UserSessionId, actual.UserSessionId) + } + + } +} + +func TestSegmentsForUserSessionId(t *testing.T) { + segments := UserSessionId{}.Segments() + if len(segments) == 0 { + t.Fatalf("UserSessionId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/usersession/method_delete_autorest.go b/resource-manager/desktopvirtualization/2022-02-10-preview/usersession/method_delete_autorest.go new file mode 100644 index 00000000000..a6ace80a14a --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/usersession/method_delete_autorest.go @@ -0,0 +1,94 @@ +package usersession + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response +} + +type DeleteOperationOptions struct { + Force *bool +} + +func DefaultDeleteOperationOptions() DeleteOperationOptions { + return DeleteOperationOptions{} +} + +func (o DeleteOperationOptions) toHeaders() map[string]interface{} { + out := make(map[string]interface{}) + + return out +} + +func (o DeleteOperationOptions) toQueryString() map[string]interface{} { + out := make(map[string]interface{}) + + if o.Force != nil { + out["force"] = *o.Force + } + + return out +} + +// Delete ... +func (c UserSessionClient) Delete(ctx context.Context, id UserSessionId, options DeleteOperationOptions) (result DeleteOperationResponse, err error) { + req, err := c.preparerForDelete(ctx, id, options) + if err != nil { + err = autorest.NewErrorWithError(err, "usersession.UserSessionClient", "Delete", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "usersession.UserSessionClient", "Delete", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForDelete(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "usersession.UserSessionClient", "Delete", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForDelete prepares the Delete request. +func (c UserSessionClient) preparerForDelete(ctx context.Context, id UserSessionId, options DeleteOperationOptions) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + for k, v := range options.toQueryString() { + queryParameters[k] = autorest.Encode("query", v) + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsDelete(), + autorest.WithBaseURL(c.baseUri), + autorest.WithHeaders(options.toHeaders()), + 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 UserSessionClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/usersession/method_disconnect_autorest.go b/resource-manager/desktopvirtualization/2022-02-10-preview/usersession/method_disconnect_autorest.go new file mode 100644 index 00000000000..07af79bf79d --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/usersession/method_disconnect_autorest.go @@ -0,0 +1,66 @@ +package usersession + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DisconnectOperationResponse struct { + HttpResponse *http.Response +} + +// Disconnect ... +func (c UserSessionClient) Disconnect(ctx context.Context, id UserSessionId) (result DisconnectOperationResponse, err error) { + req, err := c.preparerForDisconnect(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "usersession.UserSessionClient", "Disconnect", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "usersession.UserSessionClient", "Disconnect", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForDisconnect(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "usersession.UserSessionClient", "Disconnect", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForDisconnect prepares the Disconnect request. +func (c UserSessionClient) preparerForDisconnect(ctx context.Context, id UserSessionId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/disconnect", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForDisconnect handles the response to the Disconnect request. The method always +// closes the http.Response Body. +func (c UserSessionClient) responderForDisconnect(resp *http.Response) (result DisconnectOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/usersession/method_get_autorest.go b/resource-manager/desktopvirtualization/2022-02-10-preview/usersession/method_get_autorest.go new file mode 100644 index 00000000000..95e4ede3489 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/usersession/method_get_autorest.go @@ -0,0 +1,67 @@ +package usersession + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *UserSession +} + +// Get ... +func (c UserSessionClient) Get(ctx context.Context, id UserSessionId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "usersession.UserSessionClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "usersession.UserSessionClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "usersession.UserSessionClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c UserSessionClient) preparerForGet(ctx context.Context, id UserSessionId) (*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 UserSessionClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/usersession/method_list_autorest.go b/resource-manager/desktopvirtualization/2022-02-10-preview/usersession/method_list_autorest.go new file mode 100644 index 00000000000..b0104c70b7a --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/usersession/method_list_autorest.go @@ -0,0 +1,186 @@ +package usersession + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + Model *[]UserSession + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) +} + +type ListCompleteResult struct { + Items []UserSession +} + +func (r ListOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// List ... +func (c UserSessionClient) List(ctx context.Context, id SessionHostId) (resp ListOperationResponse, err error) { + req, err := c.preparerForList(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "usersession.UserSessionClient", "List", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "usersession.UserSessionClient", "List", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForList(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "usersession.UserSessionClient", "List", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// ListComplete retrieves all of the results into a single object +func (c UserSessionClient) ListComplete(ctx context.Context, id SessionHostId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, UserSessionOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c UserSessionClient) ListCompleteMatchingPredicate(ctx context.Context, id SessionHostId, predicate UserSessionOperationPredicate) (resp ListCompleteResult, err error) { + items := make([]UserSession, 0) + + page, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListCompleteResult{ + Items: items, + } + return out, nil +} + +// preparerForList prepares the List request. +func (c UserSessionClient) preparerForList(ctx context.Context, id SessionHostId) (*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/userSessions", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListWithNextLink prepares the List request with the given nextLink token. +func (c UserSessionClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForList handles the response to the List request. The method always +// closes the http.Response Body. +func (c UserSessionClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { + type page struct { + Values []UserSession `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { + req, err := c.preparerForListWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "usersession.UserSessionClient", "List", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "usersession.UserSessionClient", "List", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "usersession.UserSessionClient", "List", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/usersession/method_listbyhostpool_autorest.go b/resource-manager/desktopvirtualization/2022-02-10-preview/usersession/method_listbyhostpool_autorest.go new file mode 100644 index 00000000000..3c04145f13f --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/usersession/method_listbyhostpool_autorest.go @@ -0,0 +1,215 @@ +package usersession + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByHostPoolOperationResponse struct { + HttpResponse *http.Response + Model *[]UserSession + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListByHostPoolOperationResponse, error) +} + +type ListByHostPoolCompleteResult struct { + Items []UserSession +} + +func (r ListByHostPoolOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListByHostPoolOperationResponse) LoadMore(ctx context.Context) (resp ListByHostPoolOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +type ListByHostPoolOperationOptions struct { + Filter *string +} + +func DefaultListByHostPoolOperationOptions() ListByHostPoolOperationOptions { + return ListByHostPoolOperationOptions{} +} + +func (o ListByHostPoolOperationOptions) toHeaders() map[string]interface{} { + out := make(map[string]interface{}) + + return out +} + +func (o ListByHostPoolOperationOptions) toQueryString() map[string]interface{} { + out := make(map[string]interface{}) + + if o.Filter != nil { + out["$filter"] = *o.Filter + } + + return out +} + +// ListByHostPool ... +func (c UserSessionClient) ListByHostPool(ctx context.Context, id HostPoolId, options ListByHostPoolOperationOptions) (resp ListByHostPoolOperationResponse, err error) { + req, err := c.preparerForListByHostPool(ctx, id, options) + if err != nil { + err = autorest.NewErrorWithError(err, "usersession.UserSessionClient", "ListByHostPool", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "usersession.UserSessionClient", "ListByHostPool", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForListByHostPool(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "usersession.UserSessionClient", "ListByHostPool", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// ListByHostPoolComplete retrieves all of the results into a single object +func (c UserSessionClient) ListByHostPoolComplete(ctx context.Context, id HostPoolId, options ListByHostPoolOperationOptions) (ListByHostPoolCompleteResult, error) { + return c.ListByHostPoolCompleteMatchingPredicate(ctx, id, options, UserSessionOperationPredicate{}) +} + +// ListByHostPoolCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c UserSessionClient) ListByHostPoolCompleteMatchingPredicate(ctx context.Context, id HostPoolId, options ListByHostPoolOperationOptions, predicate UserSessionOperationPredicate) (resp ListByHostPoolCompleteResult, err error) { + items := make([]UserSession, 0) + + page, err := c.ListByHostPool(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListByHostPoolCompleteResult{ + Items: items, + } + return out, nil +} + +// preparerForListByHostPool prepares the ListByHostPool request. +func (c UserSessionClient) preparerForListByHostPool(ctx context.Context, id HostPoolId, options ListByHostPoolOperationOptions) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + for k, v := range options.toQueryString() { + queryParameters[k] = autorest.Encode("query", v) + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithHeaders(options.toHeaders()), + autorest.WithPath(fmt.Sprintf("%s/userSessions", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListByHostPoolWithNextLink prepares the ListByHostPool request with the given nextLink token. +func (c UserSessionClient) preparerForListByHostPoolWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForListByHostPool handles the response to the ListByHostPool request. The method always +// closes the http.Response Body. +func (c UserSessionClient) responderForListByHostPool(resp *http.Response) (result ListByHostPoolOperationResponse, err error) { + type page struct { + Values []UserSession `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListByHostPoolOperationResponse, err error) { + req, err := c.preparerForListByHostPoolWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "usersession.UserSessionClient", "ListByHostPool", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "usersession.UserSessionClient", "ListByHostPool", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForListByHostPool(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "usersession.UserSessionClient", "ListByHostPool", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/usersession/method_sendmessage_autorest.go b/resource-manager/desktopvirtualization/2022-02-10-preview/usersession/method_sendmessage_autorest.go new file mode 100644 index 00000000000..8cb3b5580ec --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/usersession/method_sendmessage_autorest.go @@ -0,0 +1,67 @@ +package usersession + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SendMessageOperationResponse struct { + HttpResponse *http.Response +} + +// SendMessage ... +func (c UserSessionClient) SendMessage(ctx context.Context, id UserSessionId, input SendMessage) (result SendMessageOperationResponse, err error) { + req, err := c.preparerForSendMessage(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "usersession.UserSessionClient", "SendMessage", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "usersession.UserSessionClient", "SendMessage", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForSendMessage(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "usersession.UserSessionClient", "SendMessage", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForSendMessage prepares the SendMessage request. +func (c UserSessionClient) preparerForSendMessage(ctx context.Context, id UserSessionId, input SendMessage) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/sendMessage", id.ID())), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForSendMessage handles the response to the SendMessage request. The method always +// closes the http.Response Body. +func (c UserSessionClient) responderForSendMessage(resp *http.Response) (result SendMessageOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/usersession/model_sendmessage.go b/resource-manager/desktopvirtualization/2022-02-10-preview/usersession/model_sendmessage.go new file mode 100644 index 00000000000..6e74c2bcb0a --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/usersession/model_sendmessage.go @@ -0,0 +1,9 @@ +package usersession + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SendMessage struct { + MessageBody *string `json:"messageBody,omitempty"` + MessageTitle *string `json:"messageTitle,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/usersession/model_usersession.go b/resource-manager/desktopvirtualization/2022-02-10-preview/usersession/model_usersession.go new file mode 100644 index 00000000000..34c95e10b6f --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/usersession/model_usersession.go @@ -0,0 +1,16 @@ +package usersession + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UserSession struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *UserSessionProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/usersession/model_usersessionproperties.go b/resource-manager/desktopvirtualization/2022-02-10-preview/usersession/model_usersessionproperties.go new file mode 100644 index 00000000000..e9f81a882eb --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/usersession/model_usersessionproperties.go @@ -0,0 +1,31 @@ +package usersession + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UserSessionProperties struct { + ActiveDirectoryUserName *string `json:"activeDirectoryUserName,omitempty"` + ApplicationType *ApplicationType `json:"applicationType,omitempty"` + CreateTime *string `json:"createTime,omitempty"` + ObjectId *string `json:"objectId,omitempty"` + SessionState *SessionState `json:"sessionState,omitempty"` + UserPrincipalName *string `json:"userPrincipalName,omitempty"` +} + +func (o *UserSessionProperties) GetCreateTimeAsTime() (*time.Time, error) { + if o.CreateTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreateTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *UserSessionProperties) SetCreateTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreateTime = &formatted +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/usersession/predicates.go b/resource-manager/desktopvirtualization/2022-02-10-preview/usersession/predicates.go new file mode 100644 index 00000000000..206015c6dd2 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/usersession/predicates.go @@ -0,0 +1,24 @@ +package usersession + +type UserSessionOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p UserSessionOperationPredicate) Matches(input UserSession) bool { + + if p.Id != nil && (input.Id == nil && *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil && *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil && *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/usersession/version.go b/resource-manager/desktopvirtualization/2022-02-10-preview/usersession/version.go new file mode 100644 index 00000000000..34d6457579a --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/usersession/version.go @@ -0,0 +1,12 @@ +package usersession + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2022-02-10-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/usersession/%s", defaultApiVersion) +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/workspace/client.go b/resource-manager/desktopvirtualization/2022-02-10-preview/workspace/client.go new file mode 100644 index 00000000000..57fd58240e0 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/workspace/client.go @@ -0,0 +1,18 @@ +package workspace + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspaceClient struct { + Client autorest.Client + baseUri string +} + +func NewWorkspaceClientWithBaseURI(endpoint string) WorkspaceClient { + return WorkspaceClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/workspace/constants.go b/resource-manager/desktopvirtualization/2022-02-10-preview/workspace/constants.go new file mode 100644 index 00000000000..6a92abbc04b --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/workspace/constants.go @@ -0,0 +1,133 @@ +package workspace + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionProvisioningState string + +const ( + PrivateEndpointConnectionProvisioningStateCreating PrivateEndpointConnectionProvisioningState = "Creating" + PrivateEndpointConnectionProvisioningStateDeleting PrivateEndpointConnectionProvisioningState = "Deleting" + PrivateEndpointConnectionProvisioningStateFailed PrivateEndpointConnectionProvisioningState = "Failed" + PrivateEndpointConnectionProvisioningStateSucceeded PrivateEndpointConnectionProvisioningState = "Succeeded" +) + +func PossibleValuesForPrivateEndpointConnectionProvisioningState() []string { + return []string{ + string(PrivateEndpointConnectionProvisioningStateCreating), + string(PrivateEndpointConnectionProvisioningStateDeleting), + string(PrivateEndpointConnectionProvisioningStateFailed), + string(PrivateEndpointConnectionProvisioningStateSucceeded), + } +} + +func parsePrivateEndpointConnectionProvisioningState(input string) (*PrivateEndpointConnectionProvisioningState, error) { + vals := map[string]PrivateEndpointConnectionProvisioningState{ + "creating": PrivateEndpointConnectionProvisioningStateCreating, + "deleting": PrivateEndpointConnectionProvisioningStateDeleting, + "failed": PrivateEndpointConnectionProvisioningStateFailed, + "succeeded": PrivateEndpointConnectionProvisioningStateSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PrivateEndpointConnectionProvisioningState(input) + return &out, nil +} + +type PrivateEndpointServiceConnectionStatus string + +const ( + PrivateEndpointServiceConnectionStatusApproved PrivateEndpointServiceConnectionStatus = "Approved" + PrivateEndpointServiceConnectionStatusPending PrivateEndpointServiceConnectionStatus = "Pending" + PrivateEndpointServiceConnectionStatusRejected PrivateEndpointServiceConnectionStatus = "Rejected" +) + +func PossibleValuesForPrivateEndpointServiceConnectionStatus() []string { + return []string{ + string(PrivateEndpointServiceConnectionStatusApproved), + string(PrivateEndpointServiceConnectionStatusPending), + string(PrivateEndpointServiceConnectionStatusRejected), + } +} + +func parsePrivateEndpointServiceConnectionStatus(input string) (*PrivateEndpointServiceConnectionStatus, error) { + vals := map[string]PrivateEndpointServiceConnectionStatus{ + "approved": PrivateEndpointServiceConnectionStatusApproved, + "pending": PrivateEndpointServiceConnectionStatusPending, + "rejected": PrivateEndpointServiceConnectionStatusRejected, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PrivateEndpointServiceConnectionStatus(input) + return &out, nil +} + +type PublicNetworkAccess string + +const ( + PublicNetworkAccessDisabled PublicNetworkAccess = "Disabled" + PublicNetworkAccessEnabled PublicNetworkAccess = "Enabled" +) + +func PossibleValuesForPublicNetworkAccess() []string { + return []string{ + string(PublicNetworkAccessDisabled), + string(PublicNetworkAccessEnabled), + } +} + +func parsePublicNetworkAccess(input string) (*PublicNetworkAccess, error) { + vals := map[string]PublicNetworkAccess{ + "disabled": PublicNetworkAccessDisabled, + "enabled": PublicNetworkAccessEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PublicNetworkAccess(input) + return &out, nil +} + +type SkuTier string + +const ( + SkuTierBasic SkuTier = "Basic" + SkuTierFree SkuTier = "Free" + SkuTierPremium SkuTier = "Premium" + SkuTierStandard SkuTier = "Standard" +) + +func PossibleValuesForSkuTier() []string { + return []string{ + string(SkuTierBasic), + string(SkuTierFree), + string(SkuTierPremium), + string(SkuTierStandard), + } +} + +func parseSkuTier(input string) (*SkuTier, error) { + vals := map[string]SkuTier{ + "basic": SkuTierBasic, + "free": SkuTierFree, + "premium": SkuTierPremium, + "standard": SkuTierStandard, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SkuTier(input) + return &out, nil +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/workspace/id_workspace.go b/resource-manager/desktopvirtualization/2022-02-10-preview/workspace/id_workspace.go new file mode 100644 index 00000000000..90f00ab2c31 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/workspace/id_workspace.go @@ -0,0 +1,124 @@ +package workspace + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace +type WorkspaceId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string +} + +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, workspaceName string) WorkspaceId { + return WorkspaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + } +} + +// ParseWorkspaceID parses 'input' into a WorkspaceId +func ParseWorkspaceID(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(WorkspaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := WorkspaceId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.WorkspaceName, ok = parsed.Parsed["workspaceName"]; !ok { + return nil, fmt.Errorf("the segment 'workspaceName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(WorkspaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := WorkspaceId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.WorkspaceName, ok = parsed.Parsed["workspaceName"]; !ok { + return nil, fmt.Errorf("the segment 'workspaceName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DesktopVirtualization/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftDesktopVirtualization", "Microsoft.DesktopVirtualization", "Microsoft.DesktopVirtualization"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + } +} + +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/workspace/id_workspace_test.go b/resource-manager/desktopvirtualization/2022-02-10-preview/workspace/id_workspace_test.go new file mode 100644 index 00000000000..bbbdfae6035 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/workspace/id_workspace_test.go @@ -0,0 +1,279 @@ +package workspace + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = WorkspaceId{} + +func TestNewWorkspaceID(t *testing.T) { + id := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } +} + +func TestFormatWorkspaceID(t *testing.T) { + actual := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/workspaces/workspaceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/workspaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/workspaces/workspaceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestParseWorkspaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/wOrKsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DesktopVirtualization/workspaces/workspaceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/wOrKsPaCeS/wOrKsPaCeVaLuE", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEsKtOpViRtUaLiZaTiOn/wOrKsPaCeS/wOrKsPaCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestSegmentsForWorkspaceId(t *testing.T) { + segments := WorkspaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/workspace/method_createorupdate_autorest.go b/resource-manager/desktopvirtualization/2022-02-10-preview/workspace/method_createorupdate_autorest.go new file mode 100644 index 00000000000..2dfa75cfe31 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/workspace/method_createorupdate_autorest.go @@ -0,0 +1,68 @@ +package workspace + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + Model *Workspace +} + +// CreateOrUpdate ... +func (c WorkspaceClient) CreateOrUpdate(ctx context.Context, id WorkspaceId, input Workspace) (result CreateOrUpdateOperationResponse, err error) { + req, err := c.preparerForCreateOrUpdate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "workspace.WorkspaceClient", "CreateOrUpdate", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "workspace.WorkspaceClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForCreateOrUpdate(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "workspace.WorkspaceClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForCreateOrUpdate prepares the CreateOrUpdate request. +func (c WorkspaceClient) preparerForCreateOrUpdate(ctx context.Context, id WorkspaceId, input Workspace) (*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)) +} + +// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always +// closes the http.Response Body. +func (c WorkspaceClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/workspace/method_delete_autorest.go b/resource-manager/desktopvirtualization/2022-02-10-preview/workspace/method_delete_autorest.go new file mode 100644 index 00000000000..dceeb977a12 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/workspace/method_delete_autorest.go @@ -0,0 +1,65 @@ +package workspace + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response +} + +// Delete ... +func (c WorkspaceClient) Delete(ctx context.Context, id WorkspaceId) (result DeleteOperationResponse, err error) { + req, err := c.preparerForDelete(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "workspace.WorkspaceClient", "Delete", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "workspace.WorkspaceClient", "Delete", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForDelete(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "workspace.WorkspaceClient", "Delete", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForDelete prepares the Delete request. +func (c WorkspaceClient) preparerForDelete(ctx context.Context, id WorkspaceId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.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 WorkspaceClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/workspace/method_get_autorest.go b/resource-manager/desktopvirtualization/2022-02-10-preview/workspace/method_get_autorest.go new file mode 100644 index 00000000000..93915990f1c --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/workspace/method_get_autorest.go @@ -0,0 +1,67 @@ +package workspace + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *Workspace +} + +// Get ... +func (c WorkspaceClient) Get(ctx context.Context, id WorkspaceId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "workspace.WorkspaceClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "workspace.WorkspaceClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "workspace.WorkspaceClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c WorkspaceClient) preparerForGet(ctx context.Context, id WorkspaceId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(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 WorkspaceClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/workspace/method_listbyresourcegroup_autorest.go b/resource-manager/desktopvirtualization/2022-02-10-preview/workspace/method_listbyresourcegroup_autorest.go new file mode 100644 index 00000000000..426896e9541 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/workspace/method_listbyresourcegroup_autorest.go @@ -0,0 +1,187 @@ +package workspace + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByResourceGroupOperationResponse struct { + HttpResponse *http.Response + Model *[]Workspace + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListByResourceGroupOperationResponse, error) +} + +type ListByResourceGroupCompleteResult struct { + Items []Workspace +} + +func (r ListByResourceGroupOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListByResourceGroupOperationResponse) LoadMore(ctx context.Context) (resp ListByResourceGroupOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// ListByResourceGroup ... +func (c WorkspaceClient) ListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (resp ListByResourceGroupOperationResponse, err error) { + req, err := c.preparerForListByResourceGroup(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "workspace.WorkspaceClient", "ListByResourceGroup", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "workspace.WorkspaceClient", "ListByResourceGroup", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForListByResourceGroup(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "workspace.WorkspaceClient", "ListByResourceGroup", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// ListByResourceGroupComplete retrieves all of the results into a single object +func (c WorkspaceClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (ListByResourceGroupCompleteResult, error) { + return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, WorkspaceOperationPredicate{}) +} + +// ListByResourceGroupCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c WorkspaceClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate WorkspaceOperationPredicate) (resp ListByResourceGroupCompleteResult, err error) { + items := make([]Workspace, 0) + + page, err := c.ListByResourceGroup(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListByResourceGroupCompleteResult{ + Items: items, + } + return out, nil +} + +// preparerForListByResourceGroup prepares the ListByResourceGroup request. +func (c WorkspaceClient) preparerForListByResourceGroup(ctx context.Context, id commonids.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.DesktopVirtualization/workspaces", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListByResourceGroupWithNextLink prepares the ListByResourceGroup request with the given nextLink token. +func (c WorkspaceClient) preparerForListByResourceGroupWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForListByResourceGroup handles the response to the ListByResourceGroup request. The method always +// closes the http.Response Body. +func (c WorkspaceClient) responderForListByResourceGroup(resp *http.Response) (result ListByResourceGroupOperationResponse, err error) { + type page struct { + Values []Workspace `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListByResourceGroupOperationResponse, err error) { + req, err := c.preparerForListByResourceGroupWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "workspace.WorkspaceClient", "ListByResourceGroup", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "workspace.WorkspaceClient", "ListByResourceGroup", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForListByResourceGroup(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "workspace.WorkspaceClient", "ListByResourceGroup", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/workspace/method_listbysubscription_autorest.go b/resource-manager/desktopvirtualization/2022-02-10-preview/workspace/method_listbysubscription_autorest.go new file mode 100644 index 00000000000..6ab5742aa3f --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/workspace/method_listbysubscription_autorest.go @@ -0,0 +1,187 @@ +package workspace + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListBySubscriptionOperationResponse struct { + HttpResponse *http.Response + Model *[]Workspace + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListBySubscriptionOperationResponse, error) +} + +type ListBySubscriptionCompleteResult struct { + Items []Workspace +} + +func (r ListBySubscriptionOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListBySubscriptionOperationResponse) LoadMore(ctx context.Context) (resp ListBySubscriptionOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// ListBySubscription ... +func (c WorkspaceClient) ListBySubscription(ctx context.Context, id commonids.SubscriptionId) (resp ListBySubscriptionOperationResponse, err error) { + req, err := c.preparerForListBySubscription(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "workspace.WorkspaceClient", "ListBySubscription", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "workspace.WorkspaceClient", "ListBySubscription", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForListBySubscription(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "workspace.WorkspaceClient", "ListBySubscription", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// ListBySubscriptionComplete retrieves all of the results into a single object +func (c WorkspaceClient) ListBySubscriptionComplete(ctx context.Context, id commonids.SubscriptionId) (ListBySubscriptionCompleteResult, error) { + return c.ListBySubscriptionCompleteMatchingPredicate(ctx, id, WorkspaceOperationPredicate{}) +} + +// ListBySubscriptionCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c WorkspaceClient) ListBySubscriptionCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate WorkspaceOperationPredicate) (resp ListBySubscriptionCompleteResult, err error) { + items := make([]Workspace, 0) + + page, err := c.ListBySubscription(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListBySubscriptionCompleteResult{ + Items: items, + } + return out, nil +} + +// preparerForListBySubscription prepares the ListBySubscription request. +func (c WorkspaceClient) preparerForListBySubscription(ctx context.Context, id commonids.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.DesktopVirtualization/workspaces", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListBySubscriptionWithNextLink prepares the ListBySubscription request with the given nextLink token. +func (c WorkspaceClient) preparerForListBySubscriptionWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForListBySubscription handles the response to the ListBySubscription request. The method always +// closes the http.Response Body. +func (c WorkspaceClient) responderForListBySubscription(resp *http.Response) (result ListBySubscriptionOperationResponse, err error) { + type page struct { + Values []Workspace `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListBySubscriptionOperationResponse, err error) { + req, err := c.preparerForListBySubscriptionWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "workspace.WorkspaceClient", "ListBySubscription", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "workspace.WorkspaceClient", "ListBySubscription", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForListBySubscription(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "workspace.WorkspaceClient", "ListBySubscription", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/workspace/method_update_autorest.go b/resource-manager/desktopvirtualization/2022-02-10-preview/workspace/method_update_autorest.go new file mode 100644 index 00000000000..d822ab589a6 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/workspace/method_update_autorest.go @@ -0,0 +1,68 @@ +package workspace + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + HttpResponse *http.Response + Model *Workspace +} + +// Update ... +func (c WorkspaceClient) Update(ctx context.Context, id WorkspaceId, input WorkspacePatch) (result UpdateOperationResponse, err error) { + req, err := c.preparerForUpdate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "workspace.WorkspaceClient", "Update", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "workspace.WorkspaceClient", "Update", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForUpdate(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "workspace.WorkspaceClient", "Update", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForUpdate prepares the Update request. +func (c WorkspaceClient) preparerForUpdate(ctx context.Context, id WorkspaceId, input WorkspacePatch) (*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 WorkspaceClient) responderForUpdate(resp *http.Response) (result UpdateOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/workspace/model_plan.go b/resource-manager/desktopvirtualization/2022-02-10-preview/workspace/model_plan.go new file mode 100644 index 00000000000..5fb713a75fe --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/workspace/model_plan.go @@ -0,0 +1,12 @@ +package workspace + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Plan struct { + Name string `json:"name"` + Product string `json:"product"` + PromotionCode *string `json:"promotionCode,omitempty"` + Publisher string `json:"publisher"` + Version *string `json:"version,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/workspace/model_privateendpoint.go b/resource-manager/desktopvirtualization/2022-02-10-preview/workspace/model_privateendpoint.go new file mode 100644 index 00000000000..f3aaa3c262c --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/workspace/model_privateendpoint.go @@ -0,0 +1,8 @@ +package workspace + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpoint struct { + Id *string `json:"id,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/workspace/model_privateendpointconnection.go b/resource-manager/desktopvirtualization/2022-02-10-preview/workspace/model_privateendpointconnection.go new file mode 100644 index 00000000000..515f6a66619 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/workspace/model_privateendpointconnection.go @@ -0,0 +1,11 @@ +package workspace + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnection struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PrivateEndpointConnectionProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/workspace/model_privateendpointconnectionproperties.go b/resource-manager/desktopvirtualization/2022-02-10-preview/workspace/model_privateendpointconnectionproperties.go new file mode 100644 index 00000000000..48c363c290e --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/workspace/model_privateendpointconnectionproperties.go @@ -0,0 +1,10 @@ +package workspace + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionProperties struct { + PrivateEndpoint *PrivateEndpoint `json:"privateEndpoint,omitempty"` + PrivateLinkServiceConnectionState PrivateLinkServiceConnectionState `json:"privateLinkServiceConnectionState"` + ProvisioningState *PrivateEndpointConnectionProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/workspace/model_privatelinkserviceconnectionstate.go b/resource-manager/desktopvirtualization/2022-02-10-preview/workspace/model_privatelinkserviceconnectionstate.go new file mode 100644 index 00000000000..074cb7dfa9e --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/workspace/model_privatelinkserviceconnectionstate.go @@ -0,0 +1,10 @@ +package workspace + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkServiceConnectionState struct { + ActionsRequired *string `json:"actionsRequired,omitempty"` + Description *string `json:"description,omitempty"` + Status *PrivateEndpointServiceConnectionStatus `json:"status,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/workspace/model_sku.go b/resource-manager/desktopvirtualization/2022-02-10-preview/workspace/model_sku.go new file mode 100644 index 00000000000..8b18e233d75 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/workspace/model_sku.go @@ -0,0 +1,12 @@ +package workspace + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Sku struct { + Capacity *int64 `json:"capacity,omitempty"` + Family *string `json:"family,omitempty"` + Name string `json:"name"` + Size *string `json:"size,omitempty"` + Tier *SkuTier `json:"tier,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/workspace/model_workspace.go b/resource-manager/desktopvirtualization/2022-02-10-preview/workspace/model_workspace.go new file mode 100644 index 00000000000..6b48aa98737 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/workspace/model_workspace.go @@ -0,0 +1,25 @@ +package workspace + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/identity" + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Workspace struct { + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Identity *identity.SystemAssigned `json:"identity,omitempty"` + Kind *string `json:"kind,omitempty"` + Location *string `json:"location,omitempty"` + ManagedBy *string `json:"managedBy,omitempty"` + Name *string `json:"name,omitempty"` + Plan *Plan `json:"plan,omitempty"` + Properties *WorkspaceProperties `json:"properties,omitempty"` + Sku *Sku `json:"sku,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/workspace/model_workspacepatch.go b/resource-manager/desktopvirtualization/2022-02-10-preview/workspace/model_workspacepatch.go new file mode 100644 index 00000000000..1ac870f647e --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/workspace/model_workspacepatch.go @@ -0,0 +1,9 @@ +package workspace + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspacePatch struct { + Properties *WorkspacePatchProperties `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/workspace/model_workspacepatchproperties.go b/resource-manager/desktopvirtualization/2022-02-10-preview/workspace/model_workspacepatchproperties.go new file mode 100644 index 00000000000..3f010914b65 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/workspace/model_workspacepatchproperties.go @@ -0,0 +1,11 @@ +package workspace + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspacePatchProperties struct { + ApplicationGroupReferences *[]string `json:"applicationGroupReferences,omitempty"` + Description *string `json:"description,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + PublicNetworkAccess *PublicNetworkAccess `json:"publicNetworkAccess,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/workspace/model_workspaceproperties.go b/resource-manager/desktopvirtualization/2022-02-10-preview/workspace/model_workspaceproperties.go new file mode 100644 index 00000000000..d180ba181cf --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/workspace/model_workspaceproperties.go @@ -0,0 +1,14 @@ +package workspace + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspaceProperties struct { + ApplicationGroupReferences *[]string `json:"applicationGroupReferences,omitempty"` + CloudPcResource *bool `json:"cloudPcResource,omitempty"` + Description *string `json:"description,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + ObjectId *string `json:"objectId,omitempty"` + PrivateEndpointConnections *[]PrivateEndpointConnection `json:"privateEndpointConnections,omitempty"` + PublicNetworkAccess *PublicNetworkAccess `json:"publicNetworkAccess,omitempty"` +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/workspace/predicates.go b/resource-manager/desktopvirtualization/2022-02-10-preview/workspace/predicates.go new file mode 100644 index 00000000000..232537375c9 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/workspace/predicates.go @@ -0,0 +1,44 @@ +package workspace + +type WorkspaceOperationPredicate struct { + Etag *string + Id *string + Kind *string + Location *string + ManagedBy *string + Name *string + Type *string +} + +func (p WorkspaceOperationPredicate) Matches(input Workspace) bool { + + if p.Etag != nil && (input.Etag == nil && *p.Etag != *input.Etag) { + return false + } + + if p.Id != nil && (input.Id == nil && *p.Id != *input.Id) { + return false + } + + if p.Kind != nil && (input.Kind == nil && *p.Kind != *input.Kind) { + return false + } + + if p.Location != nil && (input.Location == nil && *p.Location != *input.Location) { + return false + } + + if p.ManagedBy != nil && (input.ManagedBy == nil && *p.ManagedBy != *input.ManagedBy) { + return false + } + + if p.Name != nil && (input.Name == nil && *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil && *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/desktopvirtualization/2022-02-10-preview/workspace/version.go b/resource-manager/desktopvirtualization/2022-02-10-preview/workspace/version.go new file mode 100644 index 00000000000..537513b53d9 --- /dev/null +++ b/resource-manager/desktopvirtualization/2022-02-10-preview/workspace/version.go @@ -0,0 +1,12 @@ +package workspace + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2022-02-10-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/workspace/%s", defaultApiVersion) +}