diff --git a/go.mod b/go.mod index cec78020086..37dd204b06c 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,7 @@ require ( github.com/Azure/go-autorest/autorest v0.11.29 github.com/Azure/go-autorest/autorest/adal v0.9.23 github.com/davecgh/go-spew v1.1.1 + github.com/golang-jwt/jwt/v4 v4.5.0 github.com/hashicorp/go-azure-helpers v0.64.0 github.com/hashicorp/go-retryablehttp v0.7.4 github.com/hashicorp/go-uuid v1.0.3 @@ -22,7 +23,6 @@ require ( github.com/agext/levenshtein v1.2.2 // indirect github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect github.com/fatih/color v1.13.0 // indirect - github.com/golang-jwt/jwt/v4 v4.5.0 // indirect github.com/golang/protobuf v1.5.2 // indirect github.com/google/go-cmp v0.5.9 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect diff --git a/resource-manager/dataprotection/2023-11-01/azurebackupjob/README.md b/resource-manager/dataprotection/2023-11-01/azurebackupjob/README.md new file mode 100644 index 00000000000..e60beed1df8 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/azurebackupjob/README.md @@ -0,0 +1,64 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2023-11-01/azurebackupjob` Documentation + +The `azurebackupjob` SDK allows for interaction with the Azure Resource Manager Service `dataprotection` (API Version `2023-11-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2023-11-01/azurebackupjob" +``` + + +### Client Initialization + +```go +client := azurebackupjob.NewAzureBackupJobClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `AzureBackupJobClient.ExportJobsOperationResultGet` + +```go +ctx := context.TODO() +id := azurebackupjob.NewOperationIdID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultValue", "operationIdValue") + +read, err := client.ExportJobsOperationResultGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `AzureBackupJobClient.ExportJobsTrigger` + +```go +ctx := context.TODO() +id := azurebackupjob.NewBackupVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultValue") + +if err := client.ExportJobsTriggerThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `AzureBackupJobClient.JobsGet` + +```go +ctx := context.TODO() +id := azurebackupjob.NewBackupJobID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultValue", "jobIdValue") + +read, err := client.JobsGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/dataprotection/2023-11-01/azurebackupjob/client.go b/resource-manager/dataprotection/2023-11-01/azurebackupjob/client.go new file mode 100644 index 00000000000..11ba06b263b --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/azurebackupjob/client.go @@ -0,0 +1,26 @@ +package azurebackupjob + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureBackupJobClient struct { + Client *resourcemanager.Client +} + +func NewAzureBackupJobClientWithBaseURI(sdkApi sdkEnv.Api) (*AzureBackupJobClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "azurebackupjob", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating AzureBackupJobClient: %+v", err) + } + + return &AzureBackupJobClient{ + Client: client, + }, nil +} diff --git a/resource-manager/dataprotection/2023-11-01/azurebackupjob/id_backupjob.go b/resource-manager/dataprotection/2023-11-01/azurebackupjob/id_backupjob.go new file mode 100644 index 00000000000..8b7ca0eeb92 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/azurebackupjob/id_backupjob.go @@ -0,0 +1,134 @@ +package azurebackupjob + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = BackupJobId{} + +// BackupJobId is a struct representing the Resource ID for a Backup Job +type BackupJobId struct { + SubscriptionId string + ResourceGroupName string + BackupVaultName string + JobId string +} + +// NewBackupJobID returns a new BackupJobId struct +func NewBackupJobID(subscriptionId string, resourceGroupName string, backupVaultName string, jobId string) BackupJobId { + return BackupJobId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + BackupVaultName: backupVaultName, + JobId: jobId, + } +} + +// ParseBackupJobID parses 'input' into a BackupJobId +func ParseBackupJobID(input string) (*BackupJobId, error) { + parser := resourceids.NewParserFromResourceIdType(BackupJobId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BackupJobId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseBackupJobIDInsensitively parses 'input' case-insensitively into a BackupJobId +// note: this method should only be used for API response data and not user input +func ParseBackupJobIDInsensitively(input string) (*BackupJobId, error) { + parser := resourceids.NewParserFromResourceIdType(BackupJobId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BackupJobId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *BackupJobId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.BackupVaultName, ok = input.Parsed["backupVaultName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "backupVaultName", input) + } + + if id.JobId, ok = input.Parsed["jobId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "jobId", input) + } + + return nil +} + +// ValidateBackupJobID checks that 'input' can be parsed as a Backup Job ID +func ValidateBackupJobID(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 := ParseBackupJobID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Backup Job ID +func (id BackupJobId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DataProtection/backupVaults/%s/backupJobs/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.BackupVaultName, id.JobId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Backup Job ID +func (id BackupJobId) 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("staticMicrosoftDataProtection", "Microsoft.DataProtection", "Microsoft.DataProtection"), + resourceids.StaticSegment("staticBackupVaults", "backupVaults", "backupVaults"), + resourceids.UserSpecifiedSegment("backupVaultName", "backupVaultValue"), + resourceids.StaticSegment("staticBackupJobs", "backupJobs", "backupJobs"), + resourceids.UserSpecifiedSegment("jobId", "jobIdValue"), + } +} + +// String returns a human-readable description of this Backup Job ID +func (id BackupJobId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Backup Vault Name: %q", id.BackupVaultName), + fmt.Sprintf("Job: %q", id.JobId), + } + return fmt.Sprintf("Backup Job (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/dataprotection/2023-11-01/azurebackupjob/id_backupjob_test.go b/resource-manager/dataprotection/2023-11-01/azurebackupjob/id_backupjob_test.go new file mode 100644 index 00000000000..5fbf3b00cfc --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/azurebackupjob/id_backupjob_test.go @@ -0,0 +1,327 @@ +package azurebackupjob + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = BackupJobId{} + +func TestNewBackupJobID(t *testing.T) { + id := NewBackupJobID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultValue", "jobIdValue") + + 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.BackupVaultName != "backupVaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'BackupVaultName'", id.BackupVaultName, "backupVaultValue") + } + + if id.JobId != "jobIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'JobId'", id.JobId, "jobIdValue") + } +} + +func TestFormatBackupJobID(t *testing.T) { + actual := NewBackupJobID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultValue", "jobIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/backupJobs/jobIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseBackupJobID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BackupJobId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/backupJobs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/backupJobs/jobIdValue", + Expected: &BackupJobId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + BackupVaultName: "backupVaultValue", + JobId: "jobIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/backupJobs/jobIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBackupJobID(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.BackupVaultName != v.Expected.BackupVaultName { + t.Fatalf("Expected %q but got %q for BackupVaultName", v.Expected.BackupVaultName, actual.BackupVaultName) + } + + if actual.JobId != v.Expected.JobId { + t.Fatalf("Expected %q but got %q for JobId", v.Expected.JobId, actual.JobId) + } + + } +} + +func TestParseBackupJobIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BackupJobId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/backupJobs", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtVaLuE/bAcKuPjObS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/backupJobs/jobIdValue", + Expected: &BackupJobId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + BackupVaultName: "backupVaultValue", + JobId: "jobIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/backupJobs/jobIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtVaLuE/bAcKuPjObS/jObIdVaLuE", + Expected: &BackupJobId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + BackupVaultName: "bAcKuPvAuLtVaLuE", + JobId: "jObIdVaLuE", + }, + }, + { + // 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.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtVaLuE/bAcKuPjObS/jObIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBackupJobIDInsensitively(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.BackupVaultName != v.Expected.BackupVaultName { + t.Fatalf("Expected %q but got %q for BackupVaultName", v.Expected.BackupVaultName, actual.BackupVaultName) + } + + if actual.JobId != v.Expected.JobId { + t.Fatalf("Expected %q but got %q for JobId", v.Expected.JobId, actual.JobId) + } + + } +} + +func TestSegmentsForBackupJobId(t *testing.T) { + segments := BackupJobId{}.Segments() + if len(segments) == 0 { + t.Fatalf("BackupJobId 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/dataprotection/2023-11-01/azurebackupjob/id_backupvault.go b/resource-manager/dataprotection/2023-11-01/azurebackupjob/id_backupvault.go new file mode 100644 index 00000000000..963509b4166 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/azurebackupjob/id_backupvault.go @@ -0,0 +1,125 @@ +package azurebackupjob + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = BackupVaultId{} + +// BackupVaultId is a struct representing the Resource ID for a Backup Vault +type BackupVaultId struct { + SubscriptionId string + ResourceGroupName string + BackupVaultName string +} + +// NewBackupVaultID returns a new BackupVaultId struct +func NewBackupVaultID(subscriptionId string, resourceGroupName string, backupVaultName string) BackupVaultId { + return BackupVaultId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + BackupVaultName: backupVaultName, + } +} + +// ParseBackupVaultID parses 'input' into a BackupVaultId +func ParseBackupVaultID(input string) (*BackupVaultId, error) { + parser := resourceids.NewParserFromResourceIdType(BackupVaultId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BackupVaultId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseBackupVaultIDInsensitively parses 'input' case-insensitively into a BackupVaultId +// note: this method should only be used for API response data and not user input +func ParseBackupVaultIDInsensitively(input string) (*BackupVaultId, error) { + parser := resourceids.NewParserFromResourceIdType(BackupVaultId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BackupVaultId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *BackupVaultId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.BackupVaultName, ok = input.Parsed["backupVaultName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "backupVaultName", input) + } + + return nil +} + +// ValidateBackupVaultID checks that 'input' can be parsed as a Backup Vault ID +func ValidateBackupVaultID(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 := ParseBackupVaultID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Backup Vault ID +func (id BackupVaultId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DataProtection/backupVaults/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.BackupVaultName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Backup Vault ID +func (id BackupVaultId) 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("staticMicrosoftDataProtection", "Microsoft.DataProtection", "Microsoft.DataProtection"), + resourceids.StaticSegment("staticBackupVaults", "backupVaults", "backupVaults"), + resourceids.UserSpecifiedSegment("backupVaultName", "backupVaultValue"), + } +} + +// String returns a human-readable description of this Backup Vault ID +func (id BackupVaultId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Backup Vault Name: %q", id.BackupVaultName), + } + return fmt.Sprintf("Backup Vault (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/dataprotection/2023-11-01/azurebackupjob/id_backupvault_test.go b/resource-manager/dataprotection/2023-11-01/azurebackupjob/id_backupvault_test.go new file mode 100644 index 00000000000..04e6d93b42d --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/azurebackupjob/id_backupvault_test.go @@ -0,0 +1,282 @@ +package azurebackupjob + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = BackupVaultId{} + +func TestNewBackupVaultID(t *testing.T) { + id := NewBackupVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultValue") + + 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.BackupVaultName != "backupVaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'BackupVaultName'", id.BackupVaultName, "backupVaultValue") + } +} + +func TestFormatBackupVaultID(t *testing.T) { + actual := NewBackupVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseBackupVaultID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BackupVaultId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue", + Expected: &BackupVaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + BackupVaultName: "backupVaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBackupVaultID(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.BackupVaultName != v.Expected.BackupVaultName { + t.Fatalf("Expected %q but got %q for BackupVaultName", v.Expected.BackupVaultName, actual.BackupVaultName) + } + + } +} + +func TestParseBackupVaultIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BackupVaultId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue", + Expected: &BackupVaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + BackupVaultName: "backupVaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtVaLuE", + Expected: &BackupVaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + BackupVaultName: "bAcKuPvAuLtVaLuE", + }, + }, + { + // 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.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBackupVaultIDInsensitively(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.BackupVaultName != v.Expected.BackupVaultName { + t.Fatalf("Expected %q but got %q for BackupVaultName", v.Expected.BackupVaultName, actual.BackupVaultName) + } + + } +} + +func TestSegmentsForBackupVaultId(t *testing.T) { + segments := BackupVaultId{}.Segments() + if len(segments) == 0 { + t.Fatalf("BackupVaultId 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/dataprotection/2023-11-01/azurebackupjob/id_operationid.go b/resource-manager/dataprotection/2023-11-01/azurebackupjob/id_operationid.go new file mode 100644 index 00000000000..72e196b0385 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/azurebackupjob/id_operationid.go @@ -0,0 +1,135 @@ +package azurebackupjob + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = OperationIdId{} + +// OperationIdId is a struct representing the Resource ID for a Operation Id +type OperationIdId struct { + SubscriptionId string + ResourceGroupName string + BackupVaultName string + OperationId string +} + +// NewOperationIdID returns a new OperationIdId struct +func NewOperationIdID(subscriptionId string, resourceGroupName string, backupVaultName string, operationId string) OperationIdId { + return OperationIdId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + BackupVaultName: backupVaultName, + OperationId: operationId, + } +} + +// ParseOperationIdID parses 'input' into a OperationIdId +func ParseOperationIdID(input string) (*OperationIdId, error) { + parser := resourceids.NewParserFromResourceIdType(OperationIdId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := OperationIdId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseOperationIdIDInsensitively parses 'input' case-insensitively into a OperationIdId +// note: this method should only be used for API response data and not user input +func ParseOperationIdIDInsensitively(input string) (*OperationIdId, error) { + parser := resourceids.NewParserFromResourceIdType(OperationIdId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := OperationIdId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *OperationIdId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.BackupVaultName, ok = input.Parsed["backupVaultName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "backupVaultName", input) + } + + if id.OperationId, ok = input.Parsed["operationId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "operationId", input) + } + + return nil +} + +// ValidateOperationIdID checks that 'input' can be parsed as a Operation Id ID +func ValidateOperationIdID(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 := ParseOperationIdID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Operation Id ID +func (id OperationIdId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DataProtection/backupVaults/%s/backupJobs/operations/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.BackupVaultName, id.OperationId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Operation Id ID +func (id OperationIdId) 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("staticMicrosoftDataProtection", "Microsoft.DataProtection", "Microsoft.DataProtection"), + resourceids.StaticSegment("staticBackupVaults", "backupVaults", "backupVaults"), + resourceids.UserSpecifiedSegment("backupVaultName", "backupVaultValue"), + resourceids.StaticSegment("staticBackupJobs", "backupJobs", "backupJobs"), + resourceids.StaticSegment("staticOperations", "operations", "operations"), + resourceids.UserSpecifiedSegment("operationId", "operationIdValue"), + } +} + +// String returns a human-readable description of this Operation Id ID +func (id OperationIdId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Backup Vault Name: %q", id.BackupVaultName), + fmt.Sprintf("Operation: %q", id.OperationId), + } + return fmt.Sprintf("Operation Id (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/dataprotection/2023-11-01/azurebackupjob/id_operationid_test.go b/resource-manager/dataprotection/2023-11-01/azurebackupjob/id_operationid_test.go new file mode 100644 index 00000000000..6db8cb37ebc --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/azurebackupjob/id_operationid_test.go @@ -0,0 +1,342 @@ +package azurebackupjob + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = OperationIdId{} + +func TestNewOperationIdID(t *testing.T) { + id := NewOperationIdID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultValue", "operationIdValue") + + 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.BackupVaultName != "backupVaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'BackupVaultName'", id.BackupVaultName, "backupVaultValue") + } + + if id.OperationId != "operationIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'OperationId'", id.OperationId, "operationIdValue") + } +} + +func TestFormatOperationIdID(t *testing.T) { + actual := NewOperationIdID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultValue", "operationIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/backupJobs/operations/operationIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseOperationIdID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *OperationIdId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/backupJobs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/backupJobs/operations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/backupJobs/operations/operationIdValue", + Expected: &OperationIdId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + BackupVaultName: "backupVaultValue", + OperationId: "operationIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/backupJobs/operations/operationIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseOperationIdID(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.BackupVaultName != v.Expected.BackupVaultName { + t.Fatalf("Expected %q but got %q for BackupVaultName", v.Expected.BackupVaultName, actual.BackupVaultName) + } + + if actual.OperationId != v.Expected.OperationId { + t.Fatalf("Expected %q but got %q for OperationId", v.Expected.OperationId, actual.OperationId) + } + + } +} + +func TestParseOperationIdIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *OperationIdId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/backupJobs", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtVaLuE/bAcKuPjObS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/backupJobs/operations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtVaLuE/bAcKuPjObS/oPeRaTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/backupJobs/operations/operationIdValue", + Expected: &OperationIdId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + BackupVaultName: "backupVaultValue", + OperationId: "operationIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/backupJobs/operations/operationIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtVaLuE/bAcKuPjObS/oPeRaTiOnS/oPeRaTiOnIdVaLuE", + Expected: &OperationIdId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + BackupVaultName: "bAcKuPvAuLtVaLuE", + OperationId: "oPeRaTiOnIdVaLuE", + }, + }, + { + // 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.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtVaLuE/bAcKuPjObS/oPeRaTiOnS/oPeRaTiOnIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseOperationIdIDInsensitively(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.BackupVaultName != v.Expected.BackupVaultName { + t.Fatalf("Expected %q but got %q for BackupVaultName", v.Expected.BackupVaultName, actual.BackupVaultName) + } + + if actual.OperationId != v.Expected.OperationId { + t.Fatalf("Expected %q but got %q for OperationId", v.Expected.OperationId, actual.OperationId) + } + + } +} + +func TestSegmentsForOperationIdId(t *testing.T) { + segments := OperationIdId{}.Segments() + if len(segments) == 0 { + t.Fatalf("OperationIdId 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/dataprotection/2023-11-01/azurebackupjob/method_exportjobsoperationresultget.go b/resource-manager/dataprotection/2023-11-01/azurebackupjob/method_exportjobsoperationresultget.go new file mode 100644 index 00000000000..617b7587722 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/azurebackupjob/method_exportjobsoperationresultget.go @@ -0,0 +1,52 @@ +package azurebackupjob + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExportJobsOperationResultGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ExportJobsResult +} + +// ExportJobsOperationResultGet ... +func (c AzureBackupJobClient) ExportJobsOperationResultGet(ctx context.Context, id OperationIdId) (result ExportJobsOperationResultGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/dataprotection/2023-11-01/azurebackupjob/method_exportjobstrigger.go b/resource-manager/dataprotection/2023-11-01/azurebackupjob/method_exportjobstrigger.go new file mode 100644 index 00000000000..bd466398f8f --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/azurebackupjob/method_exportjobstrigger.go @@ -0,0 +1,70 @@ +package azurebackupjob + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExportJobsTriggerOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// ExportJobsTrigger ... +func (c AzureBackupJobClient) ExportJobsTrigger(ctx context.Context, id BackupVaultId) (result ExportJobsTriggerOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/exportBackupJobs", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// ExportJobsTriggerThenPoll performs ExportJobsTrigger then polls until it's completed +func (c AzureBackupJobClient) ExportJobsTriggerThenPoll(ctx context.Context, id BackupVaultId) error { + result, err := c.ExportJobsTrigger(ctx, id) + if err != nil { + return fmt.Errorf("performing ExportJobsTrigger: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after ExportJobsTrigger: %+v", err) + } + + return nil +} diff --git a/resource-manager/dataprotection/2023-11-01/azurebackupjob/method_jobsget.go b/resource-manager/dataprotection/2023-11-01/azurebackupjob/method_jobsget.go new file mode 100644 index 00000000000..ceff8077221 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/azurebackupjob/method_jobsget.go @@ -0,0 +1,51 @@ +package azurebackupjob + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobsGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AzureBackupJobResource +} + +// JobsGet ... +func (c AzureBackupJobClient) JobsGet(ctx context.Context, id BackupJobId) (result JobsGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/dataprotection/2023-11-01/azurebackupjob/model_azurebackupjob.go b/resource-manager/dataprotection/2023-11-01/azurebackupjob/model_azurebackupjob.go new file mode 100644 index 00000000000..cdd1d824b08 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/azurebackupjob/model_azurebackupjob.go @@ -0,0 +1,65 @@ +package azurebackupjob + +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 AzureBackupJob struct { + ActivityID string `json:"activityID"` + BackupInstanceFriendlyName string `json:"backupInstanceFriendlyName"` + BackupInstanceId *string `json:"backupInstanceId,omitempty"` + DataSourceId string `json:"dataSourceId"` + DataSourceLocation string `json:"dataSourceLocation"` + DataSourceName string `json:"dataSourceName"` + DataSourceSetName *string `json:"dataSourceSetName,omitempty"` + DataSourceType string `json:"dataSourceType"` + DestinationDataStoreName *string `json:"destinationDataStoreName,omitempty"` + Duration *string `json:"duration,omitempty"` + EndTime *string `json:"endTime,omitempty"` + ErrorDetails *[]UserFacingError `json:"errorDetails,omitempty"` + Etag *string `json:"etag,omitempty"` + ExtendedInfo *JobExtendedInfo `json:"extendedInfo,omitempty"` + IsUserTriggered bool `json:"isUserTriggered"` + Operation string `json:"operation"` + OperationCategory string `json:"operationCategory"` + PolicyId *string `json:"policyId,omitempty"` + PolicyName *string `json:"policyName,omitempty"` + ProgressEnabled bool `json:"progressEnabled"` + ProgressUrl *string `json:"progressUrl,omitempty"` + RehydrationPriority *string `json:"rehydrationPriority,omitempty"` + RestoreType *string `json:"restoreType,omitempty"` + SourceDataStoreName *string `json:"sourceDataStoreName,omitempty"` + SourceResourceGroup string `json:"sourceResourceGroup"` + SourceSubscriptionID string `json:"sourceSubscriptionID"` + StartTime string `json:"startTime"` + Status string `json:"status"` + SubscriptionId string `json:"subscriptionId"` + SupportedActions []string `json:"supportedActions"` + VaultName string `json:"vaultName"` +} + +func (o *AzureBackupJob) GetEndTimeAsTime() (*time.Time, error) { + if o.EndTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EndTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureBackupJob) SetEndTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EndTime = &formatted +} + +func (o *AzureBackupJob) GetStartTimeAsTime() (*time.Time, error) { + return dates.ParseAsFormat(&o.StartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureBackupJob) SetStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartTime = formatted +} diff --git a/resource-manager/dataprotection/2023-11-01/azurebackupjob/model_azurebackupjobresource.go b/resource-manager/dataprotection/2023-11-01/azurebackupjob/model_azurebackupjobresource.go new file mode 100644 index 00000000000..45faef86221 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/azurebackupjob/model_azurebackupjobresource.go @@ -0,0 +1,16 @@ +package azurebackupjob + +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 AzureBackupJobResource struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *AzureBackupJob `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/dataprotection/2023-11-01/azurebackupjob/model_exportjobsresult.go b/resource-manager/dataprotection/2023-11-01/azurebackupjob/model_exportjobsresult.go new file mode 100644 index 00000000000..75c7ef5aad4 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/azurebackupjob/model_exportjobsresult.go @@ -0,0 +1,11 @@ +package azurebackupjob + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExportJobsResult struct { + BlobSasKey *string `json:"blobSasKey,omitempty"` + BlobUrl *string `json:"blobUrl,omitempty"` + ExcelFileBlobSasKey *string `json:"excelFileBlobSasKey,omitempty"` + ExcelFileBlobUrl *string `json:"excelFileBlobUrl,omitempty"` +} diff --git a/resource-manager/dataprotection/2023-11-01/azurebackupjob/model_innererror.go b/resource-manager/dataprotection/2023-11-01/azurebackupjob/model_innererror.go new file mode 100644 index 00000000000..a44d4bdfa57 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/azurebackupjob/model_innererror.go @@ -0,0 +1,10 @@ +package azurebackupjob + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type InnerError struct { + AdditionalInfo *map[string]string `json:"additionalInfo,omitempty"` + Code *string `json:"code,omitempty"` + EmbeddedInnerError *InnerError `json:"embeddedInnerError,omitempty"` +} diff --git a/resource-manager/dataprotection/2023-11-01/azurebackupjob/model_jobextendedinfo.go b/resource-manager/dataprotection/2023-11-01/azurebackupjob/model_jobextendedinfo.go new file mode 100644 index 00000000000..9c0edd02f99 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/azurebackupjob/model_jobextendedinfo.go @@ -0,0 +1,15 @@ +package azurebackupjob + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobExtendedInfo struct { + AdditionalDetails *map[string]string `json:"additionalDetails,omitempty"` + BackupInstanceState *string `json:"backupInstanceState,omitempty"` + DataTransferredInBytes *float64 `json:"dataTransferredInBytes,omitempty"` + RecoveryDestination *string `json:"recoveryDestination,omitempty"` + SourceRecoverPoint *RestoreJobRecoveryPointDetails `json:"sourceRecoverPoint,omitempty"` + SubTasks *[]JobSubTask `json:"subTasks,omitempty"` + TargetRecoverPoint *RestoreJobRecoveryPointDetails `json:"targetRecoverPoint,omitempty"` + WarningDetails *[]UserFacingWarningDetail `json:"warningDetails,omitempty"` +} diff --git a/resource-manager/dataprotection/2023-11-01/azurebackupjob/model_jobsubtask.go b/resource-manager/dataprotection/2023-11-01/azurebackupjob/model_jobsubtask.go new file mode 100644 index 00000000000..9d4f15e734d --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/azurebackupjob/model_jobsubtask.go @@ -0,0 +1,12 @@ +package azurebackupjob + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobSubTask struct { + AdditionalDetails *map[string]string `json:"additionalDetails,omitempty"` + TaskId int64 `json:"taskId"` + TaskName string `json:"taskName"` + TaskProgress *string `json:"taskProgress,omitempty"` + TaskStatus string `json:"taskStatus"` +} diff --git a/resource-manager/dataprotection/2023-11-01/azurebackupjob/model_restorejobrecoverypointdetails.go b/resource-manager/dataprotection/2023-11-01/azurebackupjob/model_restorejobrecoverypointdetails.go new file mode 100644 index 00000000000..3737e75b44e --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/azurebackupjob/model_restorejobrecoverypointdetails.go @@ -0,0 +1,27 @@ +package azurebackupjob + +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 RestoreJobRecoveryPointDetails struct { + RecoveryPointID *string `json:"recoveryPointID,omitempty"` + RecoveryPointTime *string `json:"recoveryPointTime,omitempty"` +} + +func (o *RestoreJobRecoveryPointDetails) GetRecoveryPointTimeAsTime() (*time.Time, error) { + if o.RecoveryPointTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.RecoveryPointTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *RestoreJobRecoveryPointDetails) SetRecoveryPointTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.RecoveryPointTime = &formatted +} diff --git a/resource-manager/dataprotection/2023-11-01/azurebackupjob/model_userfacingerror.go b/resource-manager/dataprotection/2023-11-01/azurebackupjob/model_userfacingerror.go new file mode 100644 index 00000000000..0358f4179da --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/azurebackupjob/model_userfacingerror.go @@ -0,0 +1,16 @@ +package azurebackupjob + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UserFacingError struct { + Code *string `json:"code,omitempty"` + Details *[]UserFacingError `json:"details,omitempty"` + InnerError *InnerError `json:"innerError,omitempty"` + IsRetryable *bool `json:"isRetryable,omitempty"` + IsUserError *bool `json:"isUserError,omitempty"` + Message *string `json:"message,omitempty"` + Properties *map[string]string `json:"properties,omitempty"` + RecommendedAction *[]string `json:"recommendedAction,omitempty"` + Target *string `json:"target,omitempty"` +} diff --git a/resource-manager/dataprotection/2023-11-01/azurebackupjob/model_userfacingwarningdetail.go b/resource-manager/dataprotection/2023-11-01/azurebackupjob/model_userfacingwarningdetail.go new file mode 100644 index 00000000000..f943b79da1d --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/azurebackupjob/model_userfacingwarningdetail.go @@ -0,0 +1,9 @@ +package azurebackupjob + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UserFacingWarningDetail struct { + ResourceName *string `json:"resourceName,omitempty"` + Warning UserFacingError `json:"warning"` +} diff --git a/resource-manager/dataprotection/2023-11-01/azurebackupjob/version.go b/resource-manager/dataprotection/2023-11-01/azurebackupjob/version.go new file mode 100644 index 00000000000..3620cb9fbb7 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/azurebackupjob/version.go @@ -0,0 +1,12 @@ +package azurebackupjob + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-11-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/azurebackupjob/%s", defaultApiVersion) +} diff --git a/resource-manager/dataprotection/2023-11-01/azurebackupjobs/README.md b/resource-manager/dataprotection/2023-11-01/azurebackupjobs/README.md new file mode 100644 index 00000000000..c15e1cac90f --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/azurebackupjobs/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2023-11-01/azurebackupjobs` Documentation + +The `azurebackupjobs` SDK allows for interaction with the Azure Resource Manager Service `dataprotection` (API Version `2023-11-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2023-11-01/azurebackupjobs" +``` + + +### Client Initialization + +```go +client := azurebackupjobs.NewAzureBackupJobsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `AzureBackupJobsClient.JobsList` + +```go +ctx := context.TODO() +id := azurebackupjobs.NewBackupVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultValue") + +// alternatively `client.JobsList(ctx, id)` can be used to do batched pagination +items, err := client.JobsListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/dataprotection/2023-11-01/azurebackupjobs/client.go b/resource-manager/dataprotection/2023-11-01/azurebackupjobs/client.go new file mode 100644 index 00000000000..9cb5bb85556 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/azurebackupjobs/client.go @@ -0,0 +1,26 @@ +package azurebackupjobs + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureBackupJobsClient struct { + Client *resourcemanager.Client +} + +func NewAzureBackupJobsClientWithBaseURI(sdkApi sdkEnv.Api) (*AzureBackupJobsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "azurebackupjobs", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating AzureBackupJobsClient: %+v", err) + } + + return &AzureBackupJobsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/dataprotection/2023-11-01/azurebackupjobs/id_backupvault.go b/resource-manager/dataprotection/2023-11-01/azurebackupjobs/id_backupvault.go new file mode 100644 index 00000000000..1e8b4932b4c --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/azurebackupjobs/id_backupvault.go @@ -0,0 +1,125 @@ +package azurebackupjobs + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = BackupVaultId{} + +// BackupVaultId is a struct representing the Resource ID for a Backup Vault +type BackupVaultId struct { + SubscriptionId string + ResourceGroupName string + BackupVaultName string +} + +// NewBackupVaultID returns a new BackupVaultId struct +func NewBackupVaultID(subscriptionId string, resourceGroupName string, backupVaultName string) BackupVaultId { + return BackupVaultId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + BackupVaultName: backupVaultName, + } +} + +// ParseBackupVaultID parses 'input' into a BackupVaultId +func ParseBackupVaultID(input string) (*BackupVaultId, error) { + parser := resourceids.NewParserFromResourceIdType(BackupVaultId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BackupVaultId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseBackupVaultIDInsensitively parses 'input' case-insensitively into a BackupVaultId +// note: this method should only be used for API response data and not user input +func ParseBackupVaultIDInsensitively(input string) (*BackupVaultId, error) { + parser := resourceids.NewParserFromResourceIdType(BackupVaultId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BackupVaultId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *BackupVaultId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.BackupVaultName, ok = input.Parsed["backupVaultName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "backupVaultName", input) + } + + return nil +} + +// ValidateBackupVaultID checks that 'input' can be parsed as a Backup Vault ID +func ValidateBackupVaultID(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 := ParseBackupVaultID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Backup Vault ID +func (id BackupVaultId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DataProtection/backupVaults/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.BackupVaultName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Backup Vault ID +func (id BackupVaultId) 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("staticMicrosoftDataProtection", "Microsoft.DataProtection", "Microsoft.DataProtection"), + resourceids.StaticSegment("staticBackupVaults", "backupVaults", "backupVaults"), + resourceids.UserSpecifiedSegment("backupVaultName", "backupVaultValue"), + } +} + +// String returns a human-readable description of this Backup Vault ID +func (id BackupVaultId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Backup Vault Name: %q", id.BackupVaultName), + } + return fmt.Sprintf("Backup Vault (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/dataprotection/2023-11-01/azurebackupjobs/id_backupvault_test.go b/resource-manager/dataprotection/2023-11-01/azurebackupjobs/id_backupvault_test.go new file mode 100644 index 00000000000..c0528201a9c --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/azurebackupjobs/id_backupvault_test.go @@ -0,0 +1,282 @@ +package azurebackupjobs + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = BackupVaultId{} + +func TestNewBackupVaultID(t *testing.T) { + id := NewBackupVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultValue") + + 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.BackupVaultName != "backupVaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'BackupVaultName'", id.BackupVaultName, "backupVaultValue") + } +} + +func TestFormatBackupVaultID(t *testing.T) { + actual := NewBackupVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseBackupVaultID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BackupVaultId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue", + Expected: &BackupVaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + BackupVaultName: "backupVaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBackupVaultID(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.BackupVaultName != v.Expected.BackupVaultName { + t.Fatalf("Expected %q but got %q for BackupVaultName", v.Expected.BackupVaultName, actual.BackupVaultName) + } + + } +} + +func TestParseBackupVaultIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BackupVaultId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue", + Expected: &BackupVaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + BackupVaultName: "backupVaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtVaLuE", + Expected: &BackupVaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + BackupVaultName: "bAcKuPvAuLtVaLuE", + }, + }, + { + // 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.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBackupVaultIDInsensitively(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.BackupVaultName != v.Expected.BackupVaultName { + t.Fatalf("Expected %q but got %q for BackupVaultName", v.Expected.BackupVaultName, actual.BackupVaultName) + } + + } +} + +func TestSegmentsForBackupVaultId(t *testing.T) { + segments := BackupVaultId{}.Segments() + if len(segments) == 0 { + t.Fatalf("BackupVaultId 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/dataprotection/2023-11-01/azurebackupjobs/method_jobslist.go b/resource-manager/dataprotection/2023-11-01/azurebackupjobs/method_jobslist.go new file mode 100644 index 00000000000..4692d89c44a --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/azurebackupjobs/method_jobslist.go @@ -0,0 +1,89 @@ +package azurebackupjobs + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobsListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]AzureBackupJobResource +} + +type JobsListCompleteResult struct { + Items []AzureBackupJobResource +} + +// JobsList ... +func (c AzureBackupJobsClient) JobsList(ctx context.Context, id BackupVaultId) (result JobsListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/backupJobs", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]AzureBackupJobResource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// JobsListComplete retrieves all the results into a single object +func (c AzureBackupJobsClient) JobsListComplete(ctx context.Context, id BackupVaultId) (JobsListCompleteResult, error) { + return c.JobsListCompleteMatchingPredicate(ctx, id, AzureBackupJobResourceOperationPredicate{}) +} + +// JobsListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c AzureBackupJobsClient) JobsListCompleteMatchingPredicate(ctx context.Context, id BackupVaultId, predicate AzureBackupJobResourceOperationPredicate) (result JobsListCompleteResult, err error) { + items := make([]AzureBackupJobResource, 0) + + resp, err := c.JobsList(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = JobsListCompleteResult{ + Items: items, + } + return +} diff --git a/resource-manager/dataprotection/2023-11-01/azurebackupjobs/model_azurebackupjob.go b/resource-manager/dataprotection/2023-11-01/azurebackupjobs/model_azurebackupjob.go new file mode 100644 index 00000000000..c92a5895788 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/azurebackupjobs/model_azurebackupjob.go @@ -0,0 +1,65 @@ +package azurebackupjobs + +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 AzureBackupJob struct { + ActivityID string `json:"activityID"` + BackupInstanceFriendlyName string `json:"backupInstanceFriendlyName"` + BackupInstanceId *string `json:"backupInstanceId,omitempty"` + DataSourceId string `json:"dataSourceId"` + DataSourceLocation string `json:"dataSourceLocation"` + DataSourceName string `json:"dataSourceName"` + DataSourceSetName *string `json:"dataSourceSetName,omitempty"` + DataSourceType string `json:"dataSourceType"` + DestinationDataStoreName *string `json:"destinationDataStoreName,omitempty"` + Duration *string `json:"duration,omitempty"` + EndTime *string `json:"endTime,omitempty"` + ErrorDetails *[]UserFacingError `json:"errorDetails,omitempty"` + Etag *string `json:"etag,omitempty"` + ExtendedInfo *JobExtendedInfo `json:"extendedInfo,omitempty"` + IsUserTriggered bool `json:"isUserTriggered"` + Operation string `json:"operation"` + OperationCategory string `json:"operationCategory"` + PolicyId *string `json:"policyId,omitempty"` + PolicyName *string `json:"policyName,omitempty"` + ProgressEnabled bool `json:"progressEnabled"` + ProgressUrl *string `json:"progressUrl,omitempty"` + RehydrationPriority *string `json:"rehydrationPriority,omitempty"` + RestoreType *string `json:"restoreType,omitempty"` + SourceDataStoreName *string `json:"sourceDataStoreName,omitempty"` + SourceResourceGroup string `json:"sourceResourceGroup"` + SourceSubscriptionID string `json:"sourceSubscriptionID"` + StartTime string `json:"startTime"` + Status string `json:"status"` + SubscriptionId string `json:"subscriptionId"` + SupportedActions []string `json:"supportedActions"` + VaultName string `json:"vaultName"` +} + +func (o *AzureBackupJob) GetEndTimeAsTime() (*time.Time, error) { + if o.EndTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EndTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureBackupJob) SetEndTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EndTime = &formatted +} + +func (o *AzureBackupJob) GetStartTimeAsTime() (*time.Time, error) { + return dates.ParseAsFormat(&o.StartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureBackupJob) SetStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartTime = formatted +} diff --git a/resource-manager/dataprotection/2023-11-01/azurebackupjobs/model_azurebackupjobresource.go b/resource-manager/dataprotection/2023-11-01/azurebackupjobs/model_azurebackupjobresource.go new file mode 100644 index 00000000000..17c72e55e47 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/azurebackupjobs/model_azurebackupjobresource.go @@ -0,0 +1,16 @@ +package azurebackupjobs + +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 AzureBackupJobResource struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *AzureBackupJob `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/dataprotection/2023-11-01/azurebackupjobs/model_innererror.go b/resource-manager/dataprotection/2023-11-01/azurebackupjobs/model_innererror.go new file mode 100644 index 00000000000..323f65bc431 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/azurebackupjobs/model_innererror.go @@ -0,0 +1,10 @@ +package azurebackupjobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type InnerError struct { + AdditionalInfo *map[string]string `json:"additionalInfo,omitempty"` + Code *string `json:"code,omitempty"` + EmbeddedInnerError *InnerError `json:"embeddedInnerError,omitempty"` +} diff --git a/resource-manager/dataprotection/2023-11-01/azurebackupjobs/model_jobextendedinfo.go b/resource-manager/dataprotection/2023-11-01/azurebackupjobs/model_jobextendedinfo.go new file mode 100644 index 00000000000..2b210b62683 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/azurebackupjobs/model_jobextendedinfo.go @@ -0,0 +1,15 @@ +package azurebackupjobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobExtendedInfo struct { + AdditionalDetails *map[string]string `json:"additionalDetails,omitempty"` + BackupInstanceState *string `json:"backupInstanceState,omitempty"` + DataTransferredInBytes *float64 `json:"dataTransferredInBytes,omitempty"` + RecoveryDestination *string `json:"recoveryDestination,omitempty"` + SourceRecoverPoint *RestoreJobRecoveryPointDetails `json:"sourceRecoverPoint,omitempty"` + SubTasks *[]JobSubTask `json:"subTasks,omitempty"` + TargetRecoverPoint *RestoreJobRecoveryPointDetails `json:"targetRecoverPoint,omitempty"` + WarningDetails *[]UserFacingWarningDetail `json:"warningDetails,omitempty"` +} diff --git a/resource-manager/dataprotection/2023-11-01/azurebackupjobs/model_jobsubtask.go b/resource-manager/dataprotection/2023-11-01/azurebackupjobs/model_jobsubtask.go new file mode 100644 index 00000000000..0f42da0bc24 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/azurebackupjobs/model_jobsubtask.go @@ -0,0 +1,12 @@ +package azurebackupjobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobSubTask struct { + AdditionalDetails *map[string]string `json:"additionalDetails,omitempty"` + TaskId int64 `json:"taskId"` + TaskName string `json:"taskName"` + TaskProgress *string `json:"taskProgress,omitempty"` + TaskStatus string `json:"taskStatus"` +} diff --git a/resource-manager/dataprotection/2023-11-01/azurebackupjobs/model_restorejobrecoverypointdetails.go b/resource-manager/dataprotection/2023-11-01/azurebackupjobs/model_restorejobrecoverypointdetails.go new file mode 100644 index 00000000000..569a995bb39 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/azurebackupjobs/model_restorejobrecoverypointdetails.go @@ -0,0 +1,27 @@ +package azurebackupjobs + +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 RestoreJobRecoveryPointDetails struct { + RecoveryPointID *string `json:"recoveryPointID,omitempty"` + RecoveryPointTime *string `json:"recoveryPointTime,omitempty"` +} + +func (o *RestoreJobRecoveryPointDetails) GetRecoveryPointTimeAsTime() (*time.Time, error) { + if o.RecoveryPointTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.RecoveryPointTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *RestoreJobRecoveryPointDetails) SetRecoveryPointTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.RecoveryPointTime = &formatted +} diff --git a/resource-manager/dataprotection/2023-11-01/azurebackupjobs/model_userfacingerror.go b/resource-manager/dataprotection/2023-11-01/azurebackupjobs/model_userfacingerror.go new file mode 100644 index 00000000000..562e9fe4e79 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/azurebackupjobs/model_userfacingerror.go @@ -0,0 +1,16 @@ +package azurebackupjobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UserFacingError struct { + Code *string `json:"code,omitempty"` + Details *[]UserFacingError `json:"details,omitempty"` + InnerError *InnerError `json:"innerError,omitempty"` + IsRetryable *bool `json:"isRetryable,omitempty"` + IsUserError *bool `json:"isUserError,omitempty"` + Message *string `json:"message,omitempty"` + Properties *map[string]string `json:"properties,omitempty"` + RecommendedAction *[]string `json:"recommendedAction,omitempty"` + Target *string `json:"target,omitempty"` +} diff --git a/resource-manager/dataprotection/2023-11-01/azurebackupjobs/model_userfacingwarningdetail.go b/resource-manager/dataprotection/2023-11-01/azurebackupjobs/model_userfacingwarningdetail.go new file mode 100644 index 00000000000..5fdf9d22cc7 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/azurebackupjobs/model_userfacingwarningdetail.go @@ -0,0 +1,9 @@ +package azurebackupjobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UserFacingWarningDetail struct { + ResourceName *string `json:"resourceName,omitempty"` + Warning UserFacingError `json:"warning"` +} diff --git a/resource-manager/dataprotection/2023-11-01/azurebackupjobs/predicates.go b/resource-manager/dataprotection/2023-11-01/azurebackupjobs/predicates.go new file mode 100644 index 00000000000..5f79648ba7d --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/azurebackupjobs/predicates.go @@ -0,0 +1,27 @@ +package azurebackupjobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureBackupJobResourceOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p AzureBackupJobResourceOperationPredicate) Matches(input AzureBackupJobResource) 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/dataprotection/2023-11-01/azurebackupjobs/version.go b/resource-manager/dataprotection/2023-11-01/azurebackupjobs/version.go new file mode 100644 index 00000000000..3886d5b56ed --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/azurebackupjobs/version.go @@ -0,0 +1,12 @@ +package azurebackupjobs + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-11-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/azurebackupjobs/%s", defaultApiVersion) +} diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/README.md b/resource-manager/dataprotection/2023-11-01/backupinstances/README.md new file mode 100644 index 00000000000..975e77e520b --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/README.md @@ -0,0 +1,266 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2023-11-01/backupinstances` Documentation + +The `backupinstances` SDK allows for interaction with the Azure Resource Manager Service `dataprotection` (API Version `2023-11-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2023-11-01/backupinstances" +``` + + +### Client Initialization + +```go +client := backupinstances.NewBackupInstancesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `BackupInstancesClient.AdhocBackup` + +```go +ctx := context.TODO() +id := backupinstances.NewBackupInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultValue", "backupInstanceValue") + +payload := backupinstances.TriggerBackupRequest{ + // ... +} + + +if err := client.AdhocBackupThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `BackupInstancesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := backupinstances.NewBackupInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultValue", "backupInstanceValue") + +payload := backupinstances.BackupInstanceResource{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `BackupInstancesClient.Delete` + +```go +ctx := context.TODO() +id := backupinstances.NewBackupInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultValue", "backupInstanceValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `BackupInstancesClient.Get` + +```go +ctx := context.TODO() +id := backupinstances.NewBackupInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultValue", "backupInstanceValue") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `BackupInstancesClient.List` + +```go +ctx := context.TODO() +id := backupinstances.NewBackupVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultValue") + +// alternatively `client.List(ctx, id)` can be used to do batched pagination +items, err := client.ListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `BackupInstancesClient.ResumeBackups` + +```go +ctx := context.TODO() +id := backupinstances.NewBackupInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultValue", "backupInstanceValue") + +if err := client.ResumeBackupsThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `BackupInstancesClient.ResumeProtection` + +```go +ctx := context.TODO() +id := backupinstances.NewBackupInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultValue", "backupInstanceValue") + +if err := client.ResumeProtectionThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `BackupInstancesClient.StopProtection` + +```go +ctx := context.TODO() +id := backupinstances.NewBackupInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultValue", "backupInstanceValue") + +if err := client.StopProtectionThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `BackupInstancesClient.SuspendBackups` + +```go +ctx := context.TODO() +id := backupinstances.NewBackupInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultValue", "backupInstanceValue") + +if err := client.SuspendBackupsThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `BackupInstancesClient.SyncBackupInstance` + +```go +ctx := context.TODO() +id := backupinstances.NewBackupInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultValue", "backupInstanceValue") + +payload := backupinstances.SyncBackupInstanceRequest{ + // ... +} + + +if err := client.SyncBackupInstanceThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `BackupInstancesClient.TriggerCrossRegionRestore` + +```go +ctx := context.TODO() +id := backupinstances.NewProviderLocationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationValue") + +payload := backupinstances.CrossRegionRestoreRequestObject{ + // ... +} + + +if err := client.TriggerCrossRegionRestoreThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `BackupInstancesClient.TriggerRehydrate` + +```go +ctx := context.TODO() +id := backupinstances.NewBackupInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultValue", "backupInstanceValue") + +payload := backupinstances.AzureBackupRehydrationRequest{ + // ... +} + + +if err := client.TriggerRehydrateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `BackupInstancesClient.TriggerRestore` + +```go +ctx := context.TODO() +id := backupinstances.NewBackupInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultValue", "backupInstanceValue") + +payload := backupinstances.AzureBackupRestoreRequest{ + // ... +} + + +if err := client.TriggerRestoreThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `BackupInstancesClient.ValidateCrossRegionRestore` + +```go +ctx := context.TODO() +id := backupinstances.NewProviderLocationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationValue") + +payload := backupinstances.ValidateCrossRegionRestoreRequestObject{ + // ... +} + + +if err := client.ValidateCrossRegionRestoreThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `BackupInstancesClient.ValidateForBackup` + +```go +ctx := context.TODO() +id := backupinstances.NewBackupVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultValue") + +payload := backupinstances.ValidateForBackupRequest{ + // ... +} + + +if err := client.ValidateForBackupThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `BackupInstancesClient.ValidateForRestore` + +```go +ctx := context.TODO() +id := backupinstances.NewBackupInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultValue", "backupInstanceValue") + +payload := backupinstances.ValidateRestoreRequestObject{ + // ... +} + + +if err := client.ValidateForRestoreThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/client.go b/resource-manager/dataprotection/2023-11-01/backupinstances/client.go new file mode 100644 index 00000000000..9e37fa3fed5 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/client.go @@ -0,0 +1,26 @@ +package backupinstances + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackupInstancesClient struct { + Client *resourcemanager.Client +} + +func NewBackupInstancesClientWithBaseURI(sdkApi sdkEnv.Api) (*BackupInstancesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "backupinstances", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating BackupInstancesClient: %+v", err) + } + + return &BackupInstancesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/constants.go b/resource-manager/dataprotection/2023-11-01/backupinstances/constants.go new file mode 100644 index 00000000000..6ea153cb952 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/constants.go @@ -0,0 +1,594 @@ +package backupinstances + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CurrentProtectionState string + +const ( + CurrentProtectionStateBackupSchedulesSuspended CurrentProtectionState = "BackupSchedulesSuspended" + CurrentProtectionStateConfiguringProtection CurrentProtectionState = "ConfiguringProtection" + CurrentProtectionStateConfiguringProtectionFailed CurrentProtectionState = "ConfiguringProtectionFailed" + CurrentProtectionStateInvalid CurrentProtectionState = "Invalid" + CurrentProtectionStateNotProtected CurrentProtectionState = "NotProtected" + CurrentProtectionStateProtectionConfigured CurrentProtectionState = "ProtectionConfigured" + CurrentProtectionStateProtectionError CurrentProtectionState = "ProtectionError" + CurrentProtectionStateProtectionStopped CurrentProtectionState = "ProtectionStopped" + CurrentProtectionStateRetentionSchedulesSuspended CurrentProtectionState = "RetentionSchedulesSuspended" + CurrentProtectionStateSoftDeleted CurrentProtectionState = "SoftDeleted" + CurrentProtectionStateSoftDeleting CurrentProtectionState = "SoftDeleting" + CurrentProtectionStateUpdatingProtection CurrentProtectionState = "UpdatingProtection" +) + +func PossibleValuesForCurrentProtectionState() []string { + return []string{ + string(CurrentProtectionStateBackupSchedulesSuspended), + string(CurrentProtectionStateConfiguringProtection), + string(CurrentProtectionStateConfiguringProtectionFailed), + string(CurrentProtectionStateInvalid), + string(CurrentProtectionStateNotProtected), + string(CurrentProtectionStateProtectionConfigured), + string(CurrentProtectionStateProtectionError), + string(CurrentProtectionStateProtectionStopped), + string(CurrentProtectionStateRetentionSchedulesSuspended), + string(CurrentProtectionStateSoftDeleted), + string(CurrentProtectionStateSoftDeleting), + string(CurrentProtectionStateUpdatingProtection), + } +} + +func (s *CurrentProtectionState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCurrentProtectionState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCurrentProtectionState(input string) (*CurrentProtectionState, error) { + vals := map[string]CurrentProtectionState{ + "backupschedulessuspended": CurrentProtectionStateBackupSchedulesSuspended, + "configuringprotection": CurrentProtectionStateConfiguringProtection, + "configuringprotectionfailed": CurrentProtectionStateConfiguringProtectionFailed, + "invalid": CurrentProtectionStateInvalid, + "notprotected": CurrentProtectionStateNotProtected, + "protectionconfigured": CurrentProtectionStateProtectionConfigured, + "protectionerror": CurrentProtectionStateProtectionError, + "protectionstopped": CurrentProtectionStateProtectionStopped, + "retentionschedulessuspended": CurrentProtectionStateRetentionSchedulesSuspended, + "softdeleted": CurrentProtectionStateSoftDeleted, + "softdeleting": CurrentProtectionStateSoftDeleting, + "updatingprotection": CurrentProtectionStateUpdatingProtection, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CurrentProtectionState(input) + return &out, nil +} + +type DataStoreTypes string + +const ( + DataStoreTypesArchiveStore DataStoreTypes = "ArchiveStore" + DataStoreTypesOperationalStore DataStoreTypes = "OperationalStore" + DataStoreTypesVaultStore DataStoreTypes = "VaultStore" +) + +func PossibleValuesForDataStoreTypes() []string { + return []string{ + string(DataStoreTypesArchiveStore), + string(DataStoreTypesOperationalStore), + string(DataStoreTypesVaultStore), + } +} + +func (s *DataStoreTypes) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDataStoreTypes(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDataStoreTypes(input string) (*DataStoreTypes, error) { + vals := map[string]DataStoreTypes{ + "archivestore": DataStoreTypesArchiveStore, + "operationalstore": DataStoreTypesOperationalStore, + "vaultstore": DataStoreTypesVaultStore, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DataStoreTypes(input) + return &out, nil +} + +type ExistingResourcePolicy string + +const ( + ExistingResourcePolicyPatch ExistingResourcePolicy = "Patch" + ExistingResourcePolicySkip ExistingResourcePolicy = "Skip" +) + +func PossibleValuesForExistingResourcePolicy() []string { + return []string{ + string(ExistingResourcePolicyPatch), + string(ExistingResourcePolicySkip), + } +} + +func (s *ExistingResourcePolicy) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseExistingResourcePolicy(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseExistingResourcePolicy(input string) (*ExistingResourcePolicy, error) { + vals := map[string]ExistingResourcePolicy{ + "patch": ExistingResourcePolicyPatch, + "skip": ExistingResourcePolicySkip, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ExistingResourcePolicy(input) + return &out, nil +} + +type PersistentVolumeRestoreMode string + +const ( + PersistentVolumeRestoreModeRestoreWithVolumeData PersistentVolumeRestoreMode = "RestoreWithVolumeData" + PersistentVolumeRestoreModeRestoreWithoutVolumeData PersistentVolumeRestoreMode = "RestoreWithoutVolumeData" +) + +func PossibleValuesForPersistentVolumeRestoreMode() []string { + return []string{ + string(PersistentVolumeRestoreModeRestoreWithVolumeData), + string(PersistentVolumeRestoreModeRestoreWithoutVolumeData), + } +} + +func (s *PersistentVolumeRestoreMode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePersistentVolumeRestoreMode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePersistentVolumeRestoreMode(input string) (*PersistentVolumeRestoreMode, error) { + vals := map[string]PersistentVolumeRestoreMode{ + "restorewithvolumedata": PersistentVolumeRestoreModeRestoreWithVolumeData, + "restorewithoutvolumedata": PersistentVolumeRestoreModeRestoreWithoutVolumeData, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PersistentVolumeRestoreMode(input) + return &out, nil +} + +type RecoveryOption string + +const ( + RecoveryOptionFailIfExists RecoveryOption = "FailIfExists" +) + +func PossibleValuesForRecoveryOption() []string { + return []string{ + string(RecoveryOptionFailIfExists), + } +} + +func (s *RecoveryOption) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRecoveryOption(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRecoveryOption(input string) (*RecoveryOption, error) { + vals := map[string]RecoveryOption{ + "failifexists": RecoveryOptionFailIfExists, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RecoveryOption(input) + return &out, nil +} + +type RehydrationPriority string + +const ( + RehydrationPriorityHigh RehydrationPriority = "High" + RehydrationPriorityInvalid RehydrationPriority = "Invalid" + RehydrationPriorityStandard RehydrationPriority = "Standard" +) + +func PossibleValuesForRehydrationPriority() []string { + return []string{ + string(RehydrationPriorityHigh), + string(RehydrationPriorityInvalid), + string(RehydrationPriorityStandard), + } +} + +func (s *RehydrationPriority) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRehydrationPriority(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRehydrationPriority(input string) (*RehydrationPriority, error) { + vals := map[string]RehydrationPriority{ + "high": RehydrationPriorityHigh, + "invalid": RehydrationPriorityInvalid, + "standard": RehydrationPriorityStandard, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RehydrationPriority(input) + return &out, nil +} + +type ResourcePropertiesObjectType string + +const ( + ResourcePropertiesObjectTypeDefaultResourceProperties ResourcePropertiesObjectType = "DefaultResourceProperties" +) + +func PossibleValuesForResourcePropertiesObjectType() []string { + return []string{ + string(ResourcePropertiesObjectTypeDefaultResourceProperties), + } +} + +func (s *ResourcePropertiesObjectType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseResourcePropertiesObjectType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseResourcePropertiesObjectType(input string) (*ResourcePropertiesObjectType, error) { + vals := map[string]ResourcePropertiesObjectType{ + "defaultresourceproperties": ResourcePropertiesObjectTypeDefaultResourceProperties, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ResourcePropertiesObjectType(input) + return &out, nil +} + +type RestoreTargetLocationType string + +const ( + RestoreTargetLocationTypeAzureBlobs RestoreTargetLocationType = "AzureBlobs" + RestoreTargetLocationTypeAzureFiles RestoreTargetLocationType = "AzureFiles" + RestoreTargetLocationTypeInvalid RestoreTargetLocationType = "Invalid" +) + +func PossibleValuesForRestoreTargetLocationType() []string { + return []string{ + string(RestoreTargetLocationTypeAzureBlobs), + string(RestoreTargetLocationTypeAzureFiles), + string(RestoreTargetLocationTypeInvalid), + } +} + +func (s *RestoreTargetLocationType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRestoreTargetLocationType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRestoreTargetLocationType(input string) (*RestoreTargetLocationType, error) { + vals := map[string]RestoreTargetLocationType{ + "azureblobs": RestoreTargetLocationTypeAzureBlobs, + "azurefiles": RestoreTargetLocationTypeAzureFiles, + "invalid": RestoreTargetLocationTypeInvalid, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RestoreTargetLocationType(input) + return &out, nil +} + +type SecretStoreType string + +const ( + SecretStoreTypeAzureKeyVault SecretStoreType = "AzureKeyVault" + SecretStoreTypeInvalid SecretStoreType = "Invalid" +) + +func PossibleValuesForSecretStoreType() []string { + return []string{ + string(SecretStoreTypeAzureKeyVault), + string(SecretStoreTypeInvalid), + } +} + +func (s *SecretStoreType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSecretStoreType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSecretStoreType(input string) (*SecretStoreType, error) { + vals := map[string]SecretStoreType{ + "azurekeyvault": SecretStoreTypeAzureKeyVault, + "invalid": SecretStoreTypeInvalid, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SecretStoreType(input) + return &out, nil +} + +type SourceDataStoreType string + +const ( + SourceDataStoreTypeArchiveStore SourceDataStoreType = "ArchiveStore" + SourceDataStoreTypeOperationalStore SourceDataStoreType = "OperationalStore" + SourceDataStoreTypeSnapshotStore SourceDataStoreType = "SnapshotStore" + SourceDataStoreTypeVaultStore SourceDataStoreType = "VaultStore" +) + +func PossibleValuesForSourceDataStoreType() []string { + return []string{ + string(SourceDataStoreTypeArchiveStore), + string(SourceDataStoreTypeOperationalStore), + string(SourceDataStoreTypeSnapshotStore), + string(SourceDataStoreTypeVaultStore), + } +} + +func (s *SourceDataStoreType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSourceDataStoreType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSourceDataStoreType(input string) (*SourceDataStoreType, error) { + vals := map[string]SourceDataStoreType{ + "archivestore": SourceDataStoreTypeArchiveStore, + "operationalstore": SourceDataStoreTypeOperationalStore, + "snapshotstore": SourceDataStoreTypeSnapshotStore, + "vaultstore": SourceDataStoreTypeVaultStore, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SourceDataStoreType(input) + return &out, nil +} + +type Status string + +const ( + StatusConfiguringProtection Status = "ConfiguringProtection" + StatusConfiguringProtectionFailed Status = "ConfiguringProtectionFailed" + StatusProtectionConfigured Status = "ProtectionConfigured" + StatusProtectionStopped Status = "ProtectionStopped" + StatusSoftDeleted Status = "SoftDeleted" + StatusSoftDeleting Status = "SoftDeleting" +) + +func PossibleValuesForStatus() []string { + return []string{ + string(StatusConfiguringProtection), + string(StatusConfiguringProtectionFailed), + string(StatusProtectionConfigured), + string(StatusProtectionStopped), + string(StatusSoftDeleted), + string(StatusSoftDeleting), + } +} + +func (s *Status) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseStatus(input string) (*Status, error) { + vals := map[string]Status{ + "configuringprotection": StatusConfiguringProtection, + "configuringprotectionfailed": StatusConfiguringProtectionFailed, + "protectionconfigured": StatusProtectionConfigured, + "protectionstopped": StatusProtectionStopped, + "softdeleted": StatusSoftDeleted, + "softdeleting": StatusSoftDeleting, + } + 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 SyncType string + +const ( + SyncTypeDefault SyncType = "Default" + SyncTypeForceResync SyncType = "ForceResync" +) + +func PossibleValuesForSyncType() []string { + return []string{ + string(SyncTypeDefault), + string(SyncTypeForceResync), + } +} + +func (s *SyncType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSyncType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSyncType(input string) (*SyncType, error) { + vals := map[string]SyncType{ + "default": SyncTypeDefault, + "forceresync": SyncTypeForceResync, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SyncType(input) + return &out, nil +} + +type ValidationType string + +const ( + ValidationTypeDeepValidation ValidationType = "DeepValidation" + ValidationTypeShallowValidation ValidationType = "ShallowValidation" +) + +func PossibleValuesForValidationType() []string { + return []string{ + string(ValidationTypeDeepValidation), + string(ValidationTypeShallowValidation), + } +} + +func (s *ValidationType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseValidationType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseValidationType(input string) (*ValidationType, error) { + vals := map[string]ValidationType{ + "deepvalidation": ValidationTypeDeepValidation, + "shallowvalidation": ValidationTypeShallowValidation, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ValidationType(input) + return &out, nil +} diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/id_backupinstance.go b/resource-manager/dataprotection/2023-11-01/backupinstances/id_backupinstance.go new file mode 100644 index 00000000000..2ed30ac3214 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/id_backupinstance.go @@ -0,0 +1,134 @@ +package backupinstances + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = BackupInstanceId{} + +// BackupInstanceId is a struct representing the Resource ID for a Backup Instance +type BackupInstanceId struct { + SubscriptionId string + ResourceGroupName string + BackupVaultName string + BackupInstanceName string +} + +// NewBackupInstanceID returns a new BackupInstanceId struct +func NewBackupInstanceID(subscriptionId string, resourceGroupName string, backupVaultName string, backupInstanceName string) BackupInstanceId { + return BackupInstanceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + BackupVaultName: backupVaultName, + BackupInstanceName: backupInstanceName, + } +} + +// ParseBackupInstanceID parses 'input' into a BackupInstanceId +func ParseBackupInstanceID(input string) (*BackupInstanceId, error) { + parser := resourceids.NewParserFromResourceIdType(BackupInstanceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BackupInstanceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseBackupInstanceIDInsensitively parses 'input' case-insensitively into a BackupInstanceId +// note: this method should only be used for API response data and not user input +func ParseBackupInstanceIDInsensitively(input string) (*BackupInstanceId, error) { + parser := resourceids.NewParserFromResourceIdType(BackupInstanceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BackupInstanceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *BackupInstanceId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.BackupVaultName, ok = input.Parsed["backupVaultName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "backupVaultName", input) + } + + if id.BackupInstanceName, ok = input.Parsed["backupInstanceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "backupInstanceName", input) + } + + return nil +} + +// ValidateBackupInstanceID checks that 'input' can be parsed as a Backup Instance ID +func ValidateBackupInstanceID(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 := ParseBackupInstanceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Backup Instance ID +func (id BackupInstanceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DataProtection/backupVaults/%s/backupInstances/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.BackupVaultName, id.BackupInstanceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Backup Instance ID +func (id BackupInstanceId) 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("staticMicrosoftDataProtection", "Microsoft.DataProtection", "Microsoft.DataProtection"), + resourceids.StaticSegment("staticBackupVaults", "backupVaults", "backupVaults"), + resourceids.UserSpecifiedSegment("backupVaultName", "backupVaultValue"), + resourceids.StaticSegment("staticBackupInstances", "backupInstances", "backupInstances"), + resourceids.UserSpecifiedSegment("backupInstanceName", "backupInstanceValue"), + } +} + +// String returns a human-readable description of this Backup Instance ID +func (id BackupInstanceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Backup Vault Name: %q", id.BackupVaultName), + fmt.Sprintf("Backup Instance Name: %q", id.BackupInstanceName), + } + return fmt.Sprintf("Backup Instance (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/id_backupinstance_test.go b/resource-manager/dataprotection/2023-11-01/backupinstances/id_backupinstance_test.go new file mode 100644 index 00000000000..2d4f081cf7e --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/id_backupinstance_test.go @@ -0,0 +1,327 @@ +package backupinstances + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = BackupInstanceId{} + +func TestNewBackupInstanceID(t *testing.T) { + id := NewBackupInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultValue", "backupInstanceValue") + + 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.BackupVaultName != "backupVaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'BackupVaultName'", id.BackupVaultName, "backupVaultValue") + } + + if id.BackupInstanceName != "backupInstanceValue" { + t.Fatalf("Expected %q but got %q for Segment 'BackupInstanceName'", id.BackupInstanceName, "backupInstanceValue") + } +} + +func TestFormatBackupInstanceID(t *testing.T) { + actual := NewBackupInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultValue", "backupInstanceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/backupInstances/backupInstanceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseBackupInstanceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BackupInstanceId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/backupInstances", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/backupInstances/backupInstanceValue", + Expected: &BackupInstanceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + BackupVaultName: "backupVaultValue", + BackupInstanceName: "backupInstanceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/backupInstances/backupInstanceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBackupInstanceID(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.BackupVaultName != v.Expected.BackupVaultName { + t.Fatalf("Expected %q but got %q for BackupVaultName", v.Expected.BackupVaultName, actual.BackupVaultName) + } + + if actual.BackupInstanceName != v.Expected.BackupInstanceName { + t.Fatalf("Expected %q but got %q for BackupInstanceName", v.Expected.BackupInstanceName, actual.BackupInstanceName) + } + + } +} + +func TestParseBackupInstanceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BackupInstanceId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/backupInstances", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtVaLuE/bAcKuPiNsTaNcEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/backupInstances/backupInstanceValue", + Expected: &BackupInstanceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + BackupVaultName: "backupVaultValue", + BackupInstanceName: "backupInstanceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/backupInstances/backupInstanceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtVaLuE/bAcKuPiNsTaNcEs/bAcKuPiNsTaNcEvAlUe", + Expected: &BackupInstanceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + BackupVaultName: "bAcKuPvAuLtVaLuE", + BackupInstanceName: "bAcKuPiNsTaNcEvAlUe", + }, + }, + { + // 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.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtVaLuE/bAcKuPiNsTaNcEs/bAcKuPiNsTaNcEvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBackupInstanceIDInsensitively(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.BackupVaultName != v.Expected.BackupVaultName { + t.Fatalf("Expected %q but got %q for BackupVaultName", v.Expected.BackupVaultName, actual.BackupVaultName) + } + + if actual.BackupInstanceName != v.Expected.BackupInstanceName { + t.Fatalf("Expected %q but got %q for BackupInstanceName", v.Expected.BackupInstanceName, actual.BackupInstanceName) + } + + } +} + +func TestSegmentsForBackupInstanceId(t *testing.T) { + segments := BackupInstanceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("BackupInstanceId 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/dataprotection/2023-11-01/backupinstances/id_backupvault.go b/resource-manager/dataprotection/2023-11-01/backupinstances/id_backupvault.go new file mode 100644 index 00000000000..51e9b47f9af --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/id_backupvault.go @@ -0,0 +1,125 @@ +package backupinstances + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = BackupVaultId{} + +// BackupVaultId is a struct representing the Resource ID for a Backup Vault +type BackupVaultId struct { + SubscriptionId string + ResourceGroupName string + BackupVaultName string +} + +// NewBackupVaultID returns a new BackupVaultId struct +func NewBackupVaultID(subscriptionId string, resourceGroupName string, backupVaultName string) BackupVaultId { + return BackupVaultId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + BackupVaultName: backupVaultName, + } +} + +// ParseBackupVaultID parses 'input' into a BackupVaultId +func ParseBackupVaultID(input string) (*BackupVaultId, error) { + parser := resourceids.NewParserFromResourceIdType(BackupVaultId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BackupVaultId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseBackupVaultIDInsensitively parses 'input' case-insensitively into a BackupVaultId +// note: this method should only be used for API response data and not user input +func ParseBackupVaultIDInsensitively(input string) (*BackupVaultId, error) { + parser := resourceids.NewParserFromResourceIdType(BackupVaultId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BackupVaultId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *BackupVaultId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.BackupVaultName, ok = input.Parsed["backupVaultName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "backupVaultName", input) + } + + return nil +} + +// ValidateBackupVaultID checks that 'input' can be parsed as a Backup Vault ID +func ValidateBackupVaultID(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 := ParseBackupVaultID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Backup Vault ID +func (id BackupVaultId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DataProtection/backupVaults/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.BackupVaultName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Backup Vault ID +func (id BackupVaultId) 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("staticMicrosoftDataProtection", "Microsoft.DataProtection", "Microsoft.DataProtection"), + resourceids.StaticSegment("staticBackupVaults", "backupVaults", "backupVaults"), + resourceids.UserSpecifiedSegment("backupVaultName", "backupVaultValue"), + } +} + +// String returns a human-readable description of this Backup Vault ID +func (id BackupVaultId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Backup Vault Name: %q", id.BackupVaultName), + } + return fmt.Sprintf("Backup Vault (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/id_backupvault_test.go b/resource-manager/dataprotection/2023-11-01/backupinstances/id_backupvault_test.go new file mode 100644 index 00000000000..70b3e652c7f --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/id_backupvault_test.go @@ -0,0 +1,282 @@ +package backupinstances + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = BackupVaultId{} + +func TestNewBackupVaultID(t *testing.T) { + id := NewBackupVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultValue") + + 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.BackupVaultName != "backupVaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'BackupVaultName'", id.BackupVaultName, "backupVaultValue") + } +} + +func TestFormatBackupVaultID(t *testing.T) { + actual := NewBackupVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseBackupVaultID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BackupVaultId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue", + Expected: &BackupVaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + BackupVaultName: "backupVaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBackupVaultID(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.BackupVaultName != v.Expected.BackupVaultName { + t.Fatalf("Expected %q but got %q for BackupVaultName", v.Expected.BackupVaultName, actual.BackupVaultName) + } + + } +} + +func TestParseBackupVaultIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BackupVaultId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue", + Expected: &BackupVaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + BackupVaultName: "backupVaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtVaLuE", + Expected: &BackupVaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + BackupVaultName: "bAcKuPvAuLtVaLuE", + }, + }, + { + // 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.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBackupVaultIDInsensitively(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.BackupVaultName != v.Expected.BackupVaultName { + t.Fatalf("Expected %q but got %q for BackupVaultName", v.Expected.BackupVaultName, actual.BackupVaultName) + } + + } +} + +func TestSegmentsForBackupVaultId(t *testing.T) { + segments := BackupVaultId{}.Segments() + if len(segments) == 0 { + t.Fatalf("BackupVaultId 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/dataprotection/2023-11-01/backupinstances/id_providerlocation.go b/resource-manager/dataprotection/2023-11-01/backupinstances/id_providerlocation.go new file mode 100644 index 00000000000..d0d82fff5da --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/id_providerlocation.go @@ -0,0 +1,125 @@ +package backupinstances + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = ProviderLocationId{} + +// ProviderLocationId is a struct representing the Resource ID for a Provider Location +type ProviderLocationId struct { + SubscriptionId string + ResourceGroupName string + LocationName string +} + +// NewProviderLocationID returns a new ProviderLocationId struct +func NewProviderLocationID(subscriptionId string, resourceGroupName string, locationName string) ProviderLocationId { + return ProviderLocationId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + LocationName: locationName, + } +} + +// ParseProviderLocationID parses 'input' into a ProviderLocationId +func ParseProviderLocationID(input string) (*ProviderLocationId, error) { + parser := resourceids.NewParserFromResourceIdType(ProviderLocationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProviderLocationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseProviderLocationIDInsensitively parses 'input' case-insensitively into a ProviderLocationId +// note: this method should only be used for API response data and not user input +func ParseProviderLocationIDInsensitively(input string) (*ProviderLocationId, error) { + parser := resourceids.NewParserFromResourceIdType(ProviderLocationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProviderLocationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ProviderLocationId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.LocationName, ok = input.Parsed["locationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "locationName", input) + } + + return nil +} + +// ValidateProviderLocationID checks that 'input' can be parsed as a Provider Location ID +func ValidateProviderLocationID(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 := ParseProviderLocationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Provider Location ID +func (id ProviderLocationId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DataProtection/locations/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.LocationName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Provider Location ID +func (id ProviderLocationId) 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("staticMicrosoftDataProtection", "Microsoft.DataProtection", "Microsoft.DataProtection"), + resourceids.StaticSegment("staticLocations", "locations", "locations"), + resourceids.UserSpecifiedSegment("locationName", "locationValue"), + } +} + +// String returns a human-readable description of this Provider Location ID +func (id ProviderLocationId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Location Name: %q", id.LocationName), + } + return fmt.Sprintf("Provider Location (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/id_providerlocation_test.go b/resource-manager/dataprotection/2023-11-01/backupinstances/id_providerlocation_test.go new file mode 100644 index 00000000000..8be0a5bbec8 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/id_providerlocation_test.go @@ -0,0 +1,282 @@ +package backupinstances + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = ProviderLocationId{} + +func TestNewProviderLocationID(t *testing.T) { + id := NewProviderLocationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.LocationName != "locationValue" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationValue") + } +} + +func TestFormatProviderLocationID(t *testing.T) { + actual := NewProviderLocationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/locations/locationValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProviderLocationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProviderLocationId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/locations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/locations/locationValue", + Expected: &ProviderLocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/locations/locationValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProviderLocationID(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.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + } +} + +func TestParseProviderLocationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProviderLocationId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/lOcAtIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/locations/locationValue", + Expected: &ProviderLocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/locations/locationValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/lOcAtIoNs/lOcAtIoNvAlUe", + Expected: &ProviderLocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + LocationName: "lOcAtIoNvAlUe", + }, + }, + { + // 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.dAtApRoTeCtIoN/lOcAtIoNs/lOcAtIoNvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProviderLocationIDInsensitively(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.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + } +} + +func TestSegmentsForProviderLocationId(t *testing.T) { + segments := ProviderLocationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ProviderLocationId 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/dataprotection/2023-11-01/backupinstances/method_adhocbackup.go b/resource-manager/dataprotection/2023-11-01/backupinstances/method_adhocbackup.go new file mode 100644 index 00000000000..ea9ebc64260 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/method_adhocbackup.go @@ -0,0 +1,74 @@ +package backupinstances + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AdhocBackupOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// AdhocBackup ... +func (c BackupInstancesClient) AdhocBackup(ctx context.Context, id BackupInstanceId, input TriggerBackupRequest) (result AdhocBackupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/backup", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// AdhocBackupThenPoll performs AdhocBackup then polls until it's completed +func (c BackupInstancesClient) AdhocBackupThenPoll(ctx context.Context, id BackupInstanceId, input TriggerBackupRequest) error { + result, err := c.AdhocBackup(ctx, id, input) + if err != nil { + return fmt.Errorf("performing AdhocBackup: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after AdhocBackup: %+v", err) + } + + return nil +} diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/method_createorupdate.go b/resource-manager/dataprotection/2023-11-01/backupinstances/method_createorupdate.go new file mode 100644 index 00000000000..44d031d1be3 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/method_createorupdate.go @@ -0,0 +1,75 @@ +package backupinstances + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// CreateOrUpdate ... +func (c BackupInstancesClient) CreateOrUpdate(ctx context.Context, id BackupInstanceId, input BackupInstanceResource) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c BackupInstancesClient) CreateOrUpdateThenPoll(ctx context.Context, id BackupInstanceId, input BackupInstanceResource) error { + result, err := c.CreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing CreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after CreateOrUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/method_delete.go b/resource-manager/dataprotection/2023-11-01/backupinstances/method_delete.go new file mode 100644 index 00000000000..c51e5ec7240 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/method_delete.go @@ -0,0 +1,71 @@ +package backupinstances + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c BackupInstancesClient) Delete(ctx context.Context, id BackupInstanceId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c BackupInstancesClient) DeleteThenPoll(ctx context.Context, id BackupInstanceId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/method_get.go b/resource-manager/dataprotection/2023-11-01/backupinstances/method_get.go new file mode 100644 index 00000000000..8a6c4c4ea27 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/method_get.go @@ -0,0 +1,51 @@ +package backupinstances + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *BackupInstanceResource +} + +// Get ... +func (c BackupInstancesClient) Get(ctx context.Context, id BackupInstanceId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/method_list.go b/resource-manager/dataprotection/2023-11-01/backupinstances/method_list.go new file mode 100644 index 00000000000..eed9c76eabb --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/method_list.go @@ -0,0 +1,89 @@ +package backupinstances + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]BackupInstanceResource +} + +type ListCompleteResult struct { + Items []BackupInstanceResource +} + +// List ... +func (c BackupInstancesClient) List(ctx context.Context, id BackupVaultId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/backupInstances", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]BackupInstanceResource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c BackupInstancesClient) ListComplete(ctx context.Context, id BackupVaultId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, BackupInstanceResourceOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c BackupInstancesClient) ListCompleteMatchingPredicate(ctx context.Context, id BackupVaultId, predicate BackupInstanceResourceOperationPredicate) (result ListCompleteResult, err error) { + items := make([]BackupInstanceResource, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + Items: items, + } + return +} diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/method_resumebackups.go b/resource-manager/dataprotection/2023-11-01/backupinstances/method_resumebackups.go new file mode 100644 index 00000000000..afecf4c1dbc --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/method_resumebackups.go @@ -0,0 +1,70 @@ +package backupinstances + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResumeBackupsOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// ResumeBackups ... +func (c BackupInstancesClient) ResumeBackups(ctx context.Context, id BackupInstanceId) (result ResumeBackupsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/resumeBackups", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// ResumeBackupsThenPoll performs ResumeBackups then polls until it's completed +func (c BackupInstancesClient) ResumeBackupsThenPoll(ctx context.Context, id BackupInstanceId) error { + result, err := c.ResumeBackups(ctx, id) + if err != nil { + return fmt.Errorf("performing ResumeBackups: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after ResumeBackups: %+v", err) + } + + return nil +} diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/method_resumeprotection.go b/resource-manager/dataprotection/2023-11-01/backupinstances/method_resumeprotection.go new file mode 100644 index 00000000000..5903e05788c --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/method_resumeprotection.go @@ -0,0 +1,70 @@ +package backupinstances + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResumeProtectionOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// ResumeProtection ... +func (c BackupInstancesClient) ResumeProtection(ctx context.Context, id BackupInstanceId) (result ResumeProtectionOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/resumeProtection", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// ResumeProtectionThenPoll performs ResumeProtection then polls until it's completed +func (c BackupInstancesClient) ResumeProtectionThenPoll(ctx context.Context, id BackupInstanceId) error { + result, err := c.ResumeProtection(ctx, id) + if err != nil { + return fmt.Errorf("performing ResumeProtection: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after ResumeProtection: %+v", err) + } + + return nil +} diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/method_stopprotection.go b/resource-manager/dataprotection/2023-11-01/backupinstances/method_stopprotection.go new file mode 100644 index 00000000000..680e5671808 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/method_stopprotection.go @@ -0,0 +1,70 @@ +package backupinstances + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StopProtectionOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// StopProtection ... +func (c BackupInstancesClient) StopProtection(ctx context.Context, id BackupInstanceId) (result StopProtectionOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/stopProtection", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// StopProtectionThenPoll performs StopProtection then polls until it's completed +func (c BackupInstancesClient) StopProtectionThenPoll(ctx context.Context, id BackupInstanceId) error { + result, err := c.StopProtection(ctx, id) + if err != nil { + return fmt.Errorf("performing StopProtection: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after StopProtection: %+v", err) + } + + return nil +} diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/method_suspendbackups.go b/resource-manager/dataprotection/2023-11-01/backupinstances/method_suspendbackups.go new file mode 100644 index 00000000000..116fc13d6bf --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/method_suspendbackups.go @@ -0,0 +1,70 @@ +package backupinstances + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SuspendBackupsOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// SuspendBackups ... +func (c BackupInstancesClient) SuspendBackups(ctx context.Context, id BackupInstanceId) (result SuspendBackupsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/suspendBackups", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// SuspendBackupsThenPoll performs SuspendBackups then polls until it's completed +func (c BackupInstancesClient) SuspendBackupsThenPoll(ctx context.Context, id BackupInstanceId) error { + result, err := c.SuspendBackups(ctx, id) + if err != nil { + return fmt.Errorf("performing SuspendBackups: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after SuspendBackups: %+v", err) + } + + return nil +} diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/method_syncbackupinstance.go b/resource-manager/dataprotection/2023-11-01/backupinstances/method_syncbackupinstance.go new file mode 100644 index 00000000000..b91587d0462 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/method_syncbackupinstance.go @@ -0,0 +1,74 @@ +package backupinstances + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SyncBackupInstanceOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// SyncBackupInstance ... +func (c BackupInstancesClient) SyncBackupInstance(ctx context.Context, id BackupInstanceId, input SyncBackupInstanceRequest) (result SyncBackupInstanceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/sync", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// SyncBackupInstanceThenPoll performs SyncBackupInstance then polls until it's completed +func (c BackupInstancesClient) SyncBackupInstanceThenPoll(ctx context.Context, id BackupInstanceId, input SyncBackupInstanceRequest) error { + result, err := c.SyncBackupInstance(ctx, id, input) + if err != nil { + return fmt.Errorf("performing SyncBackupInstance: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after SyncBackupInstance: %+v", err) + } + + return nil +} diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/method_triggercrossregionrestore.go b/resource-manager/dataprotection/2023-11-01/backupinstances/method_triggercrossregionrestore.go new file mode 100644 index 00000000000..7773863c932 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/method_triggercrossregionrestore.go @@ -0,0 +1,74 @@ +package backupinstances + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TriggerCrossRegionRestoreOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// TriggerCrossRegionRestore ... +func (c BackupInstancesClient) TriggerCrossRegionRestore(ctx context.Context, id ProviderLocationId, input CrossRegionRestoreRequestObject) (result TriggerCrossRegionRestoreOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/crossRegionRestore", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// TriggerCrossRegionRestoreThenPoll performs TriggerCrossRegionRestore then polls until it's completed +func (c BackupInstancesClient) TriggerCrossRegionRestoreThenPoll(ctx context.Context, id ProviderLocationId, input CrossRegionRestoreRequestObject) error { + result, err := c.TriggerCrossRegionRestore(ctx, id, input) + if err != nil { + return fmt.Errorf("performing TriggerCrossRegionRestore: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after TriggerCrossRegionRestore: %+v", err) + } + + return nil +} diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/method_triggerrehydrate.go b/resource-manager/dataprotection/2023-11-01/backupinstances/method_triggerrehydrate.go new file mode 100644 index 00000000000..0daeeff100f --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/method_triggerrehydrate.go @@ -0,0 +1,74 @@ +package backupinstances + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TriggerRehydrateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// TriggerRehydrate ... +func (c BackupInstancesClient) TriggerRehydrate(ctx context.Context, id BackupInstanceId, input AzureBackupRehydrationRequest) (result TriggerRehydrateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/rehydrate", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// TriggerRehydrateThenPoll performs TriggerRehydrate then polls until it's completed +func (c BackupInstancesClient) TriggerRehydrateThenPoll(ctx context.Context, id BackupInstanceId, input AzureBackupRehydrationRequest) error { + result, err := c.TriggerRehydrate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing TriggerRehydrate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after TriggerRehydrate: %+v", err) + } + + return nil +} diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/method_triggerrestore.go b/resource-manager/dataprotection/2023-11-01/backupinstances/method_triggerrestore.go new file mode 100644 index 00000000000..910045b92de --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/method_triggerrestore.go @@ -0,0 +1,74 @@ +package backupinstances + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TriggerRestoreOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// TriggerRestore ... +func (c BackupInstancesClient) TriggerRestore(ctx context.Context, id BackupInstanceId, input AzureBackupRestoreRequest) (result TriggerRestoreOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/restore", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// TriggerRestoreThenPoll performs TriggerRestore then polls until it's completed +func (c BackupInstancesClient) TriggerRestoreThenPoll(ctx context.Context, id BackupInstanceId, input AzureBackupRestoreRequest) error { + result, err := c.TriggerRestore(ctx, id, input) + if err != nil { + return fmt.Errorf("performing TriggerRestore: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after TriggerRestore: %+v", err) + } + + return nil +} diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/method_validatecrossregionrestore.go b/resource-manager/dataprotection/2023-11-01/backupinstances/method_validatecrossregionrestore.go new file mode 100644 index 00000000000..6f25594584f --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/method_validatecrossregionrestore.go @@ -0,0 +1,74 @@ +package backupinstances + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ValidateCrossRegionRestoreOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// ValidateCrossRegionRestore ... +func (c BackupInstancesClient) ValidateCrossRegionRestore(ctx context.Context, id ProviderLocationId, input ValidateCrossRegionRestoreRequestObject) (result ValidateCrossRegionRestoreOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/validateCrossRegionRestore", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// ValidateCrossRegionRestoreThenPoll performs ValidateCrossRegionRestore then polls until it's completed +func (c BackupInstancesClient) ValidateCrossRegionRestoreThenPoll(ctx context.Context, id ProviderLocationId, input ValidateCrossRegionRestoreRequestObject) error { + result, err := c.ValidateCrossRegionRestore(ctx, id, input) + if err != nil { + return fmt.Errorf("performing ValidateCrossRegionRestore: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after ValidateCrossRegionRestore: %+v", err) + } + + return nil +} diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/method_validateforbackup.go b/resource-manager/dataprotection/2023-11-01/backupinstances/method_validateforbackup.go new file mode 100644 index 00000000000..793146eb041 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/method_validateforbackup.go @@ -0,0 +1,74 @@ +package backupinstances + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ValidateForBackupOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// ValidateForBackup ... +func (c BackupInstancesClient) ValidateForBackup(ctx context.Context, id BackupVaultId, input ValidateForBackupRequest) (result ValidateForBackupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/validateForBackup", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// ValidateForBackupThenPoll performs ValidateForBackup then polls until it's completed +func (c BackupInstancesClient) ValidateForBackupThenPoll(ctx context.Context, id BackupVaultId, input ValidateForBackupRequest) error { + result, err := c.ValidateForBackup(ctx, id, input) + if err != nil { + return fmt.Errorf("performing ValidateForBackup: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after ValidateForBackup: %+v", err) + } + + return nil +} diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/method_validateforrestore.go b/resource-manager/dataprotection/2023-11-01/backupinstances/method_validateforrestore.go new file mode 100644 index 00000000000..0d9b92db7cb --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/method_validateforrestore.go @@ -0,0 +1,74 @@ +package backupinstances + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ValidateForRestoreOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// ValidateForRestore ... +func (c BackupInstancesClient) ValidateForRestore(ctx context.Context, id BackupInstanceId, input ValidateRestoreRequestObject) (result ValidateForRestoreOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/validateRestore", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// ValidateForRestoreThenPoll performs ValidateForRestore then polls until it's completed +func (c BackupInstancesClient) ValidateForRestoreThenPoll(ctx context.Context, id BackupInstanceId, input ValidateRestoreRequestObject) error { + result, err := c.ValidateForRestore(ctx, id, input) + if err != nil { + return fmt.Errorf("performing ValidateForRestore: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after ValidateForRestore: %+v", err) + } + + return nil +} diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/model_adhocbackupruleoptions.go b/resource-manager/dataprotection/2023-11-01/backupinstances/model_adhocbackupruleoptions.go new file mode 100644 index 00000000000..6c6e86388b8 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/model_adhocbackupruleoptions.go @@ -0,0 +1,9 @@ +package backupinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AdHocBackupRuleOptions struct { + RuleName string `json:"ruleName"` + TriggerOption AdhocBackupTriggerOption `json:"triggerOption"` +} diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/model_adhocbackuptriggeroption.go b/resource-manager/dataprotection/2023-11-01/backupinstances/model_adhocbackuptriggeroption.go new file mode 100644 index 00000000000..3ce1a004123 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/model_adhocbackuptriggeroption.go @@ -0,0 +1,8 @@ +package backupinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AdhocBackupTriggerOption struct { + RetentionTagOverride *string `json:"retentionTagOverride,omitempty"` +} diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/model_authcredentials.go b/resource-manager/dataprotection/2023-11-01/backupinstances/model_authcredentials.go new file mode 100644 index 00000000000..8be823b957b --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/model_authcredentials.go @@ -0,0 +1,53 @@ +package backupinstances + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AuthCredentials interface { +} + +// RawAuthCredentialsImpl is returned when the Discriminated Value +// doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawAuthCredentialsImpl struct { + Type string + Values map[string]interface{} +} + +func unmarshalAuthCredentialsImplementation(input []byte) (AuthCredentials, error) { + if input == nil { + return nil, nil + } + + var temp map[string]interface{} + if err := json.Unmarshal(input, &temp); err != nil { + return nil, fmt.Errorf("unmarshaling AuthCredentials into map[string]interface: %+v", err) + } + + value, ok := temp["objectType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "SecretStoreBasedAuthCredentials") { + var out SecretStoreBasedAuthCredentials + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into SecretStoreBasedAuthCredentials: %+v", err) + } + return out, nil + } + + out := RawAuthCredentialsImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/model_azurebackuprecoverypointbasedrestorerequest.go b/resource-manager/dataprotection/2023-11-01/backupinstances/model_azurebackuprecoverypointbasedrestorerequest.go new file mode 100644 index 00000000000..5809de628f0 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/model_azurebackuprecoverypointbasedrestorerequest.go @@ -0,0 +1,74 @@ +package backupinstances + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ AzureBackupRestoreRequest = AzureBackupRecoveryPointBasedRestoreRequest{} + +type AzureBackupRecoveryPointBasedRestoreRequest struct { + RecoveryPointId string `json:"recoveryPointId"` + + // Fields inherited from AzureBackupRestoreRequest + IdentityDetails *IdentityDetails `json:"identityDetails,omitempty"` + RestoreTargetInfo RestoreTargetInfoBase `json:"restoreTargetInfo"` + SourceDataStoreType SourceDataStoreType `json:"sourceDataStoreType"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` +} + +var _ json.Marshaler = AzureBackupRecoveryPointBasedRestoreRequest{} + +func (s AzureBackupRecoveryPointBasedRestoreRequest) MarshalJSON() ([]byte, error) { + type wrapper AzureBackupRecoveryPointBasedRestoreRequest + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureBackupRecoveryPointBasedRestoreRequest: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureBackupRecoveryPointBasedRestoreRequest: %+v", err) + } + decoded["objectType"] = "AzureBackupRecoveryPointBasedRestoreRequest" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureBackupRecoveryPointBasedRestoreRequest: %+v", err) + } + + return encoded, nil +} + +var _ json.Unmarshaler = &AzureBackupRecoveryPointBasedRestoreRequest{} + +func (s *AzureBackupRecoveryPointBasedRestoreRequest) UnmarshalJSON(bytes []byte) error { + type alias AzureBackupRecoveryPointBasedRestoreRequest + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into AzureBackupRecoveryPointBasedRestoreRequest: %+v", err) + } + + s.IdentityDetails = decoded.IdentityDetails + s.RecoveryPointId = decoded.RecoveryPointId + s.SourceDataStoreType = decoded.SourceDataStoreType + s.SourceResourceId = decoded.SourceResourceId + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling AzureBackupRecoveryPointBasedRestoreRequest into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["restoreTargetInfo"]; ok { + impl, err := unmarshalRestoreTargetInfoBaseImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'RestoreTargetInfo' for 'AzureBackupRecoveryPointBasedRestoreRequest': %+v", err) + } + s.RestoreTargetInfo = impl + } + return nil +} diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/model_azurebackuprecoverytimebasedrestorerequest.go b/resource-manager/dataprotection/2023-11-01/backupinstances/model_azurebackuprecoverytimebasedrestorerequest.go new file mode 100644 index 00000000000..17052c6294a --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/model_azurebackuprecoverytimebasedrestorerequest.go @@ -0,0 +1,74 @@ +package backupinstances + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ AzureBackupRestoreRequest = AzureBackupRecoveryTimeBasedRestoreRequest{} + +type AzureBackupRecoveryTimeBasedRestoreRequest struct { + RecoveryPointTime string `json:"recoveryPointTime"` + + // Fields inherited from AzureBackupRestoreRequest + IdentityDetails *IdentityDetails `json:"identityDetails,omitempty"` + RestoreTargetInfo RestoreTargetInfoBase `json:"restoreTargetInfo"` + SourceDataStoreType SourceDataStoreType `json:"sourceDataStoreType"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` +} + +var _ json.Marshaler = AzureBackupRecoveryTimeBasedRestoreRequest{} + +func (s AzureBackupRecoveryTimeBasedRestoreRequest) MarshalJSON() ([]byte, error) { + type wrapper AzureBackupRecoveryTimeBasedRestoreRequest + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureBackupRecoveryTimeBasedRestoreRequest: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureBackupRecoveryTimeBasedRestoreRequest: %+v", err) + } + decoded["objectType"] = "AzureBackupRecoveryTimeBasedRestoreRequest" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureBackupRecoveryTimeBasedRestoreRequest: %+v", err) + } + + return encoded, nil +} + +var _ json.Unmarshaler = &AzureBackupRecoveryTimeBasedRestoreRequest{} + +func (s *AzureBackupRecoveryTimeBasedRestoreRequest) UnmarshalJSON(bytes []byte) error { + type alias AzureBackupRecoveryTimeBasedRestoreRequest + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into AzureBackupRecoveryTimeBasedRestoreRequest: %+v", err) + } + + s.IdentityDetails = decoded.IdentityDetails + s.RecoveryPointTime = decoded.RecoveryPointTime + s.SourceDataStoreType = decoded.SourceDataStoreType + s.SourceResourceId = decoded.SourceResourceId + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling AzureBackupRecoveryTimeBasedRestoreRequest into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["restoreTargetInfo"]; ok { + impl, err := unmarshalRestoreTargetInfoBaseImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'RestoreTargetInfo' for 'AzureBackupRecoveryTimeBasedRestoreRequest': %+v", err) + } + s.RestoreTargetInfo = impl + } + return nil +} diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/model_azurebackuprehydrationrequest.go b/resource-manager/dataprotection/2023-11-01/backupinstances/model_azurebackuprehydrationrequest.go new file mode 100644 index 00000000000..b78ded8adb1 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/model_azurebackuprehydrationrequest.go @@ -0,0 +1,10 @@ +package backupinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureBackupRehydrationRequest struct { + RecoveryPointId string `json:"recoveryPointId"` + RehydrationPriority *RehydrationPriority `json:"rehydrationPriority,omitempty"` + RehydrationRetentionDuration string `json:"rehydrationRetentionDuration"` +} diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/model_azurebackuprestorerequest.go b/resource-manager/dataprotection/2023-11-01/backupinstances/model_azurebackuprestorerequest.go new file mode 100644 index 00000000000..3b5348e6cdf --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/model_azurebackuprestorerequest.go @@ -0,0 +1,69 @@ +package backupinstances + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureBackupRestoreRequest interface { +} + +// RawAzureBackupRestoreRequestImpl is returned when the Discriminated Value +// doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawAzureBackupRestoreRequestImpl struct { + Type string + Values map[string]interface{} +} + +func unmarshalAzureBackupRestoreRequestImplementation(input []byte) (AzureBackupRestoreRequest, error) { + if input == nil { + return nil, nil + } + + var temp map[string]interface{} + if err := json.Unmarshal(input, &temp); err != nil { + return nil, fmt.Errorf("unmarshaling AzureBackupRestoreRequest into map[string]interface: %+v", err) + } + + value, ok := temp["objectType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "AzureBackupRecoveryPointBasedRestoreRequest") { + var out AzureBackupRecoveryPointBasedRestoreRequest + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureBackupRecoveryPointBasedRestoreRequest: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "AzureBackupRecoveryTimeBasedRestoreRequest") { + var out AzureBackupRecoveryTimeBasedRestoreRequest + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureBackupRecoveryTimeBasedRestoreRequest: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "AzureBackupRestoreWithRehydrationRequest") { + var out AzureBackupRestoreWithRehydrationRequest + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureBackupRestoreWithRehydrationRequest: %+v", err) + } + return out, nil + } + + out := RawAzureBackupRestoreRequestImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/model_azurebackuprestorewithrehydrationrequest.go b/resource-manager/dataprotection/2023-11-01/backupinstances/model_azurebackuprestorewithrehydrationrequest.go new file mode 100644 index 00000000000..1e8e3e86089 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/model_azurebackuprestorewithrehydrationrequest.go @@ -0,0 +1,78 @@ +package backupinstances + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ AzureBackupRestoreRequest = AzureBackupRestoreWithRehydrationRequest{} + +type AzureBackupRestoreWithRehydrationRequest struct { + RecoveryPointId string `json:"recoveryPointId"` + RehydrationPriority RehydrationPriority `json:"rehydrationPriority"` + RehydrationRetentionDuration string `json:"rehydrationRetentionDuration"` + + // Fields inherited from AzureBackupRestoreRequest + IdentityDetails *IdentityDetails `json:"identityDetails,omitempty"` + RestoreTargetInfo RestoreTargetInfoBase `json:"restoreTargetInfo"` + SourceDataStoreType SourceDataStoreType `json:"sourceDataStoreType"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` +} + +var _ json.Marshaler = AzureBackupRestoreWithRehydrationRequest{} + +func (s AzureBackupRestoreWithRehydrationRequest) MarshalJSON() ([]byte, error) { + type wrapper AzureBackupRestoreWithRehydrationRequest + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureBackupRestoreWithRehydrationRequest: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureBackupRestoreWithRehydrationRequest: %+v", err) + } + decoded["objectType"] = "AzureBackupRestoreWithRehydrationRequest" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureBackupRestoreWithRehydrationRequest: %+v", err) + } + + return encoded, nil +} + +var _ json.Unmarshaler = &AzureBackupRestoreWithRehydrationRequest{} + +func (s *AzureBackupRestoreWithRehydrationRequest) UnmarshalJSON(bytes []byte) error { + type alias AzureBackupRestoreWithRehydrationRequest + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into AzureBackupRestoreWithRehydrationRequest: %+v", err) + } + + s.IdentityDetails = decoded.IdentityDetails + s.RecoveryPointId = decoded.RecoveryPointId + s.RehydrationPriority = decoded.RehydrationPriority + s.RehydrationRetentionDuration = decoded.RehydrationRetentionDuration + s.SourceDataStoreType = decoded.SourceDataStoreType + s.SourceResourceId = decoded.SourceResourceId + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling AzureBackupRestoreWithRehydrationRequest into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["restoreTargetInfo"]; ok { + impl, err := unmarshalRestoreTargetInfoBaseImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'RestoreTargetInfo' for 'AzureBackupRestoreWithRehydrationRequest': %+v", err) + } + s.RestoreTargetInfo = impl + } + return nil +} diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/model_azureoperationalstoreparameters.go b/resource-manager/dataprotection/2023-11-01/backupinstances/model_azureoperationalstoreparameters.go new file mode 100644 index 00000000000..f7daf43fe3e --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/model_azureoperationalstoreparameters.go @@ -0,0 +1,42 @@ +package backupinstances + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DataStoreParameters = AzureOperationalStoreParameters{} + +type AzureOperationalStoreParameters struct { + ResourceGroupId *string `json:"resourceGroupId,omitempty"` + + // Fields inherited from DataStoreParameters + DataStoreType DataStoreTypes `json:"dataStoreType"` +} + +var _ json.Marshaler = AzureOperationalStoreParameters{} + +func (s AzureOperationalStoreParameters) MarshalJSON() ([]byte, error) { + type wrapper AzureOperationalStoreParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureOperationalStoreParameters: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureOperationalStoreParameters: %+v", err) + } + decoded["objectType"] = "AzureOperationalStoreParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureOperationalStoreParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/model_backupdatasourceparameters.go b/resource-manager/dataprotection/2023-11-01/backupinstances/model_backupdatasourceparameters.go new file mode 100644 index 00000000000..035cc0633ac --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/model_backupdatasourceparameters.go @@ -0,0 +1,61 @@ +package backupinstances + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackupDatasourceParameters interface { +} + +// RawBackupDatasourceParametersImpl is returned when the Discriminated Value +// doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawBackupDatasourceParametersImpl struct { + Type string + Values map[string]interface{} +} + +func unmarshalBackupDatasourceParametersImplementation(input []byte) (BackupDatasourceParameters, error) { + if input == nil { + return nil, nil + } + + var temp map[string]interface{} + if err := json.Unmarshal(input, &temp); err != nil { + return nil, fmt.Errorf("unmarshaling BackupDatasourceParameters into map[string]interface: %+v", err) + } + + value, ok := temp["objectType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "BlobBackupDatasourceParameters") { + var out BlobBackupDatasourceParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into BlobBackupDatasourceParameters: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "KubernetesClusterBackupDatasourceParameters") { + var out KubernetesClusterBackupDatasourceParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into KubernetesClusterBackupDatasourceParameters: %+v", err) + } + return out, nil + } + + out := RawBackupDatasourceParametersImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/model_backupinstance.go b/resource-manager/dataprotection/2023-11-01/backupinstances/model_backupinstance.go new file mode 100644 index 00000000000..73c49dd6840 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/model_backupinstance.go @@ -0,0 +1,60 @@ +package backupinstances + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackupInstance struct { + CurrentProtectionState *CurrentProtectionState `json:"currentProtectionState,omitempty"` + DataSourceInfo Datasource `json:"dataSourceInfo"` + DataSourceSetInfo *DatasourceSet `json:"dataSourceSetInfo,omitempty"` + DatasourceAuthCredentials AuthCredentials `json:"datasourceAuthCredentials"` + FriendlyName *string `json:"friendlyName,omitempty"` + IdentityDetails *IdentityDetails `json:"identityDetails,omitempty"` + ObjectType string `json:"objectType"` + PolicyInfo PolicyInfo `json:"policyInfo"` + ProtectionErrorDetails *UserFacingError `json:"protectionErrorDetails,omitempty"` + ProtectionStatus *ProtectionStatusDetails `json:"protectionStatus,omitempty"` + ProvisioningState *string `json:"provisioningState,omitempty"` + ValidationType *ValidationType `json:"validationType,omitempty"` +} + +var _ json.Unmarshaler = &BackupInstance{} + +func (s *BackupInstance) UnmarshalJSON(bytes []byte) error { + type alias BackupInstance + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into BackupInstance: %+v", err) + } + + s.CurrentProtectionState = decoded.CurrentProtectionState + s.DataSourceInfo = decoded.DataSourceInfo + s.DataSourceSetInfo = decoded.DataSourceSetInfo + s.FriendlyName = decoded.FriendlyName + s.IdentityDetails = decoded.IdentityDetails + s.ObjectType = decoded.ObjectType + s.PolicyInfo = decoded.PolicyInfo + s.ProtectionErrorDetails = decoded.ProtectionErrorDetails + s.ProtectionStatus = decoded.ProtectionStatus + s.ProvisioningState = decoded.ProvisioningState + s.ValidationType = decoded.ValidationType + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling BackupInstance into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["datasourceAuthCredentials"]; ok { + impl, err := unmarshalAuthCredentialsImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'DatasourceAuthCredentials' for 'BackupInstance': %+v", err) + } + s.DatasourceAuthCredentials = impl + } + return nil +} diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/model_backupinstanceresource.go b/resource-manager/dataprotection/2023-11-01/backupinstances/model_backupinstanceresource.go new file mode 100644 index 00000000000..ca92f651ec6 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/model_backupinstanceresource.go @@ -0,0 +1,17 @@ +package backupinstances + +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 BackupInstanceResource struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *BackupInstance `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/model_baseresourceproperties.go b/resource-manager/dataprotection/2023-11-01/backupinstances/model_baseresourceproperties.go new file mode 100644 index 00000000000..fcf07932382 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/model_baseresourceproperties.go @@ -0,0 +1,53 @@ +package backupinstances + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BaseResourceProperties interface { +} + +// RawBaseResourcePropertiesImpl is returned when the Discriminated Value +// doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawBaseResourcePropertiesImpl struct { + Type string + Values map[string]interface{} +} + +func unmarshalBaseResourcePropertiesImplementation(input []byte) (BaseResourceProperties, error) { + if input == nil { + return nil, nil + } + + var temp map[string]interface{} + if err := json.Unmarshal(input, &temp); err != nil { + return nil, fmt.Errorf("unmarshaling BaseResourceProperties into map[string]interface: %+v", err) + } + + value, ok := temp["objectType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "DefaultResourceProperties") { + var out DefaultResourceProperties + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into DefaultResourceProperties: %+v", err) + } + return out, nil + } + + out := RawBaseResourcePropertiesImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/model_blobbackupdatasourceparameters.go b/resource-manager/dataprotection/2023-11-01/backupinstances/model_blobbackupdatasourceparameters.go new file mode 100644 index 00000000000..84f49ead22c --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/model_blobbackupdatasourceparameters.go @@ -0,0 +1,41 @@ +package backupinstances + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ BackupDatasourceParameters = BlobBackupDatasourceParameters{} + +type BlobBackupDatasourceParameters struct { + ContainersList []string `json:"containersList"` + + // Fields inherited from BackupDatasourceParameters +} + +var _ json.Marshaler = BlobBackupDatasourceParameters{} + +func (s BlobBackupDatasourceParameters) MarshalJSON() ([]byte, error) { + type wrapper BlobBackupDatasourceParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling BlobBackupDatasourceParameters: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling BlobBackupDatasourceParameters: %+v", err) + } + decoded["objectType"] = "BlobBackupDatasourceParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling BlobBackupDatasourceParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/model_crossregionrestoredetails.go b/resource-manager/dataprotection/2023-11-01/backupinstances/model_crossregionrestoredetails.go new file mode 100644 index 00000000000..edbe7ac454b --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/model_crossregionrestoredetails.go @@ -0,0 +1,9 @@ +package backupinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CrossRegionRestoreDetails struct { + SourceBackupInstanceId string `json:"sourceBackupInstanceId"` + SourceRegion string `json:"sourceRegion"` +} diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/model_crossregionrestorerequestobject.go b/resource-manager/dataprotection/2023-11-01/backupinstances/model_crossregionrestorerequestobject.go new file mode 100644 index 00000000000..d958127a0de --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/model_crossregionrestorerequestobject.go @@ -0,0 +1,40 @@ +package backupinstances + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CrossRegionRestoreRequestObject struct { + CrossRegionRestoreDetails CrossRegionRestoreDetails `json:"crossRegionRestoreDetails"` + RestoreRequestObject AzureBackupRestoreRequest `json:"restoreRequestObject"` +} + +var _ json.Unmarshaler = &CrossRegionRestoreRequestObject{} + +func (s *CrossRegionRestoreRequestObject) UnmarshalJSON(bytes []byte) error { + type alias CrossRegionRestoreRequestObject + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into CrossRegionRestoreRequestObject: %+v", err) + } + + s.CrossRegionRestoreDetails = decoded.CrossRegionRestoreDetails + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling CrossRegionRestoreRequestObject into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["restoreRequestObject"]; ok { + impl, err := unmarshalAzureBackupRestoreRequestImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'RestoreRequestObject' for 'CrossRegionRestoreRequestObject': %+v", err) + } + s.RestoreRequestObject = impl + } + return nil +} diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/model_datasource.go b/resource-manager/dataprotection/2023-11-01/backupinstances/model_datasource.go new file mode 100644 index 00000000000..a8e07a37117 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/model_datasource.go @@ -0,0 +1,52 @@ +package backupinstances + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Datasource struct { + DatasourceType *string `json:"datasourceType,omitempty"` + ObjectType *string `json:"objectType,omitempty"` + ResourceID string `json:"resourceID"` + ResourceLocation *string `json:"resourceLocation,omitempty"` + ResourceName *string `json:"resourceName,omitempty"` + ResourceProperties BaseResourceProperties `json:"resourceProperties"` + ResourceType *string `json:"resourceType,omitempty"` + ResourceUri *string `json:"resourceUri,omitempty"` +} + +var _ json.Unmarshaler = &Datasource{} + +func (s *Datasource) UnmarshalJSON(bytes []byte) error { + type alias Datasource + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into Datasource: %+v", err) + } + + s.DatasourceType = decoded.DatasourceType + s.ObjectType = decoded.ObjectType + s.ResourceID = decoded.ResourceID + s.ResourceLocation = decoded.ResourceLocation + s.ResourceName = decoded.ResourceName + s.ResourceType = decoded.ResourceType + s.ResourceUri = decoded.ResourceUri + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling Datasource into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["resourceProperties"]; ok { + impl, err := unmarshalBaseResourcePropertiesImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'ResourceProperties' for 'Datasource': %+v", err) + } + s.ResourceProperties = impl + } + return nil +} diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/model_datasourceset.go b/resource-manager/dataprotection/2023-11-01/backupinstances/model_datasourceset.go new file mode 100644 index 00000000000..537af263c0b --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/model_datasourceset.go @@ -0,0 +1,52 @@ +package backupinstances + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatasourceSet struct { + DatasourceType *string `json:"datasourceType,omitempty"` + ObjectType *string `json:"objectType,omitempty"` + ResourceID string `json:"resourceID"` + ResourceLocation *string `json:"resourceLocation,omitempty"` + ResourceName *string `json:"resourceName,omitempty"` + ResourceProperties BaseResourceProperties `json:"resourceProperties"` + ResourceType *string `json:"resourceType,omitempty"` + ResourceUri *string `json:"resourceUri,omitempty"` +} + +var _ json.Unmarshaler = &DatasourceSet{} + +func (s *DatasourceSet) UnmarshalJSON(bytes []byte) error { + type alias DatasourceSet + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into DatasourceSet: %+v", err) + } + + s.DatasourceType = decoded.DatasourceType + s.ObjectType = decoded.ObjectType + s.ResourceID = decoded.ResourceID + s.ResourceLocation = decoded.ResourceLocation + s.ResourceName = decoded.ResourceName + s.ResourceType = decoded.ResourceType + s.ResourceUri = decoded.ResourceUri + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling DatasourceSet into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["resourceProperties"]; ok { + impl, err := unmarshalBaseResourcePropertiesImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'ResourceProperties' for 'DatasourceSet': %+v", err) + } + s.ResourceProperties = impl + } + return nil +} diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/model_datastoreparameters.go b/resource-manager/dataprotection/2023-11-01/backupinstances/model_datastoreparameters.go new file mode 100644 index 00000000000..ee57cd90fa3 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/model_datastoreparameters.go @@ -0,0 +1,53 @@ +package backupinstances + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DataStoreParameters interface { +} + +// RawDataStoreParametersImpl is returned when the Discriminated Value +// doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawDataStoreParametersImpl struct { + Type string + Values map[string]interface{} +} + +func unmarshalDataStoreParametersImplementation(input []byte) (DataStoreParameters, error) { + if input == nil { + return nil, nil + } + + var temp map[string]interface{} + if err := json.Unmarshal(input, &temp); err != nil { + return nil, fmt.Errorf("unmarshaling DataStoreParameters into map[string]interface: %+v", err) + } + + value, ok := temp["objectType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "AzureOperationalStoreParameters") { + var out AzureOperationalStoreParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureOperationalStoreParameters: %+v", err) + } + return out, nil + } + + out := RawDataStoreParametersImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/model_defaultresourceproperties.go b/resource-manager/dataprotection/2023-11-01/backupinstances/model_defaultresourceproperties.go new file mode 100644 index 00000000000..adac6099d8b --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/model_defaultresourceproperties.go @@ -0,0 +1,40 @@ +package backupinstances + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ BaseResourceProperties = DefaultResourceProperties{} + +type DefaultResourceProperties struct { + + // Fields inherited from BaseResourceProperties +} + +var _ json.Marshaler = DefaultResourceProperties{} + +func (s DefaultResourceProperties) MarshalJSON() ([]byte, error) { + type wrapper DefaultResourceProperties + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling DefaultResourceProperties: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling DefaultResourceProperties: %+v", err) + } + decoded["objectType"] = "DefaultResourceProperties" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling DefaultResourceProperties: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/model_identitydetails.go b/resource-manager/dataprotection/2023-11-01/backupinstances/model_identitydetails.go new file mode 100644 index 00000000000..60ba2542236 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/model_identitydetails.go @@ -0,0 +1,9 @@ +package backupinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IdentityDetails struct { + UseSystemAssignedIdentity *bool `json:"useSystemAssignedIdentity,omitempty"` + UserAssignedIdentityArmUrl *string `json:"userAssignedIdentityArmUrl,omitempty"` +} diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/model_innererror.go b/resource-manager/dataprotection/2023-11-01/backupinstances/model_innererror.go new file mode 100644 index 00000000000..15fc997eebd --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/model_innererror.go @@ -0,0 +1,10 @@ +package backupinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type InnerError struct { + AdditionalInfo *map[string]string `json:"additionalInfo,omitempty"` + Code *string `json:"code,omitempty"` + EmbeddedInnerError *InnerError `json:"embeddedInnerError,omitempty"` +} diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/model_itemlevelrestorecriteria.go b/resource-manager/dataprotection/2023-11-01/backupinstances/model_itemlevelrestorecriteria.go new file mode 100644 index 00000000000..5c1b5326ced --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/model_itemlevelrestorecriteria.go @@ -0,0 +1,93 @@ +package backupinstances + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ItemLevelRestoreCriteria interface { +} + +// RawItemLevelRestoreCriteriaImpl is returned when the Discriminated Value +// doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawItemLevelRestoreCriteriaImpl struct { + Type string + Values map[string]interface{} +} + +func unmarshalItemLevelRestoreCriteriaImplementation(input []byte) (ItemLevelRestoreCriteria, error) { + if input == nil { + return nil, nil + } + + var temp map[string]interface{} + if err := json.Unmarshal(input, &temp); err != nil { + return nil, fmt.Errorf("unmarshaling ItemLevelRestoreCriteria into map[string]interface: %+v", err) + } + + value, ok := temp["objectType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "ItemPathBasedRestoreCriteria") { + var out ItemPathBasedRestoreCriteria + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into ItemPathBasedRestoreCriteria: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "KubernetesClusterRestoreCriteria") { + var out KubernetesClusterRestoreCriteria + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into KubernetesClusterRestoreCriteria: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "KubernetesClusterVaultTierRestoreCriteria") { + var out KubernetesClusterVaultTierRestoreCriteria + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into KubernetesClusterVaultTierRestoreCriteria: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "KubernetesPVRestoreCriteria") { + var out KubernetesPVRestoreCriteria + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into KubernetesPVRestoreCriteria: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "KubernetesStorageClassRestoreCriteria") { + var out KubernetesStorageClassRestoreCriteria + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into KubernetesStorageClassRestoreCriteria: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "RangeBasedItemLevelRestoreCriteria") { + var out RangeBasedItemLevelRestoreCriteria + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into RangeBasedItemLevelRestoreCriteria: %+v", err) + } + return out, nil + } + + out := RawItemLevelRestoreCriteriaImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/model_itemlevelrestoretargetinfo.go b/resource-manager/dataprotection/2023-11-01/backupinstances/model_itemlevelrestoretargetinfo.go new file mode 100644 index 00000000000..475d8764212 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/model_itemlevelrestoretargetinfo.go @@ -0,0 +1,92 @@ +package backupinstances + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ RestoreTargetInfoBase = ItemLevelRestoreTargetInfo{} + +type ItemLevelRestoreTargetInfo struct { + DatasourceAuthCredentials AuthCredentials `json:"datasourceAuthCredentials"` + DatasourceInfo Datasource `json:"datasourceInfo"` + DatasourceSetInfo *DatasourceSet `json:"datasourceSetInfo,omitempty"` + RestoreCriteria []ItemLevelRestoreCriteria `json:"restoreCriteria"` + + // Fields inherited from RestoreTargetInfoBase + RecoveryOption RecoveryOption `json:"recoveryOption"` + RestoreLocation *string `json:"restoreLocation,omitempty"` +} + +var _ json.Marshaler = ItemLevelRestoreTargetInfo{} + +func (s ItemLevelRestoreTargetInfo) MarshalJSON() ([]byte, error) { + type wrapper ItemLevelRestoreTargetInfo + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling ItemLevelRestoreTargetInfo: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling ItemLevelRestoreTargetInfo: %+v", err) + } + decoded["objectType"] = "ItemLevelRestoreTargetInfo" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling ItemLevelRestoreTargetInfo: %+v", err) + } + + return encoded, nil +} + +var _ json.Unmarshaler = &ItemLevelRestoreTargetInfo{} + +func (s *ItemLevelRestoreTargetInfo) UnmarshalJSON(bytes []byte) error { + type alias ItemLevelRestoreTargetInfo + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into ItemLevelRestoreTargetInfo: %+v", err) + } + + s.DatasourceInfo = decoded.DatasourceInfo + s.DatasourceSetInfo = decoded.DatasourceSetInfo + s.RecoveryOption = decoded.RecoveryOption + s.RestoreLocation = decoded.RestoreLocation + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling ItemLevelRestoreTargetInfo into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["datasourceAuthCredentials"]; ok { + impl, err := unmarshalAuthCredentialsImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'DatasourceAuthCredentials' for 'ItemLevelRestoreTargetInfo': %+v", err) + } + s.DatasourceAuthCredentials = impl + } + + if v, ok := temp["restoreCriteria"]; ok { + var listTemp []json.RawMessage + if err := json.Unmarshal(v, &listTemp); err != nil { + return fmt.Errorf("unmarshaling RestoreCriteria into list []json.RawMessage: %+v", err) + } + + output := make([]ItemLevelRestoreCriteria, 0) + for i, val := range listTemp { + impl, err := unmarshalItemLevelRestoreCriteriaImplementation(val) + if err != nil { + return fmt.Errorf("unmarshaling index %d field 'RestoreCriteria' for 'ItemLevelRestoreTargetInfo': %+v", i, err) + } + output = append(output, impl) + } + s.RestoreCriteria = output + } + return nil +} diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/model_itempathbasedrestorecriteria.go b/resource-manager/dataprotection/2023-11-01/backupinstances/model_itempathbasedrestorecriteria.go new file mode 100644 index 00000000000..bd6640be142 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/model_itempathbasedrestorecriteria.go @@ -0,0 +1,43 @@ +package backupinstances + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ ItemLevelRestoreCriteria = ItemPathBasedRestoreCriteria{} + +type ItemPathBasedRestoreCriteria struct { + IsPathRelativeToBackupItem bool `json:"isPathRelativeToBackupItem"` + ItemPath string `json:"itemPath"` + SubItemPathPrefix *[]string `json:"subItemPathPrefix,omitempty"` + + // Fields inherited from ItemLevelRestoreCriteria +} + +var _ json.Marshaler = ItemPathBasedRestoreCriteria{} + +func (s ItemPathBasedRestoreCriteria) MarshalJSON() ([]byte, error) { + type wrapper ItemPathBasedRestoreCriteria + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling ItemPathBasedRestoreCriteria: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling ItemPathBasedRestoreCriteria: %+v", err) + } + decoded["objectType"] = "ItemPathBasedRestoreCriteria" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling ItemPathBasedRestoreCriteria: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/model_kubernetesclusterbackupdatasourceparameters.go b/resource-manager/dataprotection/2023-11-01/backupinstances/model_kubernetesclusterbackupdatasourceparameters.go new file mode 100644 index 00000000000..021230e39ac --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/model_kubernetesclusterbackupdatasourceparameters.go @@ -0,0 +1,48 @@ +package backupinstances + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ BackupDatasourceParameters = KubernetesClusterBackupDatasourceParameters{} + +type KubernetesClusterBackupDatasourceParameters struct { + BackupHookReferences *[]NamespacedNameResource `json:"backupHookReferences,omitempty"` + ExcludedNamespaces *[]string `json:"excludedNamespaces,omitempty"` + ExcludedResourceTypes *[]string `json:"excludedResourceTypes,omitempty"` + IncludeClusterScopeResources bool `json:"includeClusterScopeResources"` + IncludedNamespaces *[]string `json:"includedNamespaces,omitempty"` + IncludedResourceTypes *[]string `json:"includedResourceTypes,omitempty"` + LabelSelectors *[]string `json:"labelSelectors,omitempty"` + SnapshotVolumes bool `json:"snapshotVolumes"` + + // Fields inherited from BackupDatasourceParameters +} + +var _ json.Marshaler = KubernetesClusterBackupDatasourceParameters{} + +func (s KubernetesClusterBackupDatasourceParameters) MarshalJSON() ([]byte, error) { + type wrapper KubernetesClusterBackupDatasourceParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling KubernetesClusterBackupDatasourceParameters: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling KubernetesClusterBackupDatasourceParameters: %+v", err) + } + decoded["objectType"] = "KubernetesClusterBackupDatasourceParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling KubernetesClusterBackupDatasourceParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/model_kubernetesclusterrestorecriteria.go b/resource-manager/dataprotection/2023-11-01/backupinstances/model_kubernetesclusterrestorecriteria.go new file mode 100644 index 00000000000..070030fbbe0 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/model_kubernetesclusterrestorecriteria.go @@ -0,0 +1,50 @@ +package backupinstances + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ ItemLevelRestoreCriteria = KubernetesClusterRestoreCriteria{} + +type KubernetesClusterRestoreCriteria struct { + ConflictPolicy *ExistingResourcePolicy `json:"conflictPolicy,omitempty"` + ExcludedNamespaces *[]string `json:"excludedNamespaces,omitempty"` + ExcludedResourceTypes *[]string `json:"excludedResourceTypes,omitempty"` + IncludeClusterScopeResources bool `json:"includeClusterScopeResources"` + IncludedNamespaces *[]string `json:"includedNamespaces,omitempty"` + IncludedResourceTypes *[]string `json:"includedResourceTypes,omitempty"` + LabelSelectors *[]string `json:"labelSelectors,omitempty"` + NamespaceMappings *map[string]string `json:"namespaceMappings,omitempty"` + PersistentVolumeRestoreMode *PersistentVolumeRestoreMode `json:"persistentVolumeRestoreMode,omitempty"` + RestoreHookReferences *[]NamespacedNameResource `json:"restoreHookReferences,omitempty"` + + // Fields inherited from ItemLevelRestoreCriteria +} + +var _ json.Marshaler = KubernetesClusterRestoreCriteria{} + +func (s KubernetesClusterRestoreCriteria) MarshalJSON() ([]byte, error) { + type wrapper KubernetesClusterRestoreCriteria + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling KubernetesClusterRestoreCriteria: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling KubernetesClusterRestoreCriteria: %+v", err) + } + decoded["objectType"] = "KubernetesClusterRestoreCriteria" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling KubernetesClusterRestoreCriteria: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/model_kubernetesclustervaulttierrestorecriteria.go b/resource-manager/dataprotection/2023-11-01/backupinstances/model_kubernetesclustervaulttierrestorecriteria.go new file mode 100644 index 00000000000..5cd1ff7c95c --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/model_kubernetesclustervaulttierrestorecriteria.go @@ -0,0 +1,52 @@ +package backupinstances + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ ItemLevelRestoreCriteria = KubernetesClusterVaultTierRestoreCriteria{} + +type KubernetesClusterVaultTierRestoreCriteria struct { + ConflictPolicy *ExistingResourcePolicy `json:"conflictPolicy,omitempty"` + ExcludedNamespaces *[]string `json:"excludedNamespaces,omitempty"` + ExcludedResourceTypes *[]string `json:"excludedResourceTypes,omitempty"` + IncludeClusterScopeResources bool `json:"includeClusterScopeResources"` + IncludedNamespaces *[]string `json:"includedNamespaces,omitempty"` + IncludedResourceTypes *[]string `json:"includedResourceTypes,omitempty"` + LabelSelectors *[]string `json:"labelSelectors,omitempty"` + NamespaceMappings *map[string]string `json:"namespaceMappings,omitempty"` + PersistentVolumeRestoreMode *PersistentVolumeRestoreMode `json:"persistentVolumeRestoreMode,omitempty"` + RestoreHookReferences *[]NamespacedNameResource `json:"restoreHookReferences,omitempty"` + StagingResourceGroupId *string `json:"stagingResourceGroupId,omitempty"` + StagingStorageAccountId *string `json:"stagingStorageAccountId,omitempty"` + + // Fields inherited from ItemLevelRestoreCriteria +} + +var _ json.Marshaler = KubernetesClusterVaultTierRestoreCriteria{} + +func (s KubernetesClusterVaultTierRestoreCriteria) MarshalJSON() ([]byte, error) { + type wrapper KubernetesClusterVaultTierRestoreCriteria + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling KubernetesClusterVaultTierRestoreCriteria: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling KubernetesClusterVaultTierRestoreCriteria: %+v", err) + } + decoded["objectType"] = "KubernetesClusterVaultTierRestoreCriteria" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling KubernetesClusterVaultTierRestoreCriteria: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/model_kubernetespvrestorecriteria.go b/resource-manager/dataprotection/2023-11-01/backupinstances/model_kubernetespvrestorecriteria.go new file mode 100644 index 00000000000..0f3d56cbfeb --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/model_kubernetespvrestorecriteria.go @@ -0,0 +1,42 @@ +package backupinstances + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ ItemLevelRestoreCriteria = KubernetesPVRestoreCriteria{} + +type KubernetesPVRestoreCriteria struct { + Name *string `json:"name,omitempty"` + StorageClassName *string `json:"storageClassName,omitempty"` + + // Fields inherited from ItemLevelRestoreCriteria +} + +var _ json.Marshaler = KubernetesPVRestoreCriteria{} + +func (s KubernetesPVRestoreCriteria) MarshalJSON() ([]byte, error) { + type wrapper KubernetesPVRestoreCriteria + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling KubernetesPVRestoreCriteria: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling KubernetesPVRestoreCriteria: %+v", err) + } + decoded["objectType"] = "KubernetesPVRestoreCriteria" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling KubernetesPVRestoreCriteria: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/model_kubernetesstorageclassrestorecriteria.go b/resource-manager/dataprotection/2023-11-01/backupinstances/model_kubernetesstorageclassrestorecriteria.go new file mode 100644 index 00000000000..d4b08aa1e6f --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/model_kubernetesstorageclassrestorecriteria.go @@ -0,0 +1,42 @@ +package backupinstances + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ ItemLevelRestoreCriteria = KubernetesStorageClassRestoreCriteria{} + +type KubernetesStorageClassRestoreCriteria struct { + Provisioner *string `json:"provisioner,omitempty"` + SelectedStorageClassName *string `json:"selectedStorageClassName,omitempty"` + + // Fields inherited from ItemLevelRestoreCriteria +} + +var _ json.Marshaler = KubernetesStorageClassRestoreCriteria{} + +func (s KubernetesStorageClassRestoreCriteria) MarshalJSON() ([]byte, error) { + type wrapper KubernetesStorageClassRestoreCriteria + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling KubernetesStorageClassRestoreCriteria: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling KubernetesStorageClassRestoreCriteria: %+v", err) + } + decoded["objectType"] = "KubernetesStorageClassRestoreCriteria" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling KubernetesStorageClassRestoreCriteria: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/model_namespacednameresource.go b/resource-manager/dataprotection/2023-11-01/backupinstances/model_namespacednameresource.go new file mode 100644 index 00000000000..f0c6e7a847c --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/model_namespacednameresource.go @@ -0,0 +1,9 @@ +package backupinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NamespacedNameResource struct { + Name *string `json:"name,omitempty"` + Namespace *string `json:"namespace,omitempty"` +} diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/model_operationextendedinfo.go b/resource-manager/dataprotection/2023-11-01/backupinstances/model_operationextendedinfo.go new file mode 100644 index 00000000000..53581d9a9e1 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/model_operationextendedinfo.go @@ -0,0 +1,53 @@ +package backupinstances + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OperationExtendedInfo interface { +} + +// RawOperationExtendedInfoImpl is returned when the Discriminated Value +// doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawOperationExtendedInfoImpl struct { + Type string + Values map[string]interface{} +} + +func unmarshalOperationExtendedInfoImplementation(input []byte) (OperationExtendedInfo, error) { + if input == nil { + return nil, nil + } + + var temp map[string]interface{} + if err := json.Unmarshal(input, &temp); err != nil { + return nil, fmt.Errorf("unmarshaling OperationExtendedInfo into map[string]interface: %+v", err) + } + + value, ok := temp["objectType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "OperationJobExtendedInfo") { + var out OperationJobExtendedInfo + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into OperationJobExtendedInfo: %+v", err) + } + return out, nil + } + + out := RawOperationExtendedInfoImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/model_operationjobextendedinfo.go b/resource-manager/dataprotection/2023-11-01/backupinstances/model_operationjobextendedinfo.go new file mode 100644 index 00000000000..59cd3f9ddf6 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/model_operationjobextendedinfo.go @@ -0,0 +1,41 @@ +package backupinstances + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ OperationExtendedInfo = OperationJobExtendedInfo{} + +type OperationJobExtendedInfo struct { + JobId *string `json:"jobId,omitempty"` + + // Fields inherited from OperationExtendedInfo +} + +var _ json.Marshaler = OperationJobExtendedInfo{} + +func (s OperationJobExtendedInfo) MarshalJSON() ([]byte, error) { + type wrapper OperationJobExtendedInfo + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling OperationJobExtendedInfo: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling OperationJobExtendedInfo: %+v", err) + } + decoded["objectType"] = "OperationJobExtendedInfo" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling OperationJobExtendedInfo: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/model_policyinfo.go b/resource-manager/dataprotection/2023-11-01/backupinstances/model_policyinfo.go new file mode 100644 index 00000000000..41646c6341d --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/model_policyinfo.go @@ -0,0 +1,10 @@ +package backupinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PolicyInfo struct { + PolicyId string `json:"policyId"` + PolicyParameters *PolicyParameters `json:"policyParameters,omitempty"` + PolicyVersion *string `json:"policyVersion,omitempty"` +} diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/model_policyparameters.go b/resource-manager/dataprotection/2023-11-01/backupinstances/model_policyparameters.go new file mode 100644 index 00000000000..ba00f440ca8 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/model_policyparameters.go @@ -0,0 +1,59 @@ +package backupinstances + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PolicyParameters struct { + BackupDatasourceParametersList *[]BackupDatasourceParameters `json:"backupDatasourceParametersList,omitempty"` + DataStoreParametersList *[]DataStoreParameters `json:"dataStoreParametersList,omitempty"` +} + +var _ json.Unmarshaler = &PolicyParameters{} + +func (s *PolicyParameters) UnmarshalJSON(bytes []byte) error { + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling PolicyParameters into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["backupDatasourceParametersList"]; ok { + var listTemp []json.RawMessage + if err := json.Unmarshal(v, &listTemp); err != nil { + return fmt.Errorf("unmarshaling BackupDatasourceParametersList into list []json.RawMessage: %+v", err) + } + + output := make([]BackupDatasourceParameters, 0) + for i, val := range listTemp { + impl, err := unmarshalBackupDatasourceParametersImplementation(val) + if err != nil { + return fmt.Errorf("unmarshaling index %d field 'BackupDatasourceParametersList' for 'PolicyParameters': %+v", i, err) + } + output = append(output, impl) + } + s.BackupDatasourceParametersList = &output + } + + if v, ok := temp["dataStoreParametersList"]; ok { + var listTemp []json.RawMessage + if err := json.Unmarshal(v, &listTemp); err != nil { + return fmt.Errorf("unmarshaling DataStoreParametersList into list []json.RawMessage: %+v", err) + } + + output := make([]DataStoreParameters, 0) + for i, val := range listTemp { + impl, err := unmarshalDataStoreParametersImplementation(val) + if err != nil { + return fmt.Errorf("unmarshaling index %d field 'DataStoreParametersList' for 'PolicyParameters': %+v", i, err) + } + output = append(output, impl) + } + s.DataStoreParametersList = &output + } + return nil +} diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/model_protectionstatusdetails.go b/resource-manager/dataprotection/2023-11-01/backupinstances/model_protectionstatusdetails.go new file mode 100644 index 00000000000..47607ca70da --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/model_protectionstatusdetails.go @@ -0,0 +1,9 @@ +package backupinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProtectionStatusDetails struct { + ErrorDetails *UserFacingError `json:"errorDetails,omitempty"` + Status *Status `json:"status,omitempty"` +} diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/model_rangebaseditemlevelrestorecriteria.go b/resource-manager/dataprotection/2023-11-01/backupinstances/model_rangebaseditemlevelrestorecriteria.go new file mode 100644 index 00000000000..c7df0c52c2b --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/model_rangebaseditemlevelrestorecriteria.go @@ -0,0 +1,42 @@ +package backupinstances + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ ItemLevelRestoreCriteria = RangeBasedItemLevelRestoreCriteria{} + +type RangeBasedItemLevelRestoreCriteria struct { + MaxMatchingValue *string `json:"maxMatchingValue,omitempty"` + MinMatchingValue *string `json:"minMatchingValue,omitempty"` + + // Fields inherited from ItemLevelRestoreCriteria +} + +var _ json.Marshaler = RangeBasedItemLevelRestoreCriteria{} + +func (s RangeBasedItemLevelRestoreCriteria) MarshalJSON() ([]byte, error) { + type wrapper RangeBasedItemLevelRestoreCriteria + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling RangeBasedItemLevelRestoreCriteria: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling RangeBasedItemLevelRestoreCriteria: %+v", err) + } + decoded["objectType"] = "RangeBasedItemLevelRestoreCriteria" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling RangeBasedItemLevelRestoreCriteria: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/model_restorefilestargetinfo.go b/resource-manager/dataprotection/2023-11-01/backupinstances/model_restorefilestargetinfo.go new file mode 100644 index 00000000000..04fe194025c --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/model_restorefilestargetinfo.go @@ -0,0 +1,43 @@ +package backupinstances + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ RestoreTargetInfoBase = RestoreFilesTargetInfo{} + +type RestoreFilesTargetInfo struct { + TargetDetails TargetDetails `json:"targetDetails"` + + // Fields inherited from RestoreTargetInfoBase + RecoveryOption RecoveryOption `json:"recoveryOption"` + RestoreLocation *string `json:"restoreLocation,omitempty"` +} + +var _ json.Marshaler = RestoreFilesTargetInfo{} + +func (s RestoreFilesTargetInfo) MarshalJSON() ([]byte, error) { + type wrapper RestoreFilesTargetInfo + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling RestoreFilesTargetInfo: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling RestoreFilesTargetInfo: %+v", err) + } + decoded["objectType"] = "RestoreFilesTargetInfo" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling RestoreFilesTargetInfo: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/model_restoretargetinfo.go b/resource-manager/dataprotection/2023-11-01/backupinstances/model_restoretargetinfo.go new file mode 100644 index 00000000000..23f512f2c31 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/model_restoretargetinfo.go @@ -0,0 +1,74 @@ +package backupinstances + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ RestoreTargetInfoBase = RestoreTargetInfo{} + +type RestoreTargetInfo struct { + DatasourceAuthCredentials AuthCredentials `json:"datasourceAuthCredentials"` + DatasourceInfo Datasource `json:"datasourceInfo"` + DatasourceSetInfo *DatasourceSet `json:"datasourceSetInfo,omitempty"` + + // Fields inherited from RestoreTargetInfoBase + RecoveryOption RecoveryOption `json:"recoveryOption"` + RestoreLocation *string `json:"restoreLocation,omitempty"` +} + +var _ json.Marshaler = RestoreTargetInfo{} + +func (s RestoreTargetInfo) MarshalJSON() ([]byte, error) { + type wrapper RestoreTargetInfo + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling RestoreTargetInfo: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling RestoreTargetInfo: %+v", err) + } + decoded["objectType"] = "RestoreTargetInfo" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling RestoreTargetInfo: %+v", err) + } + + return encoded, nil +} + +var _ json.Unmarshaler = &RestoreTargetInfo{} + +func (s *RestoreTargetInfo) UnmarshalJSON(bytes []byte) error { + type alias RestoreTargetInfo + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into RestoreTargetInfo: %+v", err) + } + + s.DatasourceInfo = decoded.DatasourceInfo + s.DatasourceSetInfo = decoded.DatasourceSetInfo + s.RecoveryOption = decoded.RecoveryOption + s.RestoreLocation = decoded.RestoreLocation + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling RestoreTargetInfo into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["datasourceAuthCredentials"]; ok { + impl, err := unmarshalAuthCredentialsImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'DatasourceAuthCredentials' for 'RestoreTargetInfo': %+v", err) + } + s.DatasourceAuthCredentials = impl + } + return nil +} diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/model_restoretargetinfobase.go b/resource-manager/dataprotection/2023-11-01/backupinstances/model_restoretargetinfobase.go new file mode 100644 index 00000000000..ce31702dc78 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/model_restoretargetinfobase.go @@ -0,0 +1,69 @@ +package backupinstances + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RestoreTargetInfoBase interface { +} + +// RawRestoreTargetInfoBaseImpl is returned when the Discriminated Value +// doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawRestoreTargetInfoBaseImpl struct { + Type string + Values map[string]interface{} +} + +func unmarshalRestoreTargetInfoBaseImplementation(input []byte) (RestoreTargetInfoBase, error) { + if input == nil { + return nil, nil + } + + var temp map[string]interface{} + if err := json.Unmarshal(input, &temp); err != nil { + return nil, fmt.Errorf("unmarshaling RestoreTargetInfoBase into map[string]interface: %+v", err) + } + + value, ok := temp["objectType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "ItemLevelRestoreTargetInfo") { + var out ItemLevelRestoreTargetInfo + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into ItemLevelRestoreTargetInfo: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "RestoreFilesTargetInfo") { + var out RestoreFilesTargetInfo + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into RestoreFilesTargetInfo: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "RestoreTargetInfo") { + var out RestoreTargetInfo + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into RestoreTargetInfo: %+v", err) + } + return out, nil + } + + out := RawRestoreTargetInfoBaseImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/model_secretstorebasedauthcredentials.go b/resource-manager/dataprotection/2023-11-01/backupinstances/model_secretstorebasedauthcredentials.go new file mode 100644 index 00000000000..76f2af98598 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/model_secretstorebasedauthcredentials.go @@ -0,0 +1,41 @@ +package backupinstances + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ AuthCredentials = SecretStoreBasedAuthCredentials{} + +type SecretStoreBasedAuthCredentials struct { + SecretStoreResource *SecretStoreResource `json:"secretStoreResource,omitempty"` + + // Fields inherited from AuthCredentials +} + +var _ json.Marshaler = SecretStoreBasedAuthCredentials{} + +func (s SecretStoreBasedAuthCredentials) MarshalJSON() ([]byte, error) { + type wrapper SecretStoreBasedAuthCredentials + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling SecretStoreBasedAuthCredentials: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling SecretStoreBasedAuthCredentials: %+v", err) + } + decoded["objectType"] = "SecretStoreBasedAuthCredentials" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling SecretStoreBasedAuthCredentials: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/model_secretstoreresource.go b/resource-manager/dataprotection/2023-11-01/backupinstances/model_secretstoreresource.go new file mode 100644 index 00000000000..ee1d6fb0bd9 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/model_secretstoreresource.go @@ -0,0 +1,10 @@ +package backupinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SecretStoreResource struct { + SecretStoreType SecretStoreType `json:"secretStoreType"` + Uri *string `json:"uri,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/model_syncbackupinstancerequest.go b/resource-manager/dataprotection/2023-11-01/backupinstances/model_syncbackupinstancerequest.go new file mode 100644 index 00000000000..ce2412fb5e5 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/model_syncbackupinstancerequest.go @@ -0,0 +1,8 @@ +package backupinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SyncBackupInstanceRequest struct { + SyncType *SyncType `json:"syncType,omitempty"` +} diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/model_targetdetails.go b/resource-manager/dataprotection/2023-11-01/backupinstances/model_targetdetails.go new file mode 100644 index 00000000000..321cf422bff --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/model_targetdetails.go @@ -0,0 +1,11 @@ +package backupinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TargetDetails struct { + FilePrefix string `json:"filePrefix"` + RestoreTargetLocationType RestoreTargetLocationType `json:"restoreTargetLocationType"` + TargetResourceArmId *string `json:"targetResourceArmId,omitempty"` + Url string `json:"url"` +} diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/model_triggerbackuprequest.go b/resource-manager/dataprotection/2023-11-01/backupinstances/model_triggerbackuprequest.go new file mode 100644 index 00000000000..ffe844c6e4a --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/model_triggerbackuprequest.go @@ -0,0 +1,8 @@ +package backupinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TriggerBackupRequest struct { + BackupRuleOptions AdHocBackupRuleOptions `json:"backupRuleOptions"` +} diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/model_userfacingerror.go b/resource-manager/dataprotection/2023-11-01/backupinstances/model_userfacingerror.go new file mode 100644 index 00000000000..e3afc757301 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/model_userfacingerror.go @@ -0,0 +1,16 @@ +package backupinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UserFacingError struct { + Code *string `json:"code,omitempty"` + Details *[]UserFacingError `json:"details,omitempty"` + InnerError *InnerError `json:"innerError,omitempty"` + IsRetryable *bool `json:"isRetryable,omitempty"` + IsUserError *bool `json:"isUserError,omitempty"` + Message *string `json:"message,omitempty"` + Properties *map[string]string `json:"properties,omitempty"` + RecommendedAction *[]string `json:"recommendedAction,omitempty"` + Target *string `json:"target,omitempty"` +} diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/model_validatecrossregionrestorerequestobject.go b/resource-manager/dataprotection/2023-11-01/backupinstances/model_validatecrossregionrestorerequestobject.go new file mode 100644 index 00000000000..64c70ca0be3 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/model_validatecrossregionrestorerequestobject.go @@ -0,0 +1,40 @@ +package backupinstances + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ValidateCrossRegionRestoreRequestObject struct { + CrossRegionRestoreDetails CrossRegionRestoreDetails `json:"crossRegionRestoreDetails"` + RestoreRequestObject AzureBackupRestoreRequest `json:"restoreRequestObject"` +} + +var _ json.Unmarshaler = &ValidateCrossRegionRestoreRequestObject{} + +func (s *ValidateCrossRegionRestoreRequestObject) UnmarshalJSON(bytes []byte) error { + type alias ValidateCrossRegionRestoreRequestObject + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into ValidateCrossRegionRestoreRequestObject: %+v", err) + } + + s.CrossRegionRestoreDetails = decoded.CrossRegionRestoreDetails + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling ValidateCrossRegionRestoreRequestObject into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["restoreRequestObject"]; ok { + impl, err := unmarshalAzureBackupRestoreRequestImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'RestoreRequestObject' for 'ValidateCrossRegionRestoreRequestObject': %+v", err) + } + s.RestoreRequestObject = impl + } + return nil +} diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/model_validateforbackuprequest.go b/resource-manager/dataprotection/2023-11-01/backupinstances/model_validateforbackuprequest.go new file mode 100644 index 00000000000..92af8c34ee0 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/model_validateforbackuprequest.go @@ -0,0 +1,8 @@ +package backupinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ValidateForBackupRequest struct { + BackupInstance BackupInstance `json:"backupInstance"` +} diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/model_validaterestorerequestobject.go b/resource-manager/dataprotection/2023-11-01/backupinstances/model_validaterestorerequestobject.go new file mode 100644 index 00000000000..e59fe83da41 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/model_validaterestorerequestobject.go @@ -0,0 +1,32 @@ +package backupinstances + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ValidateRestoreRequestObject struct { + RestoreRequestObject AzureBackupRestoreRequest `json:"restoreRequestObject"` +} + +var _ json.Unmarshaler = &ValidateRestoreRequestObject{} + +func (s *ValidateRestoreRequestObject) UnmarshalJSON(bytes []byte) error { + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling ValidateRestoreRequestObject into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["restoreRequestObject"]; ok { + impl, err := unmarshalAzureBackupRestoreRequestImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'RestoreRequestObject' for 'ValidateRestoreRequestObject': %+v", err) + } + s.RestoreRequestObject = impl + } + return nil +} diff --git a/resource-manager/dataprotection/2023-11-01/backupinstances/predicates.go b/resource-manager/dataprotection/2023-11-01/backupinstances/predicates.go new file mode 100644 index 00000000000..c734a2fe8ca --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/predicates.go @@ -0,0 +1,27 @@ +package backupinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackupInstanceResourceOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p BackupInstanceResourceOperationPredicate) Matches(input BackupInstanceResource) 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/dataprotection/2023-11-01/backupinstances/version.go b/resource-manager/dataprotection/2023-11-01/backupinstances/version.go new file mode 100644 index 00000000000..0f1143df6f2 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupinstances/version.go @@ -0,0 +1,12 @@ +package backupinstances + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-11-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/backupinstances/%s", defaultApiVersion) +} diff --git a/resource-manager/dataprotection/2023-11-01/backuppolicies/README.md b/resource-manager/dataprotection/2023-11-01/backuppolicies/README.md new file mode 100644 index 00000000000..960b346abad --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backuppolicies/README.md @@ -0,0 +1,90 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2023-11-01/backuppolicies` Documentation + +The `backuppolicies` SDK allows for interaction with the Azure Resource Manager Service `dataprotection` (API Version `2023-11-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2023-11-01/backuppolicies" +``` + + +### Client Initialization + +```go +client := backuppolicies.NewBackupPoliciesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `BackupPoliciesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := backuppolicies.NewBackupPolicyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultValue", "backupPolicyValue") + +payload := backuppolicies.BaseBackupPolicyResource{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `BackupPoliciesClient.Delete` + +```go +ctx := context.TODO() +id := backuppolicies.NewBackupPolicyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultValue", "backupPolicyValue") + +read, err := client.Delete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `BackupPoliciesClient.Get` + +```go +ctx := context.TODO() +id := backuppolicies.NewBackupPolicyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultValue", "backupPolicyValue") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `BackupPoliciesClient.List` + +```go +ctx := context.TODO() +id := backuppolicies.NewBackupVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultValue") + +// alternatively `client.List(ctx, id)` can be used to do batched pagination +items, err := client.ListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/dataprotection/2023-11-01/backuppolicies/client.go b/resource-manager/dataprotection/2023-11-01/backuppolicies/client.go new file mode 100644 index 00000000000..7867fb217cc --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backuppolicies/client.go @@ -0,0 +1,26 @@ +package backuppolicies + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackupPoliciesClient struct { + Client *resourcemanager.Client +} + +func NewBackupPoliciesClientWithBaseURI(sdkApi sdkEnv.Api) (*BackupPoliciesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "backuppolicies", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating BackupPoliciesClient: %+v", err) + } + + return &BackupPoliciesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/dataprotection/2023-11-01/backuppolicies/constants.go b/resource-manager/dataprotection/2023-11-01/backuppolicies/constants.go new file mode 100644 index 00000000000..0a08f75af9b --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backuppolicies/constants.go @@ -0,0 +1,281 @@ +package backuppolicies + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AbsoluteMarker string + +const ( + AbsoluteMarkerAllBackup AbsoluteMarker = "AllBackup" + AbsoluteMarkerFirstOfDay AbsoluteMarker = "FirstOfDay" + AbsoluteMarkerFirstOfMonth AbsoluteMarker = "FirstOfMonth" + AbsoluteMarkerFirstOfWeek AbsoluteMarker = "FirstOfWeek" + AbsoluteMarkerFirstOfYear AbsoluteMarker = "FirstOfYear" +) + +func PossibleValuesForAbsoluteMarker() []string { + return []string{ + string(AbsoluteMarkerAllBackup), + string(AbsoluteMarkerFirstOfDay), + string(AbsoluteMarkerFirstOfMonth), + string(AbsoluteMarkerFirstOfWeek), + string(AbsoluteMarkerFirstOfYear), + } +} + +func (s *AbsoluteMarker) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAbsoluteMarker(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAbsoluteMarker(input string) (*AbsoluteMarker, error) { + vals := map[string]AbsoluteMarker{ + "allbackup": AbsoluteMarkerAllBackup, + "firstofday": AbsoluteMarkerFirstOfDay, + "firstofmonth": AbsoluteMarkerFirstOfMonth, + "firstofweek": AbsoluteMarkerFirstOfWeek, + "firstofyear": AbsoluteMarkerFirstOfYear, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AbsoluteMarker(input) + return &out, nil +} + +type DataStoreTypes string + +const ( + DataStoreTypesArchiveStore DataStoreTypes = "ArchiveStore" + DataStoreTypesOperationalStore DataStoreTypes = "OperationalStore" + DataStoreTypesVaultStore DataStoreTypes = "VaultStore" +) + +func PossibleValuesForDataStoreTypes() []string { + return []string{ + string(DataStoreTypesArchiveStore), + string(DataStoreTypesOperationalStore), + string(DataStoreTypesVaultStore), + } +} + +func (s *DataStoreTypes) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDataStoreTypes(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDataStoreTypes(input string) (*DataStoreTypes, error) { + vals := map[string]DataStoreTypes{ + "archivestore": DataStoreTypesArchiveStore, + "operationalstore": DataStoreTypesOperationalStore, + "vaultstore": DataStoreTypesVaultStore, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DataStoreTypes(input) + return &out, nil +} + +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 (s *DayOfWeek) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDayOfWeek(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +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 Month string + +const ( + MonthApril Month = "April" + MonthAugust Month = "August" + MonthDecember Month = "December" + MonthFebruary Month = "February" + MonthJanuary Month = "January" + MonthJuly Month = "July" + MonthJune Month = "June" + MonthMarch Month = "March" + MonthMay Month = "May" + MonthNovember Month = "November" + MonthOctober Month = "October" + MonthSeptember Month = "September" +) + +func PossibleValuesForMonth() []string { + return []string{ + string(MonthApril), + string(MonthAugust), + string(MonthDecember), + string(MonthFebruary), + string(MonthJanuary), + string(MonthJuly), + string(MonthJune), + string(MonthMarch), + string(MonthMay), + string(MonthNovember), + string(MonthOctober), + string(MonthSeptember), + } +} + +func (s *Month) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseMonth(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseMonth(input string) (*Month, error) { + vals := map[string]Month{ + "april": MonthApril, + "august": MonthAugust, + "december": MonthDecember, + "february": MonthFebruary, + "january": MonthJanuary, + "july": MonthJuly, + "june": MonthJune, + "march": MonthMarch, + "may": MonthMay, + "november": MonthNovember, + "october": MonthOctober, + "september": MonthSeptember, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Month(input) + return &out, nil +} + +type WeekNumber string + +const ( + WeekNumberFirst WeekNumber = "First" + WeekNumberFourth WeekNumber = "Fourth" + WeekNumberLast WeekNumber = "Last" + WeekNumberSecond WeekNumber = "Second" + WeekNumberThird WeekNumber = "Third" +) + +func PossibleValuesForWeekNumber() []string { + return []string{ + string(WeekNumberFirst), + string(WeekNumberFourth), + string(WeekNumberLast), + string(WeekNumberSecond), + string(WeekNumberThird), + } +} + +func (s *WeekNumber) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseWeekNumber(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseWeekNumber(input string) (*WeekNumber, error) { + vals := map[string]WeekNumber{ + "first": WeekNumberFirst, + "fourth": WeekNumberFourth, + "last": WeekNumberLast, + "second": WeekNumberSecond, + "third": WeekNumberThird, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := WeekNumber(input) + return &out, nil +} diff --git a/resource-manager/dataprotection/2023-11-01/backuppolicies/id_backuppolicy.go b/resource-manager/dataprotection/2023-11-01/backuppolicies/id_backuppolicy.go new file mode 100644 index 00000000000..8403e90a879 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backuppolicies/id_backuppolicy.go @@ -0,0 +1,134 @@ +package backuppolicies + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = BackupPolicyId{} + +// BackupPolicyId is a struct representing the Resource ID for a Backup Policy +type BackupPolicyId struct { + SubscriptionId string + ResourceGroupName string + BackupVaultName string + BackupPolicyName string +} + +// NewBackupPolicyID returns a new BackupPolicyId struct +func NewBackupPolicyID(subscriptionId string, resourceGroupName string, backupVaultName string, backupPolicyName string) BackupPolicyId { + return BackupPolicyId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + BackupVaultName: backupVaultName, + BackupPolicyName: backupPolicyName, + } +} + +// ParseBackupPolicyID parses 'input' into a BackupPolicyId +func ParseBackupPolicyID(input string) (*BackupPolicyId, error) { + parser := resourceids.NewParserFromResourceIdType(BackupPolicyId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BackupPolicyId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseBackupPolicyIDInsensitively parses 'input' case-insensitively into a BackupPolicyId +// note: this method should only be used for API response data and not user input +func ParseBackupPolicyIDInsensitively(input string) (*BackupPolicyId, error) { + parser := resourceids.NewParserFromResourceIdType(BackupPolicyId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BackupPolicyId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *BackupPolicyId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.BackupVaultName, ok = input.Parsed["backupVaultName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "backupVaultName", input) + } + + if id.BackupPolicyName, ok = input.Parsed["backupPolicyName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "backupPolicyName", input) + } + + return nil +} + +// ValidateBackupPolicyID checks that 'input' can be parsed as a Backup Policy ID +func ValidateBackupPolicyID(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 := ParseBackupPolicyID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Backup Policy ID +func (id BackupPolicyId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DataProtection/backupVaults/%s/backupPolicies/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.BackupVaultName, id.BackupPolicyName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Backup Policy ID +func (id BackupPolicyId) 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("staticMicrosoftDataProtection", "Microsoft.DataProtection", "Microsoft.DataProtection"), + resourceids.StaticSegment("staticBackupVaults", "backupVaults", "backupVaults"), + resourceids.UserSpecifiedSegment("backupVaultName", "backupVaultValue"), + resourceids.StaticSegment("staticBackupPolicies", "backupPolicies", "backupPolicies"), + resourceids.UserSpecifiedSegment("backupPolicyName", "backupPolicyValue"), + } +} + +// String returns a human-readable description of this Backup Policy ID +func (id BackupPolicyId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Backup Vault Name: %q", id.BackupVaultName), + fmt.Sprintf("Backup Policy Name: %q", id.BackupPolicyName), + } + return fmt.Sprintf("Backup Policy (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/dataprotection/2023-11-01/backuppolicies/id_backuppolicy_test.go b/resource-manager/dataprotection/2023-11-01/backuppolicies/id_backuppolicy_test.go new file mode 100644 index 00000000000..dbbe726c53a --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backuppolicies/id_backuppolicy_test.go @@ -0,0 +1,327 @@ +package backuppolicies + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = BackupPolicyId{} + +func TestNewBackupPolicyID(t *testing.T) { + id := NewBackupPolicyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultValue", "backupPolicyValue") + + 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.BackupVaultName != "backupVaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'BackupVaultName'", id.BackupVaultName, "backupVaultValue") + } + + if id.BackupPolicyName != "backupPolicyValue" { + t.Fatalf("Expected %q but got %q for Segment 'BackupPolicyName'", id.BackupPolicyName, "backupPolicyValue") + } +} + +func TestFormatBackupPolicyID(t *testing.T) { + actual := NewBackupPolicyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultValue", "backupPolicyValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/backupPolicies/backupPolicyValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseBackupPolicyID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BackupPolicyId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/backupPolicies", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/backupPolicies/backupPolicyValue", + Expected: &BackupPolicyId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + BackupVaultName: "backupVaultValue", + BackupPolicyName: "backupPolicyValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/backupPolicies/backupPolicyValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBackupPolicyID(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.BackupVaultName != v.Expected.BackupVaultName { + t.Fatalf("Expected %q but got %q for BackupVaultName", v.Expected.BackupVaultName, actual.BackupVaultName) + } + + if actual.BackupPolicyName != v.Expected.BackupPolicyName { + t.Fatalf("Expected %q but got %q for BackupPolicyName", v.Expected.BackupPolicyName, actual.BackupPolicyName) + } + + } +} + +func TestParseBackupPolicyIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BackupPolicyId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/backupPolicies", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtVaLuE/bAcKuPpOlIcIeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/backupPolicies/backupPolicyValue", + Expected: &BackupPolicyId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + BackupVaultName: "backupVaultValue", + BackupPolicyName: "backupPolicyValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/backupPolicies/backupPolicyValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtVaLuE/bAcKuPpOlIcIeS/bAcKuPpOlIcYvAlUe", + Expected: &BackupPolicyId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + BackupVaultName: "bAcKuPvAuLtVaLuE", + BackupPolicyName: "bAcKuPpOlIcYvAlUe", + }, + }, + { + // 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.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtVaLuE/bAcKuPpOlIcIeS/bAcKuPpOlIcYvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBackupPolicyIDInsensitively(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.BackupVaultName != v.Expected.BackupVaultName { + t.Fatalf("Expected %q but got %q for BackupVaultName", v.Expected.BackupVaultName, actual.BackupVaultName) + } + + if actual.BackupPolicyName != v.Expected.BackupPolicyName { + t.Fatalf("Expected %q but got %q for BackupPolicyName", v.Expected.BackupPolicyName, actual.BackupPolicyName) + } + + } +} + +func TestSegmentsForBackupPolicyId(t *testing.T) { + segments := BackupPolicyId{}.Segments() + if len(segments) == 0 { + t.Fatalf("BackupPolicyId 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/dataprotection/2023-11-01/backuppolicies/id_backupvault.go b/resource-manager/dataprotection/2023-11-01/backuppolicies/id_backupvault.go new file mode 100644 index 00000000000..de03baab418 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backuppolicies/id_backupvault.go @@ -0,0 +1,125 @@ +package backuppolicies + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = BackupVaultId{} + +// BackupVaultId is a struct representing the Resource ID for a Backup Vault +type BackupVaultId struct { + SubscriptionId string + ResourceGroupName string + BackupVaultName string +} + +// NewBackupVaultID returns a new BackupVaultId struct +func NewBackupVaultID(subscriptionId string, resourceGroupName string, backupVaultName string) BackupVaultId { + return BackupVaultId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + BackupVaultName: backupVaultName, + } +} + +// ParseBackupVaultID parses 'input' into a BackupVaultId +func ParseBackupVaultID(input string) (*BackupVaultId, error) { + parser := resourceids.NewParserFromResourceIdType(BackupVaultId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BackupVaultId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseBackupVaultIDInsensitively parses 'input' case-insensitively into a BackupVaultId +// note: this method should only be used for API response data and not user input +func ParseBackupVaultIDInsensitively(input string) (*BackupVaultId, error) { + parser := resourceids.NewParserFromResourceIdType(BackupVaultId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BackupVaultId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *BackupVaultId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.BackupVaultName, ok = input.Parsed["backupVaultName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "backupVaultName", input) + } + + return nil +} + +// ValidateBackupVaultID checks that 'input' can be parsed as a Backup Vault ID +func ValidateBackupVaultID(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 := ParseBackupVaultID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Backup Vault ID +func (id BackupVaultId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DataProtection/backupVaults/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.BackupVaultName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Backup Vault ID +func (id BackupVaultId) 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("staticMicrosoftDataProtection", "Microsoft.DataProtection", "Microsoft.DataProtection"), + resourceids.StaticSegment("staticBackupVaults", "backupVaults", "backupVaults"), + resourceids.UserSpecifiedSegment("backupVaultName", "backupVaultValue"), + } +} + +// String returns a human-readable description of this Backup Vault ID +func (id BackupVaultId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Backup Vault Name: %q", id.BackupVaultName), + } + return fmt.Sprintf("Backup Vault (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/dataprotection/2023-11-01/backuppolicies/id_backupvault_test.go b/resource-manager/dataprotection/2023-11-01/backuppolicies/id_backupvault_test.go new file mode 100644 index 00000000000..fb9abb3a014 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backuppolicies/id_backupvault_test.go @@ -0,0 +1,282 @@ +package backuppolicies + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = BackupVaultId{} + +func TestNewBackupVaultID(t *testing.T) { + id := NewBackupVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultValue") + + 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.BackupVaultName != "backupVaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'BackupVaultName'", id.BackupVaultName, "backupVaultValue") + } +} + +func TestFormatBackupVaultID(t *testing.T) { + actual := NewBackupVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseBackupVaultID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BackupVaultId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue", + Expected: &BackupVaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + BackupVaultName: "backupVaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBackupVaultID(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.BackupVaultName != v.Expected.BackupVaultName { + t.Fatalf("Expected %q but got %q for BackupVaultName", v.Expected.BackupVaultName, actual.BackupVaultName) + } + + } +} + +func TestParseBackupVaultIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BackupVaultId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue", + Expected: &BackupVaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + BackupVaultName: "backupVaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtVaLuE", + Expected: &BackupVaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + BackupVaultName: "bAcKuPvAuLtVaLuE", + }, + }, + { + // 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.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBackupVaultIDInsensitively(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.BackupVaultName != v.Expected.BackupVaultName { + t.Fatalf("Expected %q but got %q for BackupVaultName", v.Expected.BackupVaultName, actual.BackupVaultName) + } + + } +} + +func TestSegmentsForBackupVaultId(t *testing.T) { + segments := BackupVaultId{}.Segments() + if len(segments) == 0 { + t.Fatalf("BackupVaultId 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/dataprotection/2023-11-01/backuppolicies/method_createorupdate.go b/resource-manager/dataprotection/2023-11-01/backuppolicies/method_createorupdate.go new file mode 100644 index 00000000000..a2e069b3e80 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backuppolicies/method_createorupdate.go @@ -0,0 +1,55 @@ +package backuppolicies + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *BaseBackupPolicyResource +} + +// CreateOrUpdate ... +func (c BackupPoliciesClient) CreateOrUpdate(ctx context.Context, id BackupPolicyId, input BaseBackupPolicyResource) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/dataprotection/2023-11-01/backuppolicies/method_delete.go b/resource-manager/dataprotection/2023-11-01/backuppolicies/method_delete.go new file mode 100644 index 00000000000..8b9659f79fa --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backuppolicies/method_delete.go @@ -0,0 +1,47 @@ +package backuppolicies + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c BackupPoliciesClient) Delete(ctx context.Context, id BackupPolicyId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/dataprotection/2023-11-01/backuppolicies/method_get.go b/resource-manager/dataprotection/2023-11-01/backuppolicies/method_get.go new file mode 100644 index 00000000000..2bfac7c2929 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backuppolicies/method_get.go @@ -0,0 +1,51 @@ +package backuppolicies + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *BaseBackupPolicyResource +} + +// Get ... +func (c BackupPoliciesClient) Get(ctx context.Context, id BackupPolicyId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/dataprotection/2023-11-01/backuppolicies/method_list.go b/resource-manager/dataprotection/2023-11-01/backuppolicies/method_list.go new file mode 100644 index 00000000000..75d71b88ab0 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backuppolicies/method_list.go @@ -0,0 +1,89 @@ +package backuppolicies + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]BaseBackupPolicyResource +} + +type ListCompleteResult struct { + Items []BaseBackupPolicyResource +} + +// List ... +func (c BackupPoliciesClient) List(ctx context.Context, id BackupVaultId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/backupPolicies", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]BaseBackupPolicyResource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c BackupPoliciesClient) ListComplete(ctx context.Context, id BackupVaultId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, BaseBackupPolicyResourceOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c BackupPoliciesClient) ListCompleteMatchingPredicate(ctx context.Context, id BackupVaultId, predicate BaseBackupPolicyResourceOperationPredicate) (result ListCompleteResult, err error) { + items := make([]BaseBackupPolicyResource, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + Items: items, + } + return +} diff --git a/resource-manager/dataprotection/2023-11-01/backuppolicies/model_absolutedeleteoption.go b/resource-manager/dataprotection/2023-11-01/backuppolicies/model_absolutedeleteoption.go new file mode 100644 index 00000000000..a9aaf47dcb7 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backuppolicies/model_absolutedeleteoption.go @@ -0,0 +1,41 @@ +package backuppolicies + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeleteOption = AbsoluteDeleteOption{} + +type AbsoluteDeleteOption struct { + + // Fields inherited from DeleteOption + Duration string `json:"duration"` +} + +var _ json.Marshaler = AbsoluteDeleteOption{} + +func (s AbsoluteDeleteOption) MarshalJSON() ([]byte, error) { + type wrapper AbsoluteDeleteOption + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AbsoluteDeleteOption: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AbsoluteDeleteOption: %+v", err) + } + decoded["objectType"] = "AbsoluteDeleteOption" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AbsoluteDeleteOption: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/dataprotection/2023-11-01/backuppolicies/model_adhocbasedtaggingcriteria.go b/resource-manager/dataprotection/2023-11-01/backuppolicies/model_adhocbasedtaggingcriteria.go new file mode 100644 index 00000000000..e74b150de31 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backuppolicies/model_adhocbasedtaggingcriteria.go @@ -0,0 +1,8 @@ +package backuppolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AdhocBasedTaggingCriteria struct { + TagInfo *RetentionTag `json:"tagInfo,omitempty"` +} diff --git a/resource-manager/dataprotection/2023-11-01/backuppolicies/model_adhocbasedtriggercontext.go b/resource-manager/dataprotection/2023-11-01/backuppolicies/model_adhocbasedtriggercontext.go new file mode 100644 index 00000000000..5505a40b8a6 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backuppolicies/model_adhocbasedtriggercontext.go @@ -0,0 +1,41 @@ +package backuppolicies + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ TriggerContext = AdhocBasedTriggerContext{} + +type AdhocBasedTriggerContext struct { + TaggingCriteria AdhocBasedTaggingCriteria `json:"taggingCriteria"` + + // Fields inherited from TriggerContext +} + +var _ json.Marshaler = AdhocBasedTriggerContext{} + +func (s AdhocBasedTriggerContext) MarshalJSON() ([]byte, error) { + type wrapper AdhocBasedTriggerContext + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AdhocBasedTriggerContext: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AdhocBasedTriggerContext: %+v", err) + } + decoded["objectType"] = "AdhocBasedTriggerContext" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AdhocBasedTriggerContext: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/dataprotection/2023-11-01/backuppolicies/model_azurebackupparams.go b/resource-manager/dataprotection/2023-11-01/backuppolicies/model_azurebackupparams.go new file mode 100644 index 00000000000..024401c3d86 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backuppolicies/model_azurebackupparams.go @@ -0,0 +1,41 @@ +package backuppolicies + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ BackupParameters = AzureBackupParams{} + +type AzureBackupParams struct { + BackupType string `json:"backupType"` + + // Fields inherited from BackupParameters +} + +var _ json.Marshaler = AzureBackupParams{} + +func (s AzureBackupParams) MarshalJSON() ([]byte, error) { + type wrapper AzureBackupParams + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureBackupParams: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureBackupParams: %+v", err) + } + decoded["objectType"] = "AzureBackupParams" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureBackupParams: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/dataprotection/2023-11-01/backuppolicies/model_azurebackuprule.go b/resource-manager/dataprotection/2023-11-01/backuppolicies/model_azurebackuprule.go new file mode 100644 index 00000000000..884536bf720 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backuppolicies/model_azurebackuprule.go @@ -0,0 +1,79 @@ +package backuppolicies + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ BasePolicyRule = AzureBackupRule{} + +type AzureBackupRule struct { + BackupParameters BackupParameters `json:"backupParameters"` + DataStore DataStoreInfoBase `json:"dataStore"` + Trigger TriggerContext `json:"trigger"` + + // Fields inherited from BasePolicyRule + Name string `json:"name"` +} + +var _ json.Marshaler = AzureBackupRule{} + +func (s AzureBackupRule) MarshalJSON() ([]byte, error) { + type wrapper AzureBackupRule + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureBackupRule: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureBackupRule: %+v", err) + } + decoded["objectType"] = "AzureBackupRule" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureBackupRule: %+v", err) + } + + return encoded, nil +} + +var _ json.Unmarshaler = &AzureBackupRule{} + +func (s *AzureBackupRule) UnmarshalJSON(bytes []byte) error { + type alias AzureBackupRule + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into AzureBackupRule: %+v", err) + } + + s.DataStore = decoded.DataStore + s.Name = decoded.Name + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling AzureBackupRule into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["backupParameters"]; ok { + impl, err := unmarshalBackupParametersImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'BackupParameters' for 'AzureBackupRule': %+v", err) + } + s.BackupParameters = impl + } + + if v, ok := temp["trigger"]; ok { + impl, err := unmarshalTriggerContextImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'Trigger' for 'AzureBackupRule': %+v", err) + } + s.Trigger = impl + } + return nil +} diff --git a/resource-manager/dataprotection/2023-11-01/backuppolicies/model_azureretentionrule.go b/resource-manager/dataprotection/2023-11-01/backuppolicies/model_azureretentionrule.go new file mode 100644 index 00000000000..1362ef8628d --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backuppolicies/model_azureretentionrule.go @@ -0,0 +1,43 @@ +package backuppolicies + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ BasePolicyRule = AzureRetentionRule{} + +type AzureRetentionRule struct { + IsDefault *bool `json:"isDefault,omitempty"` + Lifecycles []SourceLifeCycle `json:"lifecycles"` + + // Fields inherited from BasePolicyRule + Name string `json:"name"` +} + +var _ json.Marshaler = AzureRetentionRule{} + +func (s AzureRetentionRule) MarshalJSON() ([]byte, error) { + type wrapper AzureRetentionRule + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureRetentionRule: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureRetentionRule: %+v", err) + } + decoded["objectType"] = "AzureRetentionRule" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureRetentionRule: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/dataprotection/2023-11-01/backuppolicies/model_backupcriteria.go b/resource-manager/dataprotection/2023-11-01/backuppolicies/model_backupcriteria.go new file mode 100644 index 00000000000..ae5e3acf7f9 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backuppolicies/model_backupcriteria.go @@ -0,0 +1,53 @@ +package backuppolicies + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackupCriteria interface { +} + +// RawBackupCriteriaImpl is returned when the Discriminated Value +// doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawBackupCriteriaImpl struct { + Type string + Values map[string]interface{} +} + +func unmarshalBackupCriteriaImplementation(input []byte) (BackupCriteria, error) { + if input == nil { + return nil, nil + } + + var temp map[string]interface{} + if err := json.Unmarshal(input, &temp); err != nil { + return nil, fmt.Errorf("unmarshaling BackupCriteria into map[string]interface: %+v", err) + } + + value, ok := temp["objectType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "ScheduleBasedBackupCriteria") { + var out ScheduleBasedBackupCriteria + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into ScheduleBasedBackupCriteria: %+v", err) + } + return out, nil + } + + out := RawBackupCriteriaImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/dataprotection/2023-11-01/backuppolicies/model_backupparameters.go b/resource-manager/dataprotection/2023-11-01/backuppolicies/model_backupparameters.go new file mode 100644 index 00000000000..2cd46e5bbe7 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backuppolicies/model_backupparameters.go @@ -0,0 +1,53 @@ +package backuppolicies + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackupParameters interface { +} + +// RawBackupParametersImpl is returned when the Discriminated Value +// doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawBackupParametersImpl struct { + Type string + Values map[string]interface{} +} + +func unmarshalBackupParametersImplementation(input []byte) (BackupParameters, error) { + if input == nil { + return nil, nil + } + + var temp map[string]interface{} + if err := json.Unmarshal(input, &temp); err != nil { + return nil, fmt.Errorf("unmarshaling BackupParameters into map[string]interface: %+v", err) + } + + value, ok := temp["objectType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "AzureBackupParams") { + var out AzureBackupParams + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureBackupParams: %+v", err) + } + return out, nil + } + + out := RawBackupParametersImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/dataprotection/2023-11-01/backuppolicies/model_backuppolicy.go b/resource-manager/dataprotection/2023-11-01/backuppolicies/model_backuppolicy.go new file mode 100644 index 00000000000..5b770c9a733 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backuppolicies/model_backuppolicy.go @@ -0,0 +1,77 @@ +package backuppolicies + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ BaseBackupPolicy = BackupPolicy{} + +type BackupPolicy struct { + PolicyRules []BasePolicyRule `json:"policyRules"` + + // Fields inherited from BaseBackupPolicy + DatasourceTypes []string `json:"datasourceTypes"` +} + +var _ json.Marshaler = BackupPolicy{} + +func (s BackupPolicy) MarshalJSON() ([]byte, error) { + type wrapper BackupPolicy + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling BackupPolicy: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling BackupPolicy: %+v", err) + } + decoded["objectType"] = "BackupPolicy" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling BackupPolicy: %+v", err) + } + + return encoded, nil +} + +var _ json.Unmarshaler = &BackupPolicy{} + +func (s *BackupPolicy) UnmarshalJSON(bytes []byte) error { + type alias BackupPolicy + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into BackupPolicy: %+v", err) + } + + s.DatasourceTypes = decoded.DatasourceTypes + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling BackupPolicy into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["policyRules"]; ok { + var listTemp []json.RawMessage + if err := json.Unmarshal(v, &listTemp); err != nil { + return fmt.Errorf("unmarshaling PolicyRules into list []json.RawMessage: %+v", err) + } + + output := make([]BasePolicyRule, 0) + for i, val := range listTemp { + impl, err := unmarshalBasePolicyRuleImplementation(val) + if err != nil { + return fmt.Errorf("unmarshaling index %d field 'PolicyRules' for 'BackupPolicy': %+v", i, err) + } + output = append(output, impl) + } + s.PolicyRules = output + } + return nil +} diff --git a/resource-manager/dataprotection/2023-11-01/backuppolicies/model_backupschedule.go b/resource-manager/dataprotection/2023-11-01/backuppolicies/model_backupschedule.go new file mode 100644 index 00000000000..47d41f51d4c --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backuppolicies/model_backupschedule.go @@ -0,0 +1,9 @@ +package backuppolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackupSchedule struct { + RepeatingTimeIntervals []string `json:"repeatingTimeIntervals"` + TimeZone *string `json:"timeZone,omitempty"` +} diff --git a/resource-manager/dataprotection/2023-11-01/backuppolicies/model_basebackuppolicy.go b/resource-manager/dataprotection/2023-11-01/backuppolicies/model_basebackuppolicy.go new file mode 100644 index 00000000000..5da7096ec0c --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backuppolicies/model_basebackuppolicy.go @@ -0,0 +1,53 @@ +package backuppolicies + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BaseBackupPolicy interface { +} + +// RawBaseBackupPolicyImpl is returned when the Discriminated Value +// doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawBaseBackupPolicyImpl struct { + Type string + Values map[string]interface{} +} + +func unmarshalBaseBackupPolicyImplementation(input []byte) (BaseBackupPolicy, error) { + if input == nil { + return nil, nil + } + + var temp map[string]interface{} + if err := json.Unmarshal(input, &temp); err != nil { + return nil, fmt.Errorf("unmarshaling BaseBackupPolicy into map[string]interface: %+v", err) + } + + value, ok := temp["objectType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "BackupPolicy") { + var out BackupPolicy + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into BackupPolicy: %+v", err) + } + return out, nil + } + + out := RawBaseBackupPolicyImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/dataprotection/2023-11-01/backuppolicies/model_basebackuppolicyresource.go b/resource-manager/dataprotection/2023-11-01/backuppolicies/model_basebackuppolicyresource.go new file mode 100644 index 00000000000..dbc62cc6103 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backuppolicies/model_basebackuppolicyresource.go @@ -0,0 +1,48 @@ +package backuppolicies + +import ( + "encoding/json" + "fmt" + + "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 BaseBackupPolicyResource struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties BaseBackupPolicy `json:"properties"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Unmarshaler = &BaseBackupPolicyResource{} + +func (s *BaseBackupPolicyResource) UnmarshalJSON(bytes []byte) error { + type alias BaseBackupPolicyResource + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into BaseBackupPolicyResource: %+v", err) + } + + s.Id = decoded.Id + s.Name = decoded.Name + s.SystemData = decoded.SystemData + s.Type = decoded.Type + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling BaseBackupPolicyResource into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["properties"]; ok { + impl, err := unmarshalBaseBackupPolicyImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'Properties' for 'BaseBackupPolicyResource': %+v", err) + } + s.Properties = impl + } + return nil +} diff --git a/resource-manager/dataprotection/2023-11-01/backuppolicies/model_basepolicyrule.go b/resource-manager/dataprotection/2023-11-01/backuppolicies/model_basepolicyrule.go new file mode 100644 index 00000000000..2434dc31521 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backuppolicies/model_basepolicyrule.go @@ -0,0 +1,61 @@ +package backuppolicies + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BasePolicyRule interface { +} + +// RawBasePolicyRuleImpl is returned when the Discriminated Value +// doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawBasePolicyRuleImpl struct { + Type string + Values map[string]interface{} +} + +func unmarshalBasePolicyRuleImplementation(input []byte) (BasePolicyRule, error) { + if input == nil { + return nil, nil + } + + var temp map[string]interface{} + if err := json.Unmarshal(input, &temp); err != nil { + return nil, fmt.Errorf("unmarshaling BasePolicyRule into map[string]interface: %+v", err) + } + + value, ok := temp["objectType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "AzureBackupRule") { + var out AzureBackupRule + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureBackupRule: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "AzureRetentionRule") { + var out AzureRetentionRule + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureRetentionRule: %+v", err) + } + return out, nil + } + + out := RawBasePolicyRuleImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/dataprotection/2023-11-01/backuppolicies/model_copyonexpiryoption.go b/resource-manager/dataprotection/2023-11-01/backuppolicies/model_copyonexpiryoption.go new file mode 100644 index 00000000000..38c92a43d50 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backuppolicies/model_copyonexpiryoption.go @@ -0,0 +1,40 @@ +package backuppolicies + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ CopyOption = CopyOnExpiryOption{} + +type CopyOnExpiryOption struct { + + // Fields inherited from CopyOption +} + +var _ json.Marshaler = CopyOnExpiryOption{} + +func (s CopyOnExpiryOption) MarshalJSON() ([]byte, error) { + type wrapper CopyOnExpiryOption + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling CopyOnExpiryOption: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling CopyOnExpiryOption: %+v", err) + } + decoded["objectType"] = "CopyOnExpiryOption" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling CopyOnExpiryOption: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/dataprotection/2023-11-01/backuppolicies/model_copyoption.go b/resource-manager/dataprotection/2023-11-01/backuppolicies/model_copyoption.go new file mode 100644 index 00000000000..8015dcb6bfd --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backuppolicies/model_copyoption.go @@ -0,0 +1,69 @@ +package backuppolicies + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CopyOption interface { +} + +// RawCopyOptionImpl is returned when the Discriminated Value +// doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawCopyOptionImpl struct { + Type string + Values map[string]interface{} +} + +func unmarshalCopyOptionImplementation(input []byte) (CopyOption, error) { + if input == nil { + return nil, nil + } + + var temp map[string]interface{} + if err := json.Unmarshal(input, &temp); err != nil { + return nil, fmt.Errorf("unmarshaling CopyOption into map[string]interface: %+v", err) + } + + value, ok := temp["objectType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "CopyOnExpiryOption") { + var out CopyOnExpiryOption + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into CopyOnExpiryOption: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "CustomCopyOption") { + var out CustomCopyOption + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into CustomCopyOption: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "ImmediateCopyOption") { + var out ImmediateCopyOption + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into ImmediateCopyOption: %+v", err) + } + return out, nil + } + + out := RawCopyOptionImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/dataprotection/2023-11-01/backuppolicies/model_customcopyoption.go b/resource-manager/dataprotection/2023-11-01/backuppolicies/model_customcopyoption.go new file mode 100644 index 00000000000..f450054e89a --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backuppolicies/model_customcopyoption.go @@ -0,0 +1,41 @@ +package backuppolicies + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ CopyOption = CustomCopyOption{} + +type CustomCopyOption struct { + Duration *string `json:"duration,omitempty"` + + // Fields inherited from CopyOption +} + +var _ json.Marshaler = CustomCopyOption{} + +func (s CustomCopyOption) MarshalJSON() ([]byte, error) { + type wrapper CustomCopyOption + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling CustomCopyOption: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling CustomCopyOption: %+v", err) + } + decoded["objectType"] = "CustomCopyOption" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling CustomCopyOption: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/dataprotection/2023-11-01/backuppolicies/model_datastoreinfobase.go b/resource-manager/dataprotection/2023-11-01/backuppolicies/model_datastoreinfobase.go new file mode 100644 index 00000000000..d462ed4c6f6 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backuppolicies/model_datastoreinfobase.go @@ -0,0 +1,9 @@ +package backuppolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DataStoreInfoBase struct { + DataStoreType DataStoreTypes `json:"dataStoreType"` + ObjectType string `json:"objectType"` +} diff --git a/resource-manager/dataprotection/2023-11-01/backuppolicies/model_day.go b/resource-manager/dataprotection/2023-11-01/backuppolicies/model_day.go new file mode 100644 index 00000000000..c46c7f57129 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backuppolicies/model_day.go @@ -0,0 +1,9 @@ +package backuppolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Day struct { + Date *int64 `json:"date,omitempty"` + IsLast *bool `json:"isLast,omitempty"` +} diff --git a/resource-manager/dataprotection/2023-11-01/backuppolicies/model_deleteoption.go b/resource-manager/dataprotection/2023-11-01/backuppolicies/model_deleteoption.go new file mode 100644 index 00000000000..d8ac5dc7882 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backuppolicies/model_deleteoption.go @@ -0,0 +1,53 @@ +package backuppolicies + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOption interface { +} + +// RawDeleteOptionImpl is returned when the Discriminated Value +// doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawDeleteOptionImpl struct { + Type string + Values map[string]interface{} +} + +func unmarshalDeleteOptionImplementation(input []byte) (DeleteOption, error) { + if input == nil { + return nil, nil + } + + var temp map[string]interface{} + if err := json.Unmarshal(input, &temp); err != nil { + return nil, fmt.Errorf("unmarshaling DeleteOption into map[string]interface: %+v", err) + } + + value, ok := temp["objectType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "AbsoluteDeleteOption") { + var out AbsoluteDeleteOption + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AbsoluteDeleteOption: %+v", err) + } + return out, nil + } + + out := RawDeleteOptionImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/dataprotection/2023-11-01/backuppolicies/model_immediatecopyoption.go b/resource-manager/dataprotection/2023-11-01/backuppolicies/model_immediatecopyoption.go new file mode 100644 index 00000000000..a8e54686cc9 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backuppolicies/model_immediatecopyoption.go @@ -0,0 +1,40 @@ +package backuppolicies + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ CopyOption = ImmediateCopyOption{} + +type ImmediateCopyOption struct { + + // Fields inherited from CopyOption +} + +var _ json.Marshaler = ImmediateCopyOption{} + +func (s ImmediateCopyOption) MarshalJSON() ([]byte, error) { + type wrapper ImmediateCopyOption + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling ImmediateCopyOption: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling ImmediateCopyOption: %+v", err) + } + decoded["objectType"] = "ImmediateCopyOption" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling ImmediateCopyOption: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/dataprotection/2023-11-01/backuppolicies/model_retentiontag.go b/resource-manager/dataprotection/2023-11-01/backuppolicies/model_retentiontag.go new file mode 100644 index 00000000000..f9a6dff3e17 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backuppolicies/model_retentiontag.go @@ -0,0 +1,10 @@ +package backuppolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RetentionTag struct { + ETag *string `json:"eTag,omitempty"` + Id *string `json:"id,omitempty"` + TagName string `json:"tagName"` +} diff --git a/resource-manager/dataprotection/2023-11-01/backuppolicies/model_schedulebasedbackupcriteria.go b/resource-manager/dataprotection/2023-11-01/backuppolicies/model_schedulebasedbackupcriteria.go new file mode 100644 index 00000000000..6e2c614f630 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backuppolicies/model_schedulebasedbackupcriteria.go @@ -0,0 +1,46 @@ +package backuppolicies + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ BackupCriteria = ScheduleBasedBackupCriteria{} + +type ScheduleBasedBackupCriteria struct { + AbsoluteCriteria *[]AbsoluteMarker `json:"absoluteCriteria,omitempty"` + DaysOfMonth *[]Day `json:"daysOfMonth,omitempty"` + DaysOfTheWeek *[]DayOfWeek `json:"daysOfTheWeek,omitempty"` + MonthsOfYear *[]Month `json:"monthsOfYear,omitempty"` + ScheduleTimes *[]string `json:"scheduleTimes,omitempty"` + WeeksOfTheMonth *[]WeekNumber `json:"weeksOfTheMonth,omitempty"` + + // Fields inherited from BackupCriteria +} + +var _ json.Marshaler = ScheduleBasedBackupCriteria{} + +func (s ScheduleBasedBackupCriteria) MarshalJSON() ([]byte, error) { + type wrapper ScheduleBasedBackupCriteria + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling ScheduleBasedBackupCriteria: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling ScheduleBasedBackupCriteria: %+v", err) + } + decoded["objectType"] = "ScheduleBasedBackupCriteria" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling ScheduleBasedBackupCriteria: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/dataprotection/2023-11-01/backuppolicies/model_schedulebasedtriggercontext.go b/resource-manager/dataprotection/2023-11-01/backuppolicies/model_schedulebasedtriggercontext.go new file mode 100644 index 00000000000..c7f96a85c13 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backuppolicies/model_schedulebasedtriggercontext.go @@ -0,0 +1,42 @@ +package backuppolicies + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ TriggerContext = ScheduleBasedTriggerContext{} + +type ScheduleBasedTriggerContext struct { + Schedule BackupSchedule `json:"schedule"` + TaggingCriteria []TaggingCriteria `json:"taggingCriteria"` + + // Fields inherited from TriggerContext +} + +var _ json.Marshaler = ScheduleBasedTriggerContext{} + +func (s ScheduleBasedTriggerContext) MarshalJSON() ([]byte, error) { + type wrapper ScheduleBasedTriggerContext + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling ScheduleBasedTriggerContext: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling ScheduleBasedTriggerContext: %+v", err) + } + decoded["objectType"] = "ScheduleBasedTriggerContext" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling ScheduleBasedTriggerContext: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/dataprotection/2023-11-01/backuppolicies/model_sourcelifecycle.go b/resource-manager/dataprotection/2023-11-01/backuppolicies/model_sourcelifecycle.go new file mode 100644 index 00000000000..7538681c1b2 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backuppolicies/model_sourcelifecycle.go @@ -0,0 +1,42 @@ +package backuppolicies + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SourceLifeCycle struct { + DeleteAfter DeleteOption `json:"deleteAfter"` + SourceDataStore DataStoreInfoBase `json:"sourceDataStore"` + TargetDataStoreCopySettings *[]TargetCopySetting `json:"targetDataStoreCopySettings,omitempty"` +} + +var _ json.Unmarshaler = &SourceLifeCycle{} + +func (s *SourceLifeCycle) UnmarshalJSON(bytes []byte) error { + type alias SourceLifeCycle + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into SourceLifeCycle: %+v", err) + } + + s.SourceDataStore = decoded.SourceDataStore + s.TargetDataStoreCopySettings = decoded.TargetDataStoreCopySettings + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling SourceLifeCycle into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["deleteAfter"]; ok { + impl, err := unmarshalDeleteOptionImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'DeleteAfter' for 'SourceLifeCycle': %+v", err) + } + s.DeleteAfter = impl + } + return nil +} diff --git a/resource-manager/dataprotection/2023-11-01/backuppolicies/model_taggingcriteria.go b/resource-manager/dataprotection/2023-11-01/backuppolicies/model_taggingcriteria.go new file mode 100644 index 00000000000..71c094c4d32 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backuppolicies/model_taggingcriteria.go @@ -0,0 +1,53 @@ +package backuppolicies + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TaggingCriteria struct { + Criteria *[]BackupCriteria `json:"criteria,omitempty"` + IsDefault bool `json:"isDefault"` + TagInfo RetentionTag `json:"tagInfo"` + TaggingPriority int64 `json:"taggingPriority"` +} + +var _ json.Unmarshaler = &TaggingCriteria{} + +func (s *TaggingCriteria) UnmarshalJSON(bytes []byte) error { + type alias TaggingCriteria + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into TaggingCriteria: %+v", err) + } + + s.IsDefault = decoded.IsDefault + s.TagInfo = decoded.TagInfo + s.TaggingPriority = decoded.TaggingPriority + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling TaggingCriteria into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["criteria"]; ok { + var listTemp []json.RawMessage + if err := json.Unmarshal(v, &listTemp); err != nil { + return fmt.Errorf("unmarshaling Criteria into list []json.RawMessage: %+v", err) + } + + output := make([]BackupCriteria, 0) + for i, val := range listTemp { + impl, err := unmarshalBackupCriteriaImplementation(val) + if err != nil { + return fmt.Errorf("unmarshaling index %d field 'Criteria' for 'TaggingCriteria': %+v", i, err) + } + output = append(output, impl) + } + s.Criteria = &output + } + return nil +} diff --git a/resource-manager/dataprotection/2023-11-01/backuppolicies/model_targetcopysetting.go b/resource-manager/dataprotection/2023-11-01/backuppolicies/model_targetcopysetting.go new file mode 100644 index 00000000000..2c3e72d496e --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backuppolicies/model_targetcopysetting.go @@ -0,0 +1,40 @@ +package backuppolicies + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TargetCopySetting struct { + CopyAfter CopyOption `json:"copyAfter"` + DataStore DataStoreInfoBase `json:"dataStore"` +} + +var _ json.Unmarshaler = &TargetCopySetting{} + +func (s *TargetCopySetting) UnmarshalJSON(bytes []byte) error { + type alias TargetCopySetting + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into TargetCopySetting: %+v", err) + } + + s.DataStore = decoded.DataStore + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling TargetCopySetting into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["copyAfter"]; ok { + impl, err := unmarshalCopyOptionImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'CopyAfter' for 'TargetCopySetting': %+v", err) + } + s.CopyAfter = impl + } + return nil +} diff --git a/resource-manager/dataprotection/2023-11-01/backuppolicies/model_triggercontext.go b/resource-manager/dataprotection/2023-11-01/backuppolicies/model_triggercontext.go new file mode 100644 index 00000000000..866643b9b21 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backuppolicies/model_triggercontext.go @@ -0,0 +1,61 @@ +package backuppolicies + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TriggerContext interface { +} + +// RawTriggerContextImpl is returned when the Discriminated Value +// doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawTriggerContextImpl struct { + Type string + Values map[string]interface{} +} + +func unmarshalTriggerContextImplementation(input []byte) (TriggerContext, error) { + if input == nil { + return nil, nil + } + + var temp map[string]interface{} + if err := json.Unmarshal(input, &temp); err != nil { + return nil, fmt.Errorf("unmarshaling TriggerContext into map[string]interface: %+v", err) + } + + value, ok := temp["objectType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "AdhocBasedTriggerContext") { + var out AdhocBasedTriggerContext + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AdhocBasedTriggerContext: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "ScheduleBasedTriggerContext") { + var out ScheduleBasedTriggerContext + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into ScheduleBasedTriggerContext: %+v", err) + } + return out, nil + } + + out := RawTriggerContextImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/dataprotection/2023-11-01/backuppolicies/predicates.go b/resource-manager/dataprotection/2023-11-01/backuppolicies/predicates.go new file mode 100644 index 00000000000..e53bb0c1ed4 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backuppolicies/predicates.go @@ -0,0 +1,27 @@ +package backuppolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BaseBackupPolicyResourceOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p BaseBackupPolicyResourceOperationPredicate) Matches(input BaseBackupPolicyResource) 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/dataprotection/2023-11-01/backuppolicies/version.go b/resource-manager/dataprotection/2023-11-01/backuppolicies/version.go new file mode 100644 index 00000000000..5bd30b89694 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backuppolicies/version.go @@ -0,0 +1,12 @@ +package backuppolicies + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-11-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/backuppolicies/%s", defaultApiVersion) +} diff --git a/resource-manager/dataprotection/2023-11-01/backupvaults/README.md b/resource-manager/dataprotection/2023-11-01/backupvaults/README.md new file mode 100644 index 00000000000..0c43353a2d9 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupvaults/README.md @@ -0,0 +1,137 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2023-11-01/backupvaults` Documentation + +The `backupvaults` SDK allows for interaction with the Azure Resource Manager Service `dataprotection` (API Version `2023-11-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2023-11-01/backupvaults" +``` + + +### Client Initialization + +```go +client := backupvaults.NewBackupVaultsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `BackupVaultsClient.CheckNameAvailability` + +```go +ctx := context.TODO() +id := backupvaults.NewProviderLocationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationValue") + +payload := backupvaults.CheckNameAvailabilityRequest{ + // ... +} + + +read, err := client.CheckNameAvailability(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `BackupVaultsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := backupvaults.NewBackupVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultValue") + +payload := backupvaults.BackupVaultResource{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `BackupVaultsClient.Delete` + +```go +ctx := context.TODO() +id := backupvaults.NewBackupVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `BackupVaultsClient.Get` + +```go +ctx := context.TODO() +id := backupvaults.NewBackupVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultValue") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `BackupVaultsClient.GetInResourceGroup` + +```go +ctx := context.TODO() +id := backupvaults.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +// alternatively `client.GetInResourceGroup(ctx, id)` can be used to do batched pagination +items, err := client.GetInResourceGroupComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `BackupVaultsClient.GetInSubscription` + +```go +ctx := context.TODO() +id := backupvaults.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.GetInSubscription(ctx, id)` can be used to do batched pagination +items, err := client.GetInSubscriptionComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `BackupVaultsClient.Update` + +```go +ctx := context.TODO() +id := backupvaults.NewBackupVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultValue") + +payload := backupvaults.PatchResourceRequestInput{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/dataprotection/2023-11-01/backupvaults/client.go b/resource-manager/dataprotection/2023-11-01/backupvaults/client.go new file mode 100644 index 00000000000..7a4dd932170 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupvaults/client.go @@ -0,0 +1,26 @@ +package backupvaults + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackupVaultsClient struct { + Client *resourcemanager.Client +} + +func NewBackupVaultsClientWithBaseURI(sdkApi sdkEnv.Api) (*BackupVaultsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "backupvaults", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating BackupVaultsClient: %+v", err) + } + + return &BackupVaultsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/dataprotection/2023-11-01/backupvaults/constants.go b/resource-manager/dataprotection/2023-11-01/backupvaults/constants.go new file mode 100644 index 00000000000..87272e92a79 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupvaults/constants.go @@ -0,0 +1,477 @@ +package backupvaults + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AlertsState string + +const ( + AlertsStateDisabled AlertsState = "Disabled" + AlertsStateEnabled AlertsState = "Enabled" +) + +func PossibleValuesForAlertsState() []string { + return []string{ + string(AlertsStateDisabled), + string(AlertsStateEnabled), + } +} + +func (s *AlertsState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertsState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAlertsState(input string) (*AlertsState, error) { + vals := map[string]AlertsState{ + "disabled": AlertsStateDisabled, + "enabled": AlertsStateEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AlertsState(input) + return &out, nil +} + +type CrossRegionRestoreState string + +const ( + CrossRegionRestoreStateDisabled CrossRegionRestoreState = "Disabled" + CrossRegionRestoreStateEnabled CrossRegionRestoreState = "Enabled" +) + +func PossibleValuesForCrossRegionRestoreState() []string { + return []string{ + string(CrossRegionRestoreStateDisabled), + string(CrossRegionRestoreStateEnabled), + } +} + +func (s *CrossRegionRestoreState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCrossRegionRestoreState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCrossRegionRestoreState(input string) (*CrossRegionRestoreState, error) { + vals := map[string]CrossRegionRestoreState{ + "disabled": CrossRegionRestoreStateDisabled, + "enabled": CrossRegionRestoreStateEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CrossRegionRestoreState(input) + return &out, nil +} + +type CrossSubscriptionRestoreState string + +const ( + CrossSubscriptionRestoreStateDisabled CrossSubscriptionRestoreState = "Disabled" + CrossSubscriptionRestoreStateEnabled CrossSubscriptionRestoreState = "Enabled" + CrossSubscriptionRestoreStatePermanentlyDisabled CrossSubscriptionRestoreState = "PermanentlyDisabled" +) + +func PossibleValuesForCrossSubscriptionRestoreState() []string { + return []string{ + string(CrossSubscriptionRestoreStateDisabled), + string(CrossSubscriptionRestoreStateEnabled), + string(CrossSubscriptionRestoreStatePermanentlyDisabled), + } +} + +func (s *CrossSubscriptionRestoreState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCrossSubscriptionRestoreState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCrossSubscriptionRestoreState(input string) (*CrossSubscriptionRestoreState, error) { + vals := map[string]CrossSubscriptionRestoreState{ + "disabled": CrossSubscriptionRestoreStateDisabled, + "enabled": CrossSubscriptionRestoreStateEnabled, + "permanentlydisabled": CrossSubscriptionRestoreStatePermanentlyDisabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CrossSubscriptionRestoreState(input) + return &out, nil +} + +type ImmutabilityState string + +const ( + ImmutabilityStateDisabled ImmutabilityState = "Disabled" + ImmutabilityStateLocked ImmutabilityState = "Locked" + ImmutabilityStateUnlocked ImmutabilityState = "Unlocked" +) + +func PossibleValuesForImmutabilityState() []string { + return []string{ + string(ImmutabilityStateDisabled), + string(ImmutabilityStateLocked), + string(ImmutabilityStateUnlocked), + } +} + +func (s *ImmutabilityState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseImmutabilityState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseImmutabilityState(input string) (*ImmutabilityState, error) { + vals := map[string]ImmutabilityState{ + "disabled": ImmutabilityStateDisabled, + "locked": ImmutabilityStateLocked, + "unlocked": ImmutabilityStateUnlocked, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ImmutabilityState(input) + return &out, nil +} + +type ProvisioningState string + +const ( + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateProvisioning ProvisioningState = "Provisioning" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateUnknown ProvisioningState = "Unknown" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateFailed), + string(ProvisioningStateProvisioning), + string(ProvisioningStateSucceeded), + string(ProvisioningStateUnknown), + string(ProvisioningStateUpdating), + } +} + +func (s *ProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "failed": ProvisioningStateFailed, + "provisioning": ProvisioningStateProvisioning, + "succeeded": ProvisioningStateSucceeded, + "unknown": ProvisioningStateUnknown, + "updating": ProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProvisioningState(input) + return &out, nil +} + +type ResourceMoveState string + +const ( + ResourceMoveStateCommitFailed ResourceMoveState = "CommitFailed" + ResourceMoveStateCommitTimedout ResourceMoveState = "CommitTimedout" + ResourceMoveStateCriticalFailure ResourceMoveState = "CriticalFailure" + ResourceMoveStateFailed ResourceMoveState = "Failed" + ResourceMoveStateInProgress ResourceMoveState = "InProgress" + ResourceMoveStateMoveSucceeded ResourceMoveState = "MoveSucceeded" + ResourceMoveStatePartialSuccess ResourceMoveState = "PartialSuccess" + ResourceMoveStatePrepareFailed ResourceMoveState = "PrepareFailed" + ResourceMoveStatePrepareTimedout ResourceMoveState = "PrepareTimedout" + ResourceMoveStateUnknown ResourceMoveState = "Unknown" +) + +func PossibleValuesForResourceMoveState() []string { + return []string{ + string(ResourceMoveStateCommitFailed), + string(ResourceMoveStateCommitTimedout), + string(ResourceMoveStateCriticalFailure), + string(ResourceMoveStateFailed), + string(ResourceMoveStateInProgress), + string(ResourceMoveStateMoveSucceeded), + string(ResourceMoveStatePartialSuccess), + string(ResourceMoveStatePrepareFailed), + string(ResourceMoveStatePrepareTimedout), + string(ResourceMoveStateUnknown), + } +} + +func (s *ResourceMoveState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseResourceMoveState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseResourceMoveState(input string) (*ResourceMoveState, error) { + vals := map[string]ResourceMoveState{ + "commitfailed": ResourceMoveStateCommitFailed, + "committimedout": ResourceMoveStateCommitTimedout, + "criticalfailure": ResourceMoveStateCriticalFailure, + "failed": ResourceMoveStateFailed, + "inprogress": ResourceMoveStateInProgress, + "movesucceeded": ResourceMoveStateMoveSucceeded, + "partialsuccess": ResourceMoveStatePartialSuccess, + "preparefailed": ResourceMoveStatePrepareFailed, + "preparetimedout": ResourceMoveStatePrepareTimedout, + "unknown": ResourceMoveStateUnknown, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ResourceMoveState(input) + return &out, nil +} + +type SecureScoreLevel string + +const ( + SecureScoreLevelAdequate SecureScoreLevel = "Adequate" + SecureScoreLevelMaximum SecureScoreLevel = "Maximum" + SecureScoreLevelMinimum SecureScoreLevel = "Minimum" + SecureScoreLevelNone SecureScoreLevel = "None" + SecureScoreLevelNotSupported SecureScoreLevel = "NotSupported" +) + +func PossibleValuesForSecureScoreLevel() []string { + return []string{ + string(SecureScoreLevelAdequate), + string(SecureScoreLevelMaximum), + string(SecureScoreLevelMinimum), + string(SecureScoreLevelNone), + string(SecureScoreLevelNotSupported), + } +} + +func (s *SecureScoreLevel) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSecureScoreLevel(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSecureScoreLevel(input string) (*SecureScoreLevel, error) { + vals := map[string]SecureScoreLevel{ + "adequate": SecureScoreLevelAdequate, + "maximum": SecureScoreLevelMaximum, + "minimum": SecureScoreLevelMinimum, + "none": SecureScoreLevelNone, + "notsupported": SecureScoreLevelNotSupported, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SecureScoreLevel(input) + return &out, nil +} + +type SoftDeleteState string + +const ( + SoftDeleteStateAlwaysOn SoftDeleteState = "AlwaysOn" + SoftDeleteStateOff SoftDeleteState = "Off" + SoftDeleteStateOn SoftDeleteState = "On" +) + +func PossibleValuesForSoftDeleteState() []string { + return []string{ + string(SoftDeleteStateAlwaysOn), + string(SoftDeleteStateOff), + string(SoftDeleteStateOn), + } +} + +func (s *SoftDeleteState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSoftDeleteState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSoftDeleteState(input string) (*SoftDeleteState, error) { + vals := map[string]SoftDeleteState{ + "alwayson": SoftDeleteStateAlwaysOn, + "off": SoftDeleteStateOff, + "on": SoftDeleteStateOn, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SoftDeleteState(input) + return &out, nil +} + +type StorageSettingStoreTypes string + +const ( + StorageSettingStoreTypesArchiveStore StorageSettingStoreTypes = "ArchiveStore" + StorageSettingStoreTypesOperationalStore StorageSettingStoreTypes = "OperationalStore" + StorageSettingStoreTypesVaultStore StorageSettingStoreTypes = "VaultStore" +) + +func PossibleValuesForStorageSettingStoreTypes() []string { + return []string{ + string(StorageSettingStoreTypesArchiveStore), + string(StorageSettingStoreTypesOperationalStore), + string(StorageSettingStoreTypesVaultStore), + } +} + +func (s *StorageSettingStoreTypes) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseStorageSettingStoreTypes(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseStorageSettingStoreTypes(input string) (*StorageSettingStoreTypes, error) { + vals := map[string]StorageSettingStoreTypes{ + "archivestore": StorageSettingStoreTypesArchiveStore, + "operationalstore": StorageSettingStoreTypesOperationalStore, + "vaultstore": StorageSettingStoreTypesVaultStore, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := StorageSettingStoreTypes(input) + return &out, nil +} + +type StorageSettingTypes string + +const ( + StorageSettingTypesGeoRedundant StorageSettingTypes = "GeoRedundant" + StorageSettingTypesLocallyRedundant StorageSettingTypes = "LocallyRedundant" + StorageSettingTypesZoneRedundant StorageSettingTypes = "ZoneRedundant" +) + +func PossibleValuesForStorageSettingTypes() []string { + return []string{ + string(StorageSettingTypesGeoRedundant), + string(StorageSettingTypesLocallyRedundant), + string(StorageSettingTypesZoneRedundant), + } +} + +func (s *StorageSettingTypes) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseStorageSettingTypes(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseStorageSettingTypes(input string) (*StorageSettingTypes, error) { + vals := map[string]StorageSettingTypes{ + "georedundant": StorageSettingTypesGeoRedundant, + "locallyredundant": StorageSettingTypesLocallyRedundant, + "zoneredundant": StorageSettingTypesZoneRedundant, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := StorageSettingTypes(input) + return &out, nil +} diff --git a/resource-manager/dataprotection/2023-11-01/backupvaults/id_backupvault.go b/resource-manager/dataprotection/2023-11-01/backupvaults/id_backupvault.go new file mode 100644 index 00000000000..b2cb37557bf --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupvaults/id_backupvault.go @@ -0,0 +1,125 @@ +package backupvaults + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = BackupVaultId{} + +// BackupVaultId is a struct representing the Resource ID for a Backup Vault +type BackupVaultId struct { + SubscriptionId string + ResourceGroupName string + BackupVaultName string +} + +// NewBackupVaultID returns a new BackupVaultId struct +func NewBackupVaultID(subscriptionId string, resourceGroupName string, backupVaultName string) BackupVaultId { + return BackupVaultId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + BackupVaultName: backupVaultName, + } +} + +// ParseBackupVaultID parses 'input' into a BackupVaultId +func ParseBackupVaultID(input string) (*BackupVaultId, error) { + parser := resourceids.NewParserFromResourceIdType(BackupVaultId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BackupVaultId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseBackupVaultIDInsensitively parses 'input' case-insensitively into a BackupVaultId +// note: this method should only be used for API response data and not user input +func ParseBackupVaultIDInsensitively(input string) (*BackupVaultId, error) { + parser := resourceids.NewParserFromResourceIdType(BackupVaultId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BackupVaultId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *BackupVaultId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.BackupVaultName, ok = input.Parsed["backupVaultName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "backupVaultName", input) + } + + return nil +} + +// ValidateBackupVaultID checks that 'input' can be parsed as a Backup Vault ID +func ValidateBackupVaultID(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 := ParseBackupVaultID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Backup Vault ID +func (id BackupVaultId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DataProtection/backupVaults/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.BackupVaultName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Backup Vault ID +func (id BackupVaultId) 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("staticMicrosoftDataProtection", "Microsoft.DataProtection", "Microsoft.DataProtection"), + resourceids.StaticSegment("staticBackupVaults", "backupVaults", "backupVaults"), + resourceids.UserSpecifiedSegment("backupVaultName", "backupVaultValue"), + } +} + +// String returns a human-readable description of this Backup Vault ID +func (id BackupVaultId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Backup Vault Name: %q", id.BackupVaultName), + } + return fmt.Sprintf("Backup Vault (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/dataprotection/2023-11-01/backupvaults/id_backupvault_test.go b/resource-manager/dataprotection/2023-11-01/backupvaults/id_backupvault_test.go new file mode 100644 index 00000000000..8aa1b6b6d5d --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupvaults/id_backupvault_test.go @@ -0,0 +1,282 @@ +package backupvaults + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = BackupVaultId{} + +func TestNewBackupVaultID(t *testing.T) { + id := NewBackupVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultValue") + + 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.BackupVaultName != "backupVaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'BackupVaultName'", id.BackupVaultName, "backupVaultValue") + } +} + +func TestFormatBackupVaultID(t *testing.T) { + actual := NewBackupVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseBackupVaultID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BackupVaultId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue", + Expected: &BackupVaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + BackupVaultName: "backupVaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBackupVaultID(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.BackupVaultName != v.Expected.BackupVaultName { + t.Fatalf("Expected %q but got %q for BackupVaultName", v.Expected.BackupVaultName, actual.BackupVaultName) + } + + } +} + +func TestParseBackupVaultIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BackupVaultId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue", + Expected: &BackupVaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + BackupVaultName: "backupVaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtVaLuE", + Expected: &BackupVaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + BackupVaultName: "bAcKuPvAuLtVaLuE", + }, + }, + { + // 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.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBackupVaultIDInsensitively(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.BackupVaultName != v.Expected.BackupVaultName { + t.Fatalf("Expected %q but got %q for BackupVaultName", v.Expected.BackupVaultName, actual.BackupVaultName) + } + + } +} + +func TestSegmentsForBackupVaultId(t *testing.T) { + segments := BackupVaultId{}.Segments() + if len(segments) == 0 { + t.Fatalf("BackupVaultId 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/dataprotection/2023-11-01/backupvaults/id_providerlocation.go b/resource-manager/dataprotection/2023-11-01/backupvaults/id_providerlocation.go new file mode 100644 index 00000000000..ade2d54f0fc --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupvaults/id_providerlocation.go @@ -0,0 +1,125 @@ +package backupvaults + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = ProviderLocationId{} + +// ProviderLocationId is a struct representing the Resource ID for a Provider Location +type ProviderLocationId struct { + SubscriptionId string + ResourceGroupName string + LocationName string +} + +// NewProviderLocationID returns a new ProviderLocationId struct +func NewProviderLocationID(subscriptionId string, resourceGroupName string, locationName string) ProviderLocationId { + return ProviderLocationId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + LocationName: locationName, + } +} + +// ParseProviderLocationID parses 'input' into a ProviderLocationId +func ParseProviderLocationID(input string) (*ProviderLocationId, error) { + parser := resourceids.NewParserFromResourceIdType(ProviderLocationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProviderLocationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseProviderLocationIDInsensitively parses 'input' case-insensitively into a ProviderLocationId +// note: this method should only be used for API response data and not user input +func ParseProviderLocationIDInsensitively(input string) (*ProviderLocationId, error) { + parser := resourceids.NewParserFromResourceIdType(ProviderLocationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProviderLocationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ProviderLocationId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.LocationName, ok = input.Parsed["locationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "locationName", input) + } + + return nil +} + +// ValidateProviderLocationID checks that 'input' can be parsed as a Provider Location ID +func ValidateProviderLocationID(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 := ParseProviderLocationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Provider Location ID +func (id ProviderLocationId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DataProtection/locations/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.LocationName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Provider Location ID +func (id ProviderLocationId) 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("staticMicrosoftDataProtection", "Microsoft.DataProtection", "Microsoft.DataProtection"), + resourceids.StaticSegment("staticLocations", "locations", "locations"), + resourceids.UserSpecifiedSegment("locationName", "locationValue"), + } +} + +// String returns a human-readable description of this Provider Location ID +func (id ProviderLocationId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Location Name: %q", id.LocationName), + } + return fmt.Sprintf("Provider Location (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/dataprotection/2023-11-01/backupvaults/id_providerlocation_test.go b/resource-manager/dataprotection/2023-11-01/backupvaults/id_providerlocation_test.go new file mode 100644 index 00000000000..a60bb8a8ec9 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupvaults/id_providerlocation_test.go @@ -0,0 +1,282 @@ +package backupvaults + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = ProviderLocationId{} + +func TestNewProviderLocationID(t *testing.T) { + id := NewProviderLocationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.LocationName != "locationValue" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationValue") + } +} + +func TestFormatProviderLocationID(t *testing.T) { + actual := NewProviderLocationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/locations/locationValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProviderLocationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProviderLocationId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/locations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/locations/locationValue", + Expected: &ProviderLocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/locations/locationValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProviderLocationID(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.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + } +} + +func TestParseProviderLocationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProviderLocationId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/lOcAtIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/locations/locationValue", + Expected: &ProviderLocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/locations/locationValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/lOcAtIoNs/lOcAtIoNvAlUe", + Expected: &ProviderLocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + LocationName: "lOcAtIoNvAlUe", + }, + }, + { + // 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.dAtApRoTeCtIoN/lOcAtIoNs/lOcAtIoNvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProviderLocationIDInsensitively(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.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + } +} + +func TestSegmentsForProviderLocationId(t *testing.T) { + segments := ProviderLocationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ProviderLocationId 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/dataprotection/2023-11-01/backupvaults/method_checknameavailability.go b/resource-manager/dataprotection/2023-11-01/backupvaults/method_checknameavailability.go new file mode 100644 index 00000000000..2266afec7d2 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupvaults/method_checknameavailability.go @@ -0,0 +1,56 @@ +package backupvaults + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CheckNameAvailabilityOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *CheckNameAvailabilityResult +} + +// CheckNameAvailability ... +func (c BackupVaultsClient) CheckNameAvailability(ctx context.Context, id ProviderLocationId, input CheckNameAvailabilityRequest) (result CheckNameAvailabilityOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/checkNameAvailability", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/dataprotection/2023-11-01/backupvaults/method_createorupdate.go b/resource-manager/dataprotection/2023-11-01/backupvaults/method_createorupdate.go new file mode 100644 index 00000000000..5dad69e8765 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupvaults/method_createorupdate.go @@ -0,0 +1,74 @@ +package backupvaults + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// CreateOrUpdate ... +func (c BackupVaultsClient) CreateOrUpdate(ctx context.Context, id BackupVaultId, input BackupVaultResource) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c BackupVaultsClient) CreateOrUpdateThenPoll(ctx context.Context, id BackupVaultId, input BackupVaultResource) error { + result, err := c.CreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing CreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after CreateOrUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/dataprotection/2023-11-01/backupvaults/method_delete.go b/resource-manager/dataprotection/2023-11-01/backupvaults/method_delete.go new file mode 100644 index 00000000000..6899d5db814 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupvaults/method_delete.go @@ -0,0 +1,71 @@ +package backupvaults + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c BackupVaultsClient) Delete(ctx context.Context, id BackupVaultId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c BackupVaultsClient) DeleteThenPoll(ctx context.Context, id BackupVaultId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} diff --git a/resource-manager/dataprotection/2023-11-01/backupvaults/method_get.go b/resource-manager/dataprotection/2023-11-01/backupvaults/method_get.go new file mode 100644 index 00000000000..b0f7c3278a1 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupvaults/method_get.go @@ -0,0 +1,51 @@ +package backupvaults + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *BackupVaultResource +} + +// Get ... +func (c BackupVaultsClient) Get(ctx context.Context, id BackupVaultId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/dataprotection/2023-11-01/backupvaults/method_getinresourcegroup.go b/resource-manager/dataprotection/2023-11-01/backupvaults/method_getinresourcegroup.go new file mode 100644 index 00000000000..5d21b6c4e53 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupvaults/method_getinresourcegroup.go @@ -0,0 +1,90 @@ +package backupvaults + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetInResourceGroupOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]BackupVaultResource +} + +type GetInResourceGroupCompleteResult struct { + Items []BackupVaultResource +} + +// GetInResourceGroup ... +func (c BackupVaultsClient) GetInResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (result GetInResourceGroupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.DataProtection/backupVaults", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]BackupVaultResource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// GetInResourceGroupComplete retrieves all the results into a single object +func (c BackupVaultsClient) GetInResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (GetInResourceGroupCompleteResult, error) { + return c.GetInResourceGroupCompleteMatchingPredicate(ctx, id, BackupVaultResourceOperationPredicate{}) +} + +// GetInResourceGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c BackupVaultsClient) GetInResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate BackupVaultResourceOperationPredicate) (result GetInResourceGroupCompleteResult, err error) { + items := make([]BackupVaultResource, 0) + + resp, err := c.GetInResourceGroup(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = GetInResourceGroupCompleteResult{ + Items: items, + } + return +} diff --git a/resource-manager/dataprotection/2023-11-01/backupvaults/method_getinsubscription.go b/resource-manager/dataprotection/2023-11-01/backupvaults/method_getinsubscription.go new file mode 100644 index 00000000000..bf31f1422d0 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupvaults/method_getinsubscription.go @@ -0,0 +1,90 @@ +package backupvaults + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetInSubscriptionOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]BackupVaultResource +} + +type GetInSubscriptionCompleteResult struct { + Items []BackupVaultResource +} + +// GetInSubscription ... +func (c BackupVaultsClient) GetInSubscription(ctx context.Context, id commonids.SubscriptionId) (result GetInSubscriptionOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.DataProtection/backupVaults", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]BackupVaultResource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// GetInSubscriptionComplete retrieves all the results into a single object +func (c BackupVaultsClient) GetInSubscriptionComplete(ctx context.Context, id commonids.SubscriptionId) (GetInSubscriptionCompleteResult, error) { + return c.GetInSubscriptionCompleteMatchingPredicate(ctx, id, BackupVaultResourceOperationPredicate{}) +} + +// GetInSubscriptionCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c BackupVaultsClient) GetInSubscriptionCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate BackupVaultResourceOperationPredicate) (result GetInSubscriptionCompleteResult, err error) { + items := make([]BackupVaultResource, 0) + + resp, err := c.GetInSubscription(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = GetInSubscriptionCompleteResult{ + Items: items, + } + return +} diff --git a/resource-manager/dataprotection/2023-11-01/backupvaults/method_update.go b/resource-manager/dataprotection/2023-11-01/backupvaults/method_update.go new file mode 100644 index 00000000000..566927a091b --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupvaults/method_update.go @@ -0,0 +1,74 @@ +package backupvaults + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Update ... +func (c BackupVaultsClient) Update(ctx context.Context, id BackupVaultId, input PatchResourceRequestInput) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// UpdateThenPoll performs Update then polls until it's completed +func (c BackupVaultsClient) UpdateThenPoll(ctx context.Context, id BackupVaultId, input PatchResourceRequestInput) error { + result, err := c.Update(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Update: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Update: %+v", err) + } + + return nil +} diff --git a/resource-manager/dataprotection/2023-11-01/backupvaults/model_azuremonitoralertsettings.go b/resource-manager/dataprotection/2023-11-01/backupvaults/model_azuremonitoralertsettings.go new file mode 100644 index 00000000000..8abdec3ec1b --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupvaults/model_azuremonitoralertsettings.go @@ -0,0 +1,8 @@ +package backupvaults + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureMonitorAlertSettings struct { + AlertsForAllJobFailures *AlertsState `json:"alertsForAllJobFailures,omitempty"` +} diff --git a/resource-manager/dataprotection/2023-11-01/backupvaults/model_backupvault.go b/resource-manager/dataprotection/2023-11-01/backupvaults/model_backupvault.go new file mode 100644 index 00000000000..1fe98bc9cf5 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupvaults/model_backupvault.go @@ -0,0 +1,17 @@ +package backupvaults + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackupVault struct { + FeatureSettings *FeatureSettings `json:"featureSettings,omitempty"` + IsVaultProtectedByResourceGuard *bool `json:"isVaultProtectedByResourceGuard,omitempty"` + MonitoringSettings *MonitoringSettings `json:"monitoringSettings,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + ReplicatedRegions *[]string `json:"replicatedRegions,omitempty"` + ResourceMoveDetails *ResourceMoveDetails `json:"resourceMoveDetails,omitempty"` + ResourceMoveState *ResourceMoveState `json:"resourceMoveState,omitempty"` + SecureScore *SecureScoreLevel `json:"secureScore,omitempty"` + SecuritySettings *SecuritySettings `json:"securitySettings,omitempty"` + StorageSettings []StorageSetting `json:"storageSettings"` +} diff --git a/resource-manager/dataprotection/2023-11-01/backupvaults/model_backupvaultresource.go b/resource-manager/dataprotection/2023-11-01/backupvaults/model_backupvaultresource.go new file mode 100644 index 00000000000..978197ca4e3 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupvaults/model_backupvaultresource.go @@ -0,0 +1,20 @@ +package backupvaults + +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 BackupVaultResource struct { + ETag *string `json:"eTag,omitempty"` + Id *string `json:"id,omitempty"` + Identity *DppIdentityDetails `json:"identity,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties BackupVault `json:"properties"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/dataprotection/2023-11-01/backupvaults/model_checknameavailabilityrequest.go b/resource-manager/dataprotection/2023-11-01/backupvaults/model_checknameavailabilityrequest.go new file mode 100644 index 00000000000..bb78afc83b2 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupvaults/model_checknameavailabilityrequest.go @@ -0,0 +1,9 @@ +package backupvaults + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CheckNameAvailabilityRequest struct { + Name *string `json:"name,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/dataprotection/2023-11-01/backupvaults/model_checknameavailabilityresult.go b/resource-manager/dataprotection/2023-11-01/backupvaults/model_checknameavailabilityresult.go new file mode 100644 index 00000000000..86c51891313 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupvaults/model_checknameavailabilityresult.go @@ -0,0 +1,10 @@ +package backupvaults + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CheckNameAvailabilityResult struct { + Message *string `json:"message,omitempty"` + NameAvailable *bool `json:"nameAvailable,omitempty"` + Reason *string `json:"reason,omitempty"` +} diff --git a/resource-manager/dataprotection/2023-11-01/backupvaults/model_crossregionrestoresettings.go b/resource-manager/dataprotection/2023-11-01/backupvaults/model_crossregionrestoresettings.go new file mode 100644 index 00000000000..71637991bdd --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupvaults/model_crossregionrestoresettings.go @@ -0,0 +1,8 @@ +package backupvaults + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CrossRegionRestoreSettings struct { + State *CrossRegionRestoreState `json:"state,omitempty"` +} diff --git a/resource-manager/dataprotection/2023-11-01/backupvaults/model_crosssubscriptionrestoresettings.go b/resource-manager/dataprotection/2023-11-01/backupvaults/model_crosssubscriptionrestoresettings.go new file mode 100644 index 00000000000..0e8ba93d082 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupvaults/model_crosssubscriptionrestoresettings.go @@ -0,0 +1,8 @@ +package backupvaults + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CrossSubscriptionRestoreSettings struct { + State *CrossSubscriptionRestoreState `json:"state,omitempty"` +} diff --git a/resource-manager/dataprotection/2023-11-01/backupvaults/model_dppidentitydetails.go b/resource-manager/dataprotection/2023-11-01/backupvaults/model_dppidentitydetails.go new file mode 100644 index 00000000000..88294a548cd --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupvaults/model_dppidentitydetails.go @@ -0,0 +1,11 @@ +package backupvaults + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DppIdentityDetails struct { + PrincipalId *string `json:"principalId,omitempty"` + TenantId *string `json:"tenantId,omitempty"` + Type *string `json:"type,omitempty"` + UserAssignedIdentities *map[string]UserAssignedIdentity `json:"userAssignedIdentities,omitempty"` +} diff --git a/resource-manager/dataprotection/2023-11-01/backupvaults/model_featuresettings.go b/resource-manager/dataprotection/2023-11-01/backupvaults/model_featuresettings.go new file mode 100644 index 00000000000..c8981f793c3 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupvaults/model_featuresettings.go @@ -0,0 +1,9 @@ +package backupvaults + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FeatureSettings struct { + CrossRegionRestoreSettings *CrossRegionRestoreSettings `json:"crossRegionRestoreSettings,omitempty"` + CrossSubscriptionRestoreSettings *CrossSubscriptionRestoreSettings `json:"crossSubscriptionRestoreSettings,omitempty"` +} diff --git a/resource-manager/dataprotection/2023-11-01/backupvaults/model_immutabilitysettings.go b/resource-manager/dataprotection/2023-11-01/backupvaults/model_immutabilitysettings.go new file mode 100644 index 00000000000..1e8bb471362 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupvaults/model_immutabilitysettings.go @@ -0,0 +1,8 @@ +package backupvaults + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ImmutabilitySettings struct { + State *ImmutabilityState `json:"state,omitempty"` +} diff --git a/resource-manager/dataprotection/2023-11-01/backupvaults/model_monitoringsettings.go b/resource-manager/dataprotection/2023-11-01/backupvaults/model_monitoringsettings.go new file mode 100644 index 00000000000..de0fa26a601 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupvaults/model_monitoringsettings.go @@ -0,0 +1,8 @@ +package backupvaults + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MonitoringSettings struct { + AzureMonitorAlertSettings *AzureMonitorAlertSettings `json:"azureMonitorAlertSettings,omitempty"` +} diff --git a/resource-manager/dataprotection/2023-11-01/backupvaults/model_patchbackupvaultinput.go b/resource-manager/dataprotection/2023-11-01/backupvaults/model_patchbackupvaultinput.go new file mode 100644 index 00000000000..217d3bf07f6 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupvaults/model_patchbackupvaultinput.go @@ -0,0 +1,10 @@ +package backupvaults + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PatchBackupVaultInput struct { + FeatureSettings *FeatureSettings `json:"featureSettings,omitempty"` + MonitoringSettings *MonitoringSettings `json:"monitoringSettings,omitempty"` + SecuritySettings *SecuritySettings `json:"securitySettings,omitempty"` +} diff --git a/resource-manager/dataprotection/2023-11-01/backupvaults/model_patchresourcerequestinput.go b/resource-manager/dataprotection/2023-11-01/backupvaults/model_patchresourcerequestinput.go new file mode 100644 index 00000000000..09683e7a1d0 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupvaults/model_patchresourcerequestinput.go @@ -0,0 +1,10 @@ +package backupvaults + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PatchResourceRequestInput struct { + Identity *DppIdentityDetails `json:"identity,omitempty"` + Properties *PatchBackupVaultInput `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/dataprotection/2023-11-01/backupvaults/model_resourcemovedetails.go b/resource-manager/dataprotection/2023-11-01/backupvaults/model_resourcemovedetails.go new file mode 100644 index 00000000000..dc459fff005 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupvaults/model_resourcemovedetails.go @@ -0,0 +1,12 @@ +package backupvaults + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceMoveDetails struct { + CompletionTimeUtc *string `json:"completionTimeUtc,omitempty"` + OperationId *string `json:"operationId,omitempty"` + SourceResourcePath *string `json:"sourceResourcePath,omitempty"` + StartTimeUtc *string `json:"startTimeUtc,omitempty"` + TargetResourcePath *string `json:"targetResourcePath,omitempty"` +} diff --git a/resource-manager/dataprotection/2023-11-01/backupvaults/model_securitysettings.go b/resource-manager/dataprotection/2023-11-01/backupvaults/model_securitysettings.go new file mode 100644 index 00000000000..f16b74e6a44 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupvaults/model_securitysettings.go @@ -0,0 +1,9 @@ +package backupvaults + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SecuritySettings struct { + ImmutabilitySettings *ImmutabilitySettings `json:"immutabilitySettings,omitempty"` + SoftDeleteSettings *SoftDeleteSettings `json:"softDeleteSettings,omitempty"` +} diff --git a/resource-manager/dataprotection/2023-11-01/backupvaults/model_softdeletesettings.go b/resource-manager/dataprotection/2023-11-01/backupvaults/model_softdeletesettings.go new file mode 100644 index 00000000000..903e8180d14 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupvaults/model_softdeletesettings.go @@ -0,0 +1,9 @@ +package backupvaults + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SoftDeleteSettings struct { + RetentionDurationInDays *float64 `json:"retentionDurationInDays,omitempty"` + State *SoftDeleteState `json:"state,omitempty"` +} diff --git a/resource-manager/dataprotection/2023-11-01/backupvaults/model_storagesetting.go b/resource-manager/dataprotection/2023-11-01/backupvaults/model_storagesetting.go new file mode 100644 index 00000000000..6112268872b --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupvaults/model_storagesetting.go @@ -0,0 +1,9 @@ +package backupvaults + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StorageSetting struct { + DatastoreType *StorageSettingStoreTypes `json:"datastoreType,omitempty"` + Type *StorageSettingTypes `json:"type,omitempty"` +} diff --git a/resource-manager/dataprotection/2023-11-01/backupvaults/model_userassignedidentity.go b/resource-manager/dataprotection/2023-11-01/backupvaults/model_userassignedidentity.go new file mode 100644 index 00000000000..25716effc20 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupvaults/model_userassignedidentity.go @@ -0,0 +1,9 @@ +package backupvaults + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UserAssignedIdentity struct { + ClientId *string `json:"clientId,omitempty"` + PrincipalId *string `json:"principalId,omitempty"` +} diff --git a/resource-manager/dataprotection/2023-11-01/backupvaults/predicates.go b/resource-manager/dataprotection/2023-11-01/backupvaults/predicates.go new file mode 100644 index 00000000000..241a550b4d5 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupvaults/predicates.go @@ -0,0 +1,37 @@ +package backupvaults + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackupVaultResourceOperationPredicate struct { + ETag *string + Id *string + Location *string + Name *string + Type *string +} + +func (p BackupVaultResourceOperationPredicate) Matches(input BackupVaultResource) 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.Location != nil && *p.Location != input.Location { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/dataprotection/2023-11-01/backupvaults/version.go b/resource-manager/dataprotection/2023-11-01/backupvaults/version.go new file mode 100644 index 00000000000..742a32aa461 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/backupvaults/version.go @@ -0,0 +1,12 @@ +package backupvaults + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-11-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/backupvaults/%s", defaultApiVersion) +} diff --git a/resource-manager/dataprotection/2023-11-01/client.go b/resource-manager/dataprotection/2023-11-01/client.go new file mode 100644 index 00000000000..96f747115d3 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/client.go @@ -0,0 +1,136 @@ +package v2023_11_01 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2023-11-01/azurebackupjob" + "github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2023-11-01/azurebackupjobs" + "github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2023-11-01/backupinstances" + "github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2023-11-01/backuppolicies" + "github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2023-11-01/backupvaults" + "github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2023-11-01/deletedbackupinstances" + "github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2023-11-01/dppfeaturesupport" + "github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2023-11-01/dppjob" + "github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2023-11-01/dppresourceguardproxies" + "github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2023-11-01/fetchsecondaryrecoverypoints" + "github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2023-11-01/findrestorabletimeranges" + "github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2023-11-01/recoverypoint" + "github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2023-11-01/resourceguards" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +type Client struct { + AzureBackupJob *azurebackupjob.AzureBackupJobClient + AzureBackupJobs *azurebackupjobs.AzureBackupJobsClient + BackupInstances *backupinstances.BackupInstancesClient + BackupPolicies *backuppolicies.BackupPoliciesClient + BackupVaults *backupvaults.BackupVaultsClient + DeletedBackupInstances *deletedbackupinstances.DeletedBackupInstancesClient + DppFeatureSupport *dppfeaturesupport.DppFeatureSupportClient + DppJob *dppjob.DppJobClient + DppResourceGuardProxies *dppresourceguardproxies.DppResourceGuardProxiesClient + FetchSecondaryRecoveryPoints *fetchsecondaryrecoverypoints.FetchSecondaryRecoveryPointsClient + FindRestorableTimeRanges *findrestorabletimeranges.FindRestorableTimeRangesClient + RecoveryPoint *recoverypoint.RecoveryPointClient + ResourceGuards *resourceguards.ResourceGuardsClient +} + +func NewClientWithBaseURI(sdkApi sdkEnv.Api, configureFunc func(c *resourcemanager.Client)) (*Client, error) { + azureBackupJobClient, err := azurebackupjob.NewAzureBackupJobClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building AzureBackupJob client: %+v", err) + } + configureFunc(azureBackupJobClient.Client) + + azureBackupJobsClient, err := azurebackupjobs.NewAzureBackupJobsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building AzureBackupJobs client: %+v", err) + } + configureFunc(azureBackupJobsClient.Client) + + backupInstancesClient, err := backupinstances.NewBackupInstancesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building BackupInstances client: %+v", err) + } + configureFunc(backupInstancesClient.Client) + + backupPoliciesClient, err := backuppolicies.NewBackupPoliciesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building BackupPolicies client: %+v", err) + } + configureFunc(backupPoliciesClient.Client) + + backupVaultsClient, err := backupvaults.NewBackupVaultsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building BackupVaults client: %+v", err) + } + configureFunc(backupVaultsClient.Client) + + deletedBackupInstancesClient, err := deletedbackupinstances.NewDeletedBackupInstancesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building DeletedBackupInstances client: %+v", err) + } + configureFunc(deletedBackupInstancesClient.Client) + + dppFeatureSupportClient, err := dppfeaturesupport.NewDppFeatureSupportClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building DppFeatureSupport client: %+v", err) + } + configureFunc(dppFeatureSupportClient.Client) + + dppJobClient, err := dppjob.NewDppJobClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building DppJob client: %+v", err) + } + configureFunc(dppJobClient.Client) + + dppResourceGuardProxiesClient, err := dppresourceguardproxies.NewDppResourceGuardProxiesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building DppResourceGuardProxies client: %+v", err) + } + configureFunc(dppResourceGuardProxiesClient.Client) + + fetchSecondaryRecoveryPointsClient, err := fetchsecondaryrecoverypoints.NewFetchSecondaryRecoveryPointsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building FetchSecondaryRecoveryPoints client: %+v", err) + } + configureFunc(fetchSecondaryRecoveryPointsClient.Client) + + findRestorableTimeRangesClient, err := findrestorabletimeranges.NewFindRestorableTimeRangesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building FindRestorableTimeRanges client: %+v", err) + } + configureFunc(findRestorableTimeRangesClient.Client) + + recoveryPointClient, err := recoverypoint.NewRecoveryPointClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building RecoveryPoint client: %+v", err) + } + configureFunc(recoveryPointClient.Client) + + resourceGuardsClient, err := resourceguards.NewResourceGuardsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ResourceGuards client: %+v", err) + } + configureFunc(resourceGuardsClient.Client) + + return &Client{ + AzureBackupJob: azureBackupJobClient, + AzureBackupJobs: azureBackupJobsClient, + BackupInstances: backupInstancesClient, + BackupPolicies: backupPoliciesClient, + BackupVaults: backupVaultsClient, + DeletedBackupInstances: deletedBackupInstancesClient, + DppFeatureSupport: dppFeatureSupportClient, + DppJob: dppJobClient, + DppResourceGuardProxies: dppResourceGuardProxiesClient, + FetchSecondaryRecoveryPoints: fetchSecondaryRecoveryPointsClient, + FindRestorableTimeRanges: findRestorableTimeRangesClient, + RecoveryPoint: recoveryPointClient, + ResourceGuards: resourceGuardsClient, + }, nil +} diff --git a/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/README.md b/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/README.md new file mode 100644 index 00000000000..1ff36deee31 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/README.md @@ -0,0 +1,65 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2023-11-01/deletedbackupinstances` Documentation + +The `deletedbackupinstances` SDK allows for interaction with the Azure Resource Manager Service `dataprotection` (API Version `2023-11-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2023-11-01/deletedbackupinstances" +``` + + +### Client Initialization + +```go +client := deletedbackupinstances.NewDeletedBackupInstancesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DeletedBackupInstancesClient.Get` + +```go +ctx := context.TODO() +id := deletedbackupinstances.NewDeletedBackupInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultValue", "deletedBackupInstanceValue") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DeletedBackupInstancesClient.List` + +```go +ctx := context.TODO() +id := deletedbackupinstances.NewBackupVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultValue") + +// alternatively `client.List(ctx, id)` can be used to do batched pagination +items, err := client.ListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `DeletedBackupInstancesClient.Undelete` + +```go +ctx := context.TODO() +id := deletedbackupinstances.NewDeletedBackupInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultValue", "deletedBackupInstanceValue") + +if err := client.UndeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` diff --git a/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/client.go b/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/client.go new file mode 100644 index 00000000000..e70cb344e5d --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/client.go @@ -0,0 +1,26 @@ +package deletedbackupinstances + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeletedBackupInstancesClient struct { + Client *resourcemanager.Client +} + +func NewDeletedBackupInstancesClientWithBaseURI(sdkApi sdkEnv.Api) (*DeletedBackupInstancesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "deletedbackupinstances", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DeletedBackupInstancesClient: %+v", err) + } + + return &DeletedBackupInstancesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/constants.go b/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/constants.go new file mode 100644 index 00000000000..d0a2f7e9313 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/constants.go @@ -0,0 +1,298 @@ +package deletedbackupinstances + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CurrentProtectionState string + +const ( + CurrentProtectionStateBackupSchedulesSuspended CurrentProtectionState = "BackupSchedulesSuspended" + CurrentProtectionStateConfiguringProtection CurrentProtectionState = "ConfiguringProtection" + CurrentProtectionStateConfiguringProtectionFailed CurrentProtectionState = "ConfiguringProtectionFailed" + CurrentProtectionStateInvalid CurrentProtectionState = "Invalid" + CurrentProtectionStateNotProtected CurrentProtectionState = "NotProtected" + CurrentProtectionStateProtectionConfigured CurrentProtectionState = "ProtectionConfigured" + CurrentProtectionStateProtectionError CurrentProtectionState = "ProtectionError" + CurrentProtectionStateProtectionStopped CurrentProtectionState = "ProtectionStopped" + CurrentProtectionStateRetentionSchedulesSuspended CurrentProtectionState = "RetentionSchedulesSuspended" + CurrentProtectionStateSoftDeleted CurrentProtectionState = "SoftDeleted" + CurrentProtectionStateSoftDeleting CurrentProtectionState = "SoftDeleting" + CurrentProtectionStateUpdatingProtection CurrentProtectionState = "UpdatingProtection" +) + +func PossibleValuesForCurrentProtectionState() []string { + return []string{ + string(CurrentProtectionStateBackupSchedulesSuspended), + string(CurrentProtectionStateConfiguringProtection), + string(CurrentProtectionStateConfiguringProtectionFailed), + string(CurrentProtectionStateInvalid), + string(CurrentProtectionStateNotProtected), + string(CurrentProtectionStateProtectionConfigured), + string(CurrentProtectionStateProtectionError), + string(CurrentProtectionStateProtectionStopped), + string(CurrentProtectionStateRetentionSchedulesSuspended), + string(CurrentProtectionStateSoftDeleted), + string(CurrentProtectionStateSoftDeleting), + string(CurrentProtectionStateUpdatingProtection), + } +} + +func (s *CurrentProtectionState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCurrentProtectionState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCurrentProtectionState(input string) (*CurrentProtectionState, error) { + vals := map[string]CurrentProtectionState{ + "backupschedulessuspended": CurrentProtectionStateBackupSchedulesSuspended, + "configuringprotection": CurrentProtectionStateConfiguringProtection, + "configuringprotectionfailed": CurrentProtectionStateConfiguringProtectionFailed, + "invalid": CurrentProtectionStateInvalid, + "notprotected": CurrentProtectionStateNotProtected, + "protectionconfigured": CurrentProtectionStateProtectionConfigured, + "protectionerror": CurrentProtectionStateProtectionError, + "protectionstopped": CurrentProtectionStateProtectionStopped, + "retentionschedulessuspended": CurrentProtectionStateRetentionSchedulesSuspended, + "softdeleted": CurrentProtectionStateSoftDeleted, + "softdeleting": CurrentProtectionStateSoftDeleting, + "updatingprotection": CurrentProtectionStateUpdatingProtection, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CurrentProtectionState(input) + return &out, nil +} + +type DataStoreTypes string + +const ( + DataStoreTypesArchiveStore DataStoreTypes = "ArchiveStore" + DataStoreTypesOperationalStore DataStoreTypes = "OperationalStore" + DataStoreTypesVaultStore DataStoreTypes = "VaultStore" +) + +func PossibleValuesForDataStoreTypes() []string { + return []string{ + string(DataStoreTypesArchiveStore), + string(DataStoreTypesOperationalStore), + string(DataStoreTypesVaultStore), + } +} + +func (s *DataStoreTypes) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDataStoreTypes(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDataStoreTypes(input string) (*DataStoreTypes, error) { + vals := map[string]DataStoreTypes{ + "archivestore": DataStoreTypesArchiveStore, + "operationalstore": DataStoreTypesOperationalStore, + "vaultstore": DataStoreTypesVaultStore, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DataStoreTypes(input) + return &out, nil +} + +type ResourcePropertiesObjectType string + +const ( + ResourcePropertiesObjectTypeDefaultResourceProperties ResourcePropertiesObjectType = "DefaultResourceProperties" +) + +func PossibleValuesForResourcePropertiesObjectType() []string { + return []string{ + string(ResourcePropertiesObjectTypeDefaultResourceProperties), + } +} + +func (s *ResourcePropertiesObjectType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseResourcePropertiesObjectType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseResourcePropertiesObjectType(input string) (*ResourcePropertiesObjectType, error) { + vals := map[string]ResourcePropertiesObjectType{ + "defaultresourceproperties": ResourcePropertiesObjectTypeDefaultResourceProperties, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ResourcePropertiesObjectType(input) + return &out, nil +} + +type SecretStoreType string + +const ( + SecretStoreTypeAzureKeyVault SecretStoreType = "AzureKeyVault" + SecretStoreTypeInvalid SecretStoreType = "Invalid" +) + +func PossibleValuesForSecretStoreType() []string { + return []string{ + string(SecretStoreTypeAzureKeyVault), + string(SecretStoreTypeInvalid), + } +} + +func (s *SecretStoreType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSecretStoreType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSecretStoreType(input string) (*SecretStoreType, error) { + vals := map[string]SecretStoreType{ + "azurekeyvault": SecretStoreTypeAzureKeyVault, + "invalid": SecretStoreTypeInvalid, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SecretStoreType(input) + return &out, nil +} + +type Status string + +const ( + StatusConfiguringProtection Status = "ConfiguringProtection" + StatusConfiguringProtectionFailed Status = "ConfiguringProtectionFailed" + StatusProtectionConfigured Status = "ProtectionConfigured" + StatusProtectionStopped Status = "ProtectionStopped" + StatusSoftDeleted Status = "SoftDeleted" + StatusSoftDeleting Status = "SoftDeleting" +) + +func PossibleValuesForStatus() []string { + return []string{ + string(StatusConfiguringProtection), + string(StatusConfiguringProtectionFailed), + string(StatusProtectionConfigured), + string(StatusProtectionStopped), + string(StatusSoftDeleted), + string(StatusSoftDeleting), + } +} + +func (s *Status) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseStatus(input string) (*Status, error) { + vals := map[string]Status{ + "configuringprotection": StatusConfiguringProtection, + "configuringprotectionfailed": StatusConfiguringProtectionFailed, + "protectionconfigured": StatusProtectionConfigured, + "protectionstopped": StatusProtectionStopped, + "softdeleted": StatusSoftDeleted, + "softdeleting": StatusSoftDeleting, + } + 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 ValidationType string + +const ( + ValidationTypeDeepValidation ValidationType = "DeepValidation" + ValidationTypeShallowValidation ValidationType = "ShallowValidation" +) + +func PossibleValuesForValidationType() []string { + return []string{ + string(ValidationTypeDeepValidation), + string(ValidationTypeShallowValidation), + } +} + +func (s *ValidationType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseValidationType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseValidationType(input string) (*ValidationType, error) { + vals := map[string]ValidationType{ + "deepvalidation": ValidationTypeDeepValidation, + "shallowvalidation": ValidationTypeShallowValidation, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ValidationType(input) + return &out, nil +} diff --git a/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/id_backupvault.go b/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/id_backupvault.go new file mode 100644 index 00000000000..950f77c00b8 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/id_backupvault.go @@ -0,0 +1,125 @@ +package deletedbackupinstances + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = BackupVaultId{} + +// BackupVaultId is a struct representing the Resource ID for a Backup Vault +type BackupVaultId struct { + SubscriptionId string + ResourceGroupName string + BackupVaultName string +} + +// NewBackupVaultID returns a new BackupVaultId struct +func NewBackupVaultID(subscriptionId string, resourceGroupName string, backupVaultName string) BackupVaultId { + return BackupVaultId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + BackupVaultName: backupVaultName, + } +} + +// ParseBackupVaultID parses 'input' into a BackupVaultId +func ParseBackupVaultID(input string) (*BackupVaultId, error) { + parser := resourceids.NewParserFromResourceIdType(BackupVaultId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BackupVaultId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseBackupVaultIDInsensitively parses 'input' case-insensitively into a BackupVaultId +// note: this method should only be used for API response data and not user input +func ParseBackupVaultIDInsensitively(input string) (*BackupVaultId, error) { + parser := resourceids.NewParserFromResourceIdType(BackupVaultId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BackupVaultId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *BackupVaultId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.BackupVaultName, ok = input.Parsed["backupVaultName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "backupVaultName", input) + } + + return nil +} + +// ValidateBackupVaultID checks that 'input' can be parsed as a Backup Vault ID +func ValidateBackupVaultID(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 := ParseBackupVaultID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Backup Vault ID +func (id BackupVaultId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DataProtection/backupVaults/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.BackupVaultName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Backup Vault ID +func (id BackupVaultId) 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("staticMicrosoftDataProtection", "Microsoft.DataProtection", "Microsoft.DataProtection"), + resourceids.StaticSegment("staticBackupVaults", "backupVaults", "backupVaults"), + resourceids.UserSpecifiedSegment("backupVaultName", "backupVaultValue"), + } +} + +// String returns a human-readable description of this Backup Vault ID +func (id BackupVaultId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Backup Vault Name: %q", id.BackupVaultName), + } + return fmt.Sprintf("Backup Vault (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/id_backupvault_test.go b/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/id_backupvault_test.go new file mode 100644 index 00000000000..c6f6e177865 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/id_backupvault_test.go @@ -0,0 +1,282 @@ +package deletedbackupinstances + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = BackupVaultId{} + +func TestNewBackupVaultID(t *testing.T) { + id := NewBackupVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultValue") + + 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.BackupVaultName != "backupVaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'BackupVaultName'", id.BackupVaultName, "backupVaultValue") + } +} + +func TestFormatBackupVaultID(t *testing.T) { + actual := NewBackupVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseBackupVaultID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BackupVaultId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue", + Expected: &BackupVaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + BackupVaultName: "backupVaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBackupVaultID(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.BackupVaultName != v.Expected.BackupVaultName { + t.Fatalf("Expected %q but got %q for BackupVaultName", v.Expected.BackupVaultName, actual.BackupVaultName) + } + + } +} + +func TestParseBackupVaultIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BackupVaultId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue", + Expected: &BackupVaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + BackupVaultName: "backupVaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtVaLuE", + Expected: &BackupVaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + BackupVaultName: "bAcKuPvAuLtVaLuE", + }, + }, + { + // 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.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBackupVaultIDInsensitively(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.BackupVaultName != v.Expected.BackupVaultName { + t.Fatalf("Expected %q but got %q for BackupVaultName", v.Expected.BackupVaultName, actual.BackupVaultName) + } + + } +} + +func TestSegmentsForBackupVaultId(t *testing.T) { + segments := BackupVaultId{}.Segments() + if len(segments) == 0 { + t.Fatalf("BackupVaultId 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/dataprotection/2023-11-01/deletedbackupinstances/id_deletedbackupinstance.go b/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/id_deletedbackupinstance.go new file mode 100644 index 00000000000..2effdb1d047 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/id_deletedbackupinstance.go @@ -0,0 +1,134 @@ +package deletedbackupinstances + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = DeletedBackupInstanceId{} + +// DeletedBackupInstanceId is a struct representing the Resource ID for a Deleted Backup Instance +type DeletedBackupInstanceId struct { + SubscriptionId string + ResourceGroupName string + BackupVaultName string + DeletedBackupInstanceName string +} + +// NewDeletedBackupInstanceID returns a new DeletedBackupInstanceId struct +func NewDeletedBackupInstanceID(subscriptionId string, resourceGroupName string, backupVaultName string, deletedBackupInstanceName string) DeletedBackupInstanceId { + return DeletedBackupInstanceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + BackupVaultName: backupVaultName, + DeletedBackupInstanceName: deletedBackupInstanceName, + } +} + +// ParseDeletedBackupInstanceID parses 'input' into a DeletedBackupInstanceId +func ParseDeletedBackupInstanceID(input string) (*DeletedBackupInstanceId, error) { + parser := resourceids.NewParserFromResourceIdType(DeletedBackupInstanceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DeletedBackupInstanceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseDeletedBackupInstanceIDInsensitively parses 'input' case-insensitively into a DeletedBackupInstanceId +// note: this method should only be used for API response data and not user input +func ParseDeletedBackupInstanceIDInsensitively(input string) (*DeletedBackupInstanceId, error) { + parser := resourceids.NewParserFromResourceIdType(DeletedBackupInstanceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DeletedBackupInstanceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *DeletedBackupInstanceId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.BackupVaultName, ok = input.Parsed["backupVaultName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "backupVaultName", input) + } + + if id.DeletedBackupInstanceName, ok = input.Parsed["deletedBackupInstanceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "deletedBackupInstanceName", input) + } + + return nil +} + +// ValidateDeletedBackupInstanceID checks that 'input' can be parsed as a Deleted Backup Instance ID +func ValidateDeletedBackupInstanceID(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 := ParseDeletedBackupInstanceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Deleted Backup Instance ID +func (id DeletedBackupInstanceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DataProtection/backupVaults/%s/deletedBackupInstances/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.BackupVaultName, id.DeletedBackupInstanceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Deleted Backup Instance ID +func (id DeletedBackupInstanceId) 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("staticMicrosoftDataProtection", "Microsoft.DataProtection", "Microsoft.DataProtection"), + resourceids.StaticSegment("staticBackupVaults", "backupVaults", "backupVaults"), + resourceids.UserSpecifiedSegment("backupVaultName", "backupVaultValue"), + resourceids.StaticSegment("staticDeletedBackupInstances", "deletedBackupInstances", "deletedBackupInstances"), + resourceids.UserSpecifiedSegment("deletedBackupInstanceName", "deletedBackupInstanceValue"), + } +} + +// String returns a human-readable description of this Deleted Backup Instance ID +func (id DeletedBackupInstanceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Backup Vault Name: %q", id.BackupVaultName), + fmt.Sprintf("Deleted Backup Instance Name: %q", id.DeletedBackupInstanceName), + } + return fmt.Sprintf("Deleted Backup Instance (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/id_deletedbackupinstance_test.go b/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/id_deletedbackupinstance_test.go new file mode 100644 index 00000000000..e6d0c059cc4 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/id_deletedbackupinstance_test.go @@ -0,0 +1,327 @@ +package deletedbackupinstances + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = DeletedBackupInstanceId{} + +func TestNewDeletedBackupInstanceID(t *testing.T) { + id := NewDeletedBackupInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultValue", "deletedBackupInstanceValue") + + 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.BackupVaultName != "backupVaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'BackupVaultName'", id.BackupVaultName, "backupVaultValue") + } + + if id.DeletedBackupInstanceName != "deletedBackupInstanceValue" { + t.Fatalf("Expected %q but got %q for Segment 'DeletedBackupInstanceName'", id.DeletedBackupInstanceName, "deletedBackupInstanceValue") + } +} + +func TestFormatDeletedBackupInstanceID(t *testing.T) { + actual := NewDeletedBackupInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultValue", "deletedBackupInstanceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/deletedBackupInstances/deletedBackupInstanceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseDeletedBackupInstanceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DeletedBackupInstanceId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/deletedBackupInstances", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/deletedBackupInstances/deletedBackupInstanceValue", + Expected: &DeletedBackupInstanceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + BackupVaultName: "backupVaultValue", + DeletedBackupInstanceName: "deletedBackupInstanceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/deletedBackupInstances/deletedBackupInstanceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDeletedBackupInstanceID(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.BackupVaultName != v.Expected.BackupVaultName { + t.Fatalf("Expected %q but got %q for BackupVaultName", v.Expected.BackupVaultName, actual.BackupVaultName) + } + + if actual.DeletedBackupInstanceName != v.Expected.DeletedBackupInstanceName { + t.Fatalf("Expected %q but got %q for DeletedBackupInstanceName", v.Expected.DeletedBackupInstanceName, actual.DeletedBackupInstanceName) + } + + } +} + +func TestParseDeletedBackupInstanceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DeletedBackupInstanceId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/deletedBackupInstances", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtVaLuE/dElEtEdBaCkUpInStAnCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/deletedBackupInstances/deletedBackupInstanceValue", + Expected: &DeletedBackupInstanceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + BackupVaultName: "backupVaultValue", + DeletedBackupInstanceName: "deletedBackupInstanceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/deletedBackupInstances/deletedBackupInstanceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtVaLuE/dElEtEdBaCkUpInStAnCeS/dElEtEdBaCkUpInStAnCeVaLuE", + Expected: &DeletedBackupInstanceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + BackupVaultName: "bAcKuPvAuLtVaLuE", + DeletedBackupInstanceName: "dElEtEdBaCkUpInStAnCeVaLuE", + }, + }, + { + // 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.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtVaLuE/dElEtEdBaCkUpInStAnCeS/dElEtEdBaCkUpInStAnCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDeletedBackupInstanceIDInsensitively(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.BackupVaultName != v.Expected.BackupVaultName { + t.Fatalf("Expected %q but got %q for BackupVaultName", v.Expected.BackupVaultName, actual.BackupVaultName) + } + + if actual.DeletedBackupInstanceName != v.Expected.DeletedBackupInstanceName { + t.Fatalf("Expected %q but got %q for DeletedBackupInstanceName", v.Expected.DeletedBackupInstanceName, actual.DeletedBackupInstanceName) + } + + } +} + +func TestSegmentsForDeletedBackupInstanceId(t *testing.T) { + segments := DeletedBackupInstanceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("DeletedBackupInstanceId 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/dataprotection/2023-11-01/deletedbackupinstances/method_get.go b/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/method_get.go new file mode 100644 index 00000000000..7fa22d6d7ad --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/method_get.go @@ -0,0 +1,51 @@ +package deletedbackupinstances + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DeletedBackupInstanceResource +} + +// Get ... +func (c DeletedBackupInstancesClient) Get(ctx context.Context, id DeletedBackupInstanceId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/method_list.go b/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/method_list.go new file mode 100644 index 00000000000..dd00e4b927c --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/method_list.go @@ -0,0 +1,89 @@ +package deletedbackupinstances + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]DeletedBackupInstanceResource +} + +type ListCompleteResult struct { + Items []DeletedBackupInstanceResource +} + +// List ... +func (c DeletedBackupInstancesClient) List(ctx context.Context, id BackupVaultId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/deletedBackupInstances", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]DeletedBackupInstanceResource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c DeletedBackupInstancesClient) ListComplete(ctx context.Context, id BackupVaultId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, DeletedBackupInstanceResourceOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DeletedBackupInstancesClient) ListCompleteMatchingPredicate(ctx context.Context, id BackupVaultId, predicate DeletedBackupInstanceResourceOperationPredicate) (result ListCompleteResult, err error) { + items := make([]DeletedBackupInstanceResource, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + Items: items, + } + return +} diff --git a/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/method_undelete.go b/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/method_undelete.go new file mode 100644 index 00000000000..1ab188478a5 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/method_undelete.go @@ -0,0 +1,70 @@ +package deletedbackupinstances + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UndeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Undelete ... +func (c DeletedBackupInstancesClient) Undelete(ctx context.Context, id DeletedBackupInstanceId) (result UndeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/undelete", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// UndeleteThenPoll performs Undelete then polls until it's completed +func (c DeletedBackupInstancesClient) UndeleteThenPoll(ctx context.Context, id DeletedBackupInstanceId) error { + result, err := c.Undelete(ctx, id) + if err != nil { + return fmt.Errorf("performing Undelete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Undelete: %+v", err) + } + + return nil +} diff --git a/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/model_authcredentials.go b/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/model_authcredentials.go new file mode 100644 index 00000000000..e1f6967a3f6 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/model_authcredentials.go @@ -0,0 +1,53 @@ +package deletedbackupinstances + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AuthCredentials interface { +} + +// RawAuthCredentialsImpl is returned when the Discriminated Value +// doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawAuthCredentialsImpl struct { + Type string + Values map[string]interface{} +} + +func unmarshalAuthCredentialsImplementation(input []byte) (AuthCredentials, error) { + if input == nil { + return nil, nil + } + + var temp map[string]interface{} + if err := json.Unmarshal(input, &temp); err != nil { + return nil, fmt.Errorf("unmarshaling AuthCredentials into map[string]interface: %+v", err) + } + + value, ok := temp["objectType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "SecretStoreBasedAuthCredentials") { + var out SecretStoreBasedAuthCredentials + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into SecretStoreBasedAuthCredentials: %+v", err) + } + return out, nil + } + + out := RawAuthCredentialsImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/model_azureoperationalstoreparameters.go b/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/model_azureoperationalstoreparameters.go new file mode 100644 index 00000000000..82c85ebf9e1 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/model_azureoperationalstoreparameters.go @@ -0,0 +1,42 @@ +package deletedbackupinstances + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DataStoreParameters = AzureOperationalStoreParameters{} + +type AzureOperationalStoreParameters struct { + ResourceGroupId *string `json:"resourceGroupId,omitempty"` + + // Fields inherited from DataStoreParameters + DataStoreType DataStoreTypes `json:"dataStoreType"` +} + +var _ json.Marshaler = AzureOperationalStoreParameters{} + +func (s AzureOperationalStoreParameters) MarshalJSON() ([]byte, error) { + type wrapper AzureOperationalStoreParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureOperationalStoreParameters: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureOperationalStoreParameters: %+v", err) + } + decoded["objectType"] = "AzureOperationalStoreParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureOperationalStoreParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/model_backupdatasourceparameters.go b/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/model_backupdatasourceparameters.go new file mode 100644 index 00000000000..61a96f79393 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/model_backupdatasourceparameters.go @@ -0,0 +1,61 @@ +package deletedbackupinstances + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackupDatasourceParameters interface { +} + +// RawBackupDatasourceParametersImpl is returned when the Discriminated Value +// doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawBackupDatasourceParametersImpl struct { + Type string + Values map[string]interface{} +} + +func unmarshalBackupDatasourceParametersImplementation(input []byte) (BackupDatasourceParameters, error) { + if input == nil { + return nil, nil + } + + var temp map[string]interface{} + if err := json.Unmarshal(input, &temp); err != nil { + return nil, fmt.Errorf("unmarshaling BackupDatasourceParameters into map[string]interface: %+v", err) + } + + value, ok := temp["objectType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "BlobBackupDatasourceParameters") { + var out BlobBackupDatasourceParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into BlobBackupDatasourceParameters: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "KubernetesClusterBackupDatasourceParameters") { + var out KubernetesClusterBackupDatasourceParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into KubernetesClusterBackupDatasourceParameters: %+v", err) + } + return out, nil + } + + out := RawBackupDatasourceParametersImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/model_baseresourceproperties.go b/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/model_baseresourceproperties.go new file mode 100644 index 00000000000..395fa05201d --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/model_baseresourceproperties.go @@ -0,0 +1,53 @@ +package deletedbackupinstances + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BaseResourceProperties interface { +} + +// RawBaseResourcePropertiesImpl is returned when the Discriminated Value +// doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawBaseResourcePropertiesImpl struct { + Type string + Values map[string]interface{} +} + +func unmarshalBaseResourcePropertiesImplementation(input []byte) (BaseResourceProperties, error) { + if input == nil { + return nil, nil + } + + var temp map[string]interface{} + if err := json.Unmarshal(input, &temp); err != nil { + return nil, fmt.Errorf("unmarshaling BaseResourceProperties into map[string]interface: %+v", err) + } + + value, ok := temp["objectType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "DefaultResourceProperties") { + var out DefaultResourceProperties + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into DefaultResourceProperties: %+v", err) + } + return out, nil + } + + out := RawBaseResourcePropertiesImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/model_blobbackupdatasourceparameters.go b/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/model_blobbackupdatasourceparameters.go new file mode 100644 index 00000000000..8dbfe3038cd --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/model_blobbackupdatasourceparameters.go @@ -0,0 +1,41 @@ +package deletedbackupinstances + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ BackupDatasourceParameters = BlobBackupDatasourceParameters{} + +type BlobBackupDatasourceParameters struct { + ContainersList []string `json:"containersList"` + + // Fields inherited from BackupDatasourceParameters +} + +var _ json.Marshaler = BlobBackupDatasourceParameters{} + +func (s BlobBackupDatasourceParameters) MarshalJSON() ([]byte, error) { + type wrapper BlobBackupDatasourceParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling BlobBackupDatasourceParameters: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling BlobBackupDatasourceParameters: %+v", err) + } + decoded["objectType"] = "BlobBackupDatasourceParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling BlobBackupDatasourceParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/model_datasource.go b/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/model_datasource.go new file mode 100644 index 00000000000..ae955b4355b --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/model_datasource.go @@ -0,0 +1,52 @@ +package deletedbackupinstances + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Datasource struct { + DatasourceType *string `json:"datasourceType,omitempty"` + ObjectType *string `json:"objectType,omitempty"` + ResourceID string `json:"resourceID"` + ResourceLocation *string `json:"resourceLocation,omitempty"` + ResourceName *string `json:"resourceName,omitempty"` + ResourceProperties BaseResourceProperties `json:"resourceProperties"` + ResourceType *string `json:"resourceType,omitempty"` + ResourceUri *string `json:"resourceUri,omitempty"` +} + +var _ json.Unmarshaler = &Datasource{} + +func (s *Datasource) UnmarshalJSON(bytes []byte) error { + type alias Datasource + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into Datasource: %+v", err) + } + + s.DatasourceType = decoded.DatasourceType + s.ObjectType = decoded.ObjectType + s.ResourceID = decoded.ResourceID + s.ResourceLocation = decoded.ResourceLocation + s.ResourceName = decoded.ResourceName + s.ResourceType = decoded.ResourceType + s.ResourceUri = decoded.ResourceUri + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling Datasource into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["resourceProperties"]; ok { + impl, err := unmarshalBaseResourcePropertiesImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'ResourceProperties' for 'Datasource': %+v", err) + } + s.ResourceProperties = impl + } + return nil +} diff --git a/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/model_datasourceset.go b/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/model_datasourceset.go new file mode 100644 index 00000000000..03857806dea --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/model_datasourceset.go @@ -0,0 +1,52 @@ +package deletedbackupinstances + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatasourceSet struct { + DatasourceType *string `json:"datasourceType,omitempty"` + ObjectType *string `json:"objectType,omitempty"` + ResourceID string `json:"resourceID"` + ResourceLocation *string `json:"resourceLocation,omitempty"` + ResourceName *string `json:"resourceName,omitempty"` + ResourceProperties BaseResourceProperties `json:"resourceProperties"` + ResourceType *string `json:"resourceType,omitempty"` + ResourceUri *string `json:"resourceUri,omitempty"` +} + +var _ json.Unmarshaler = &DatasourceSet{} + +func (s *DatasourceSet) UnmarshalJSON(bytes []byte) error { + type alias DatasourceSet + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into DatasourceSet: %+v", err) + } + + s.DatasourceType = decoded.DatasourceType + s.ObjectType = decoded.ObjectType + s.ResourceID = decoded.ResourceID + s.ResourceLocation = decoded.ResourceLocation + s.ResourceName = decoded.ResourceName + s.ResourceType = decoded.ResourceType + s.ResourceUri = decoded.ResourceUri + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling DatasourceSet into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["resourceProperties"]; ok { + impl, err := unmarshalBaseResourcePropertiesImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'ResourceProperties' for 'DatasourceSet': %+v", err) + } + s.ResourceProperties = impl + } + return nil +} diff --git a/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/model_datastoreparameters.go b/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/model_datastoreparameters.go new file mode 100644 index 00000000000..0c5750816d1 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/model_datastoreparameters.go @@ -0,0 +1,53 @@ +package deletedbackupinstances + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DataStoreParameters interface { +} + +// RawDataStoreParametersImpl is returned when the Discriminated Value +// doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawDataStoreParametersImpl struct { + Type string + Values map[string]interface{} +} + +func unmarshalDataStoreParametersImplementation(input []byte) (DataStoreParameters, error) { + if input == nil { + return nil, nil + } + + var temp map[string]interface{} + if err := json.Unmarshal(input, &temp); err != nil { + return nil, fmt.Errorf("unmarshaling DataStoreParameters into map[string]interface: %+v", err) + } + + value, ok := temp["objectType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "AzureOperationalStoreParameters") { + var out AzureOperationalStoreParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureOperationalStoreParameters: %+v", err) + } + return out, nil + } + + out := RawDataStoreParametersImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/model_defaultresourceproperties.go b/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/model_defaultresourceproperties.go new file mode 100644 index 00000000000..618a75af3b9 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/model_defaultresourceproperties.go @@ -0,0 +1,40 @@ +package deletedbackupinstances + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ BaseResourceProperties = DefaultResourceProperties{} + +type DefaultResourceProperties struct { + + // Fields inherited from BaseResourceProperties +} + +var _ json.Marshaler = DefaultResourceProperties{} + +func (s DefaultResourceProperties) MarshalJSON() ([]byte, error) { + type wrapper DefaultResourceProperties + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling DefaultResourceProperties: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling DefaultResourceProperties: %+v", err) + } + decoded["objectType"] = "DefaultResourceProperties" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling DefaultResourceProperties: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/model_deletedbackupinstance.go b/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/model_deletedbackupinstance.go new file mode 100644 index 00000000000..a1cec159406 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/model_deletedbackupinstance.go @@ -0,0 +1,62 @@ +package deletedbackupinstances + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeletedBackupInstance struct { + CurrentProtectionState *CurrentProtectionState `json:"currentProtectionState,omitempty"` + DataSourceInfo Datasource `json:"dataSourceInfo"` + DataSourceSetInfo *DatasourceSet `json:"dataSourceSetInfo,omitempty"` + DatasourceAuthCredentials AuthCredentials `json:"datasourceAuthCredentials"` + DeletionInfo *DeletionInfo `json:"deletionInfo,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + IdentityDetails *IdentityDetails `json:"identityDetails,omitempty"` + ObjectType string `json:"objectType"` + PolicyInfo PolicyInfo `json:"policyInfo"` + ProtectionErrorDetails *UserFacingError `json:"protectionErrorDetails,omitempty"` + ProtectionStatus *ProtectionStatusDetails `json:"protectionStatus,omitempty"` + ProvisioningState *string `json:"provisioningState,omitempty"` + ValidationType *ValidationType `json:"validationType,omitempty"` +} + +var _ json.Unmarshaler = &DeletedBackupInstance{} + +func (s *DeletedBackupInstance) UnmarshalJSON(bytes []byte) error { + type alias DeletedBackupInstance + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into DeletedBackupInstance: %+v", err) + } + + s.CurrentProtectionState = decoded.CurrentProtectionState + s.DataSourceInfo = decoded.DataSourceInfo + s.DataSourceSetInfo = decoded.DataSourceSetInfo + s.DeletionInfo = decoded.DeletionInfo + s.FriendlyName = decoded.FriendlyName + s.IdentityDetails = decoded.IdentityDetails + s.ObjectType = decoded.ObjectType + s.PolicyInfo = decoded.PolicyInfo + s.ProtectionErrorDetails = decoded.ProtectionErrorDetails + s.ProtectionStatus = decoded.ProtectionStatus + s.ProvisioningState = decoded.ProvisioningState + s.ValidationType = decoded.ValidationType + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling DeletedBackupInstance into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["datasourceAuthCredentials"]; ok { + impl, err := unmarshalAuthCredentialsImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'DatasourceAuthCredentials' for 'DeletedBackupInstance': %+v", err) + } + s.DatasourceAuthCredentials = impl + } + return nil +} diff --git a/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/model_deletedbackupinstanceresource.go b/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/model_deletedbackupinstanceresource.go new file mode 100644 index 00000000000..9d4b9f116ec --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/model_deletedbackupinstanceresource.go @@ -0,0 +1,16 @@ +package deletedbackupinstances + +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 DeletedBackupInstanceResource struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *DeletedBackupInstance `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/model_deletioninfo.go b/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/model_deletioninfo.go new file mode 100644 index 00000000000..e01dc7d9b15 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/model_deletioninfo.go @@ -0,0 +1,11 @@ +package deletedbackupinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeletionInfo struct { + BillingEndDate *string `json:"billingEndDate,omitempty"` + DeleteActivityID *string `json:"deleteActivityID,omitempty"` + DeletionTime *string `json:"deletionTime,omitempty"` + ScheduledPurgeTime *string `json:"scheduledPurgeTime,omitempty"` +} diff --git a/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/model_identitydetails.go b/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/model_identitydetails.go new file mode 100644 index 00000000000..e04ae4cdbf2 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/model_identitydetails.go @@ -0,0 +1,9 @@ +package deletedbackupinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IdentityDetails struct { + UseSystemAssignedIdentity *bool `json:"useSystemAssignedIdentity,omitempty"` + UserAssignedIdentityArmUrl *string `json:"userAssignedIdentityArmUrl,omitempty"` +} diff --git a/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/model_innererror.go b/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/model_innererror.go new file mode 100644 index 00000000000..e59cb1caa0f --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/model_innererror.go @@ -0,0 +1,10 @@ +package deletedbackupinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type InnerError struct { + AdditionalInfo *map[string]string `json:"additionalInfo,omitempty"` + Code *string `json:"code,omitempty"` + EmbeddedInnerError *InnerError `json:"embeddedInnerError,omitempty"` +} diff --git a/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/model_kubernetesclusterbackupdatasourceparameters.go b/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/model_kubernetesclusterbackupdatasourceparameters.go new file mode 100644 index 00000000000..10068d31fa5 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/model_kubernetesclusterbackupdatasourceparameters.go @@ -0,0 +1,48 @@ +package deletedbackupinstances + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ BackupDatasourceParameters = KubernetesClusterBackupDatasourceParameters{} + +type KubernetesClusterBackupDatasourceParameters struct { + BackupHookReferences *[]NamespacedNameResource `json:"backupHookReferences,omitempty"` + ExcludedNamespaces *[]string `json:"excludedNamespaces,omitempty"` + ExcludedResourceTypes *[]string `json:"excludedResourceTypes,omitempty"` + IncludeClusterScopeResources bool `json:"includeClusterScopeResources"` + IncludedNamespaces *[]string `json:"includedNamespaces,omitempty"` + IncludedResourceTypes *[]string `json:"includedResourceTypes,omitempty"` + LabelSelectors *[]string `json:"labelSelectors,omitempty"` + SnapshotVolumes bool `json:"snapshotVolumes"` + + // Fields inherited from BackupDatasourceParameters +} + +var _ json.Marshaler = KubernetesClusterBackupDatasourceParameters{} + +func (s KubernetesClusterBackupDatasourceParameters) MarshalJSON() ([]byte, error) { + type wrapper KubernetesClusterBackupDatasourceParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling KubernetesClusterBackupDatasourceParameters: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling KubernetesClusterBackupDatasourceParameters: %+v", err) + } + decoded["objectType"] = "KubernetesClusterBackupDatasourceParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling KubernetesClusterBackupDatasourceParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/model_namespacednameresource.go b/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/model_namespacednameresource.go new file mode 100644 index 00000000000..70d84cc64c6 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/model_namespacednameresource.go @@ -0,0 +1,9 @@ +package deletedbackupinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NamespacedNameResource struct { + Name *string `json:"name,omitempty"` + Namespace *string `json:"namespace,omitempty"` +} diff --git a/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/model_policyinfo.go b/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/model_policyinfo.go new file mode 100644 index 00000000000..0ab008c3307 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/model_policyinfo.go @@ -0,0 +1,10 @@ +package deletedbackupinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PolicyInfo struct { + PolicyId string `json:"policyId"` + PolicyParameters *PolicyParameters `json:"policyParameters,omitempty"` + PolicyVersion *string `json:"policyVersion,omitempty"` +} diff --git a/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/model_policyparameters.go b/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/model_policyparameters.go new file mode 100644 index 00000000000..b1f479381f0 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/model_policyparameters.go @@ -0,0 +1,59 @@ +package deletedbackupinstances + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PolicyParameters struct { + BackupDatasourceParametersList *[]BackupDatasourceParameters `json:"backupDatasourceParametersList,omitempty"` + DataStoreParametersList *[]DataStoreParameters `json:"dataStoreParametersList,omitempty"` +} + +var _ json.Unmarshaler = &PolicyParameters{} + +func (s *PolicyParameters) UnmarshalJSON(bytes []byte) error { + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling PolicyParameters into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["backupDatasourceParametersList"]; ok { + var listTemp []json.RawMessage + if err := json.Unmarshal(v, &listTemp); err != nil { + return fmt.Errorf("unmarshaling BackupDatasourceParametersList into list []json.RawMessage: %+v", err) + } + + output := make([]BackupDatasourceParameters, 0) + for i, val := range listTemp { + impl, err := unmarshalBackupDatasourceParametersImplementation(val) + if err != nil { + return fmt.Errorf("unmarshaling index %d field 'BackupDatasourceParametersList' for 'PolicyParameters': %+v", i, err) + } + output = append(output, impl) + } + s.BackupDatasourceParametersList = &output + } + + if v, ok := temp["dataStoreParametersList"]; ok { + var listTemp []json.RawMessage + if err := json.Unmarshal(v, &listTemp); err != nil { + return fmt.Errorf("unmarshaling DataStoreParametersList into list []json.RawMessage: %+v", err) + } + + output := make([]DataStoreParameters, 0) + for i, val := range listTemp { + impl, err := unmarshalDataStoreParametersImplementation(val) + if err != nil { + return fmt.Errorf("unmarshaling index %d field 'DataStoreParametersList' for 'PolicyParameters': %+v", i, err) + } + output = append(output, impl) + } + s.DataStoreParametersList = &output + } + return nil +} diff --git a/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/model_protectionstatusdetails.go b/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/model_protectionstatusdetails.go new file mode 100644 index 00000000000..27e9741b405 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/model_protectionstatusdetails.go @@ -0,0 +1,9 @@ +package deletedbackupinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProtectionStatusDetails struct { + ErrorDetails *UserFacingError `json:"errorDetails,omitempty"` + Status *Status `json:"status,omitempty"` +} diff --git a/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/model_secretstorebasedauthcredentials.go b/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/model_secretstorebasedauthcredentials.go new file mode 100644 index 00000000000..61dd7ae1963 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/model_secretstorebasedauthcredentials.go @@ -0,0 +1,41 @@ +package deletedbackupinstances + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ AuthCredentials = SecretStoreBasedAuthCredentials{} + +type SecretStoreBasedAuthCredentials struct { + SecretStoreResource *SecretStoreResource `json:"secretStoreResource,omitempty"` + + // Fields inherited from AuthCredentials +} + +var _ json.Marshaler = SecretStoreBasedAuthCredentials{} + +func (s SecretStoreBasedAuthCredentials) MarshalJSON() ([]byte, error) { + type wrapper SecretStoreBasedAuthCredentials + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling SecretStoreBasedAuthCredentials: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling SecretStoreBasedAuthCredentials: %+v", err) + } + decoded["objectType"] = "SecretStoreBasedAuthCredentials" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling SecretStoreBasedAuthCredentials: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/model_secretstoreresource.go b/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/model_secretstoreresource.go new file mode 100644 index 00000000000..940322a2821 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/model_secretstoreresource.go @@ -0,0 +1,10 @@ +package deletedbackupinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SecretStoreResource struct { + SecretStoreType SecretStoreType `json:"secretStoreType"` + Uri *string `json:"uri,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/model_userfacingerror.go b/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/model_userfacingerror.go new file mode 100644 index 00000000000..db9ffc175f6 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/model_userfacingerror.go @@ -0,0 +1,16 @@ +package deletedbackupinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UserFacingError struct { + Code *string `json:"code,omitempty"` + Details *[]UserFacingError `json:"details,omitempty"` + InnerError *InnerError `json:"innerError,omitempty"` + IsRetryable *bool `json:"isRetryable,omitempty"` + IsUserError *bool `json:"isUserError,omitempty"` + Message *string `json:"message,omitempty"` + Properties *map[string]string `json:"properties,omitempty"` + RecommendedAction *[]string `json:"recommendedAction,omitempty"` + Target *string `json:"target,omitempty"` +} diff --git a/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/predicates.go b/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/predicates.go new file mode 100644 index 00000000000..d7c6585786d --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/predicates.go @@ -0,0 +1,27 @@ +package deletedbackupinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeletedBackupInstanceResourceOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p DeletedBackupInstanceResourceOperationPredicate) Matches(input DeletedBackupInstanceResource) 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/dataprotection/2023-11-01/deletedbackupinstances/version.go b/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/version.go new file mode 100644 index 00000000000..3998aa6bf3a --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/deletedbackupinstances/version.go @@ -0,0 +1,12 @@ +package deletedbackupinstances + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-11-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/deletedbackupinstances/%s", defaultApiVersion) +} diff --git a/resource-manager/dataprotection/2023-11-01/dppfeaturesupport/README.md b/resource-manager/dataprotection/2023-11-01/dppfeaturesupport/README.md new file mode 100644 index 00000000000..99a863ef43d --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/dppfeaturesupport/README.md @@ -0,0 +1,41 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2023-11-01/dppfeaturesupport` Documentation + +The `dppfeaturesupport` SDK allows for interaction with the Azure Resource Manager Service `dataprotection` (API Version `2023-11-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2023-11-01/dppfeaturesupport" +``` + + +### Client Initialization + +```go +client := dppfeaturesupport.NewDppFeatureSupportClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DppFeatureSupportClient.DataProtectionCheckFeatureSupport` + +```go +ctx := context.TODO() +id := dppfeaturesupport.NewLocationID("12345678-1234-9876-4563-123456789012", "locationValue") + +payload := dppfeaturesupport.FeatureValidationRequestBase{ + // ... +} + + +read, err := client.DataProtectionCheckFeatureSupport(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/dataprotection/2023-11-01/dppfeaturesupport/client.go b/resource-manager/dataprotection/2023-11-01/dppfeaturesupport/client.go new file mode 100644 index 00000000000..05f9070486d --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/dppfeaturesupport/client.go @@ -0,0 +1,26 @@ +package dppfeaturesupport + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DppFeatureSupportClient struct { + Client *resourcemanager.Client +} + +func NewDppFeatureSupportClientWithBaseURI(sdkApi sdkEnv.Api) (*DppFeatureSupportClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "dppfeaturesupport", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DppFeatureSupportClient: %+v", err) + } + + return &DppFeatureSupportClient{ + Client: client, + }, nil +} diff --git a/resource-manager/dataprotection/2023-11-01/dppfeaturesupport/constants.go b/resource-manager/dataprotection/2023-11-01/dppfeaturesupport/constants.go new file mode 100644 index 00000000000..91dae34ba66 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/dppfeaturesupport/constants.go @@ -0,0 +1,104 @@ +package dppfeaturesupport + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FeatureSupportStatus string + +const ( + FeatureSupportStatusAlphaPreview FeatureSupportStatus = "AlphaPreview" + FeatureSupportStatusGenerallyAvailable FeatureSupportStatus = "GenerallyAvailable" + FeatureSupportStatusInvalid FeatureSupportStatus = "Invalid" + FeatureSupportStatusNotSupported FeatureSupportStatus = "NotSupported" + FeatureSupportStatusPrivatePreview FeatureSupportStatus = "PrivatePreview" + FeatureSupportStatusPublicPreview FeatureSupportStatus = "PublicPreview" +) + +func PossibleValuesForFeatureSupportStatus() []string { + return []string{ + string(FeatureSupportStatusAlphaPreview), + string(FeatureSupportStatusGenerallyAvailable), + string(FeatureSupportStatusInvalid), + string(FeatureSupportStatusNotSupported), + string(FeatureSupportStatusPrivatePreview), + string(FeatureSupportStatusPublicPreview), + } +} + +func (s *FeatureSupportStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseFeatureSupportStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseFeatureSupportStatus(input string) (*FeatureSupportStatus, error) { + vals := map[string]FeatureSupportStatus{ + "alphapreview": FeatureSupportStatusAlphaPreview, + "generallyavailable": FeatureSupportStatusGenerallyAvailable, + "invalid": FeatureSupportStatusInvalid, + "notsupported": FeatureSupportStatusNotSupported, + "privatepreview": FeatureSupportStatusPrivatePreview, + "publicpreview": FeatureSupportStatusPublicPreview, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := FeatureSupportStatus(input) + return &out, nil +} + +type FeatureType string + +const ( + FeatureTypeDataSourceType FeatureType = "DataSourceType" + FeatureTypeInvalid FeatureType = "Invalid" +) + +func PossibleValuesForFeatureType() []string { + return []string{ + string(FeatureTypeDataSourceType), + string(FeatureTypeInvalid), + } +} + +func (s *FeatureType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseFeatureType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseFeatureType(input string) (*FeatureType, error) { + vals := map[string]FeatureType{ + "datasourcetype": FeatureTypeDataSourceType, + "invalid": FeatureTypeInvalid, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := FeatureType(input) + return &out, nil +} diff --git a/resource-manager/dataprotection/2023-11-01/dppfeaturesupport/id_location.go b/resource-manager/dataprotection/2023-11-01/dppfeaturesupport/id_location.go new file mode 100644 index 00000000000..aa04649a21d --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/dppfeaturesupport/id_location.go @@ -0,0 +1,116 @@ +package dppfeaturesupport + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = LocationId{} + +// LocationId is a struct representing the Resource ID for a Location +type LocationId struct { + SubscriptionId string + LocationName string +} + +// NewLocationID returns a new LocationId struct +func NewLocationID(subscriptionId string, locationName string) LocationId { + return LocationId{ + SubscriptionId: subscriptionId, + LocationName: locationName, + } +} + +// ParseLocationID parses 'input' into a LocationId +func ParseLocationID(input string) (*LocationId, error) { + parser := resourceids.NewParserFromResourceIdType(LocationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LocationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseLocationIDInsensitively parses 'input' case-insensitively into a LocationId +// note: this method should only be used for API response data and not user input +func ParseLocationIDInsensitively(input string) (*LocationId, error) { + parser := resourceids.NewParserFromResourceIdType(LocationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LocationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *LocationId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.LocationName, ok = input.Parsed["locationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "locationName", input) + } + + return nil +} + +// ValidateLocationID checks that 'input' can be parsed as a Location ID +func ValidateLocationID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseLocationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Location ID +func (id LocationId) ID() string { + fmtString := "/subscriptions/%s/providers/Microsoft.DataProtection/locations/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.LocationName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Location ID +func (id LocationId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftDataProtection", "Microsoft.DataProtection", "Microsoft.DataProtection"), + resourceids.StaticSegment("staticLocations", "locations", "locations"), + resourceids.UserSpecifiedSegment("locationName", "locationValue"), + } +} + +// String returns a human-readable description of this Location ID +func (id LocationId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Location Name: %q", id.LocationName), + } + return fmt.Sprintf("Location (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/dataprotection/2023-11-01/dppfeaturesupport/id_location_test.go b/resource-manager/dataprotection/2023-11-01/dppfeaturesupport/id_location_test.go new file mode 100644 index 00000000000..3a3d6c0d8f5 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/dppfeaturesupport/id_location_test.go @@ -0,0 +1,237 @@ +package dppfeaturesupport + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = LocationId{} + +func TestNewLocationID(t *testing.T) { + id := NewLocationID("12345678-1234-9876-4563-123456789012", "locationValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.LocationName != "locationValue" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationValue") + } +} + +func TestFormatLocationID(t *testing.T) { + actual := NewLocationID("12345678-1234-9876-4563-123456789012", "locationValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.DataProtection/locations/locationValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseLocationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *LocationId + }{ + { + // 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/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.DataProtection", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.DataProtection/locations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.DataProtection/locations/locationValue", + Expected: &LocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.DataProtection/locations/locationValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseLocationID(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.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + } +} + +func TestParseLocationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *LocationId + }{ + { + // 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/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.DataProtection", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.DataProtection/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/lOcAtIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.DataProtection/locations/locationValue", + Expected: &LocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.DataProtection/locations/locationValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/lOcAtIoNs/lOcAtIoNvAlUe", + Expected: &LocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "lOcAtIoNvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/lOcAtIoNs/lOcAtIoNvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseLocationIDInsensitively(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.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + } +} + +func TestSegmentsForLocationId(t *testing.T) { + segments := LocationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("LocationId 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/dataprotection/2023-11-01/dppfeaturesupport/method_dataprotectioncheckfeaturesupport.go b/resource-manager/dataprotection/2023-11-01/dppfeaturesupport/method_dataprotectioncheckfeaturesupport.go new file mode 100644 index 00000000000..5b01a004060 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/dppfeaturesupport/method_dataprotectioncheckfeaturesupport.go @@ -0,0 +1,63 @@ +package dppfeaturesupport + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DataProtectionCheckFeatureSupportOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *FeatureValidationResponseBase +} + +// DataProtectionCheckFeatureSupport ... +func (c DppFeatureSupportClient) DataProtectionCheckFeatureSupport(ctx context.Context, id LocationId, input FeatureValidationRequestBase) (result DataProtectionCheckFeatureSupportOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/checkFeatureSupport", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalFeatureValidationResponseBaseImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/dataprotection/2023-11-01/dppfeaturesupport/model_featurevalidationrequest.go b/resource-manager/dataprotection/2023-11-01/dppfeaturesupport/model_featurevalidationrequest.go new file mode 100644 index 00000000000..245619e2f34 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/dppfeaturesupport/model_featurevalidationrequest.go @@ -0,0 +1,42 @@ +package dppfeaturesupport + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ FeatureValidationRequestBase = FeatureValidationRequest{} + +type FeatureValidationRequest struct { + FeatureName *string `json:"featureName,omitempty"` + FeatureType *FeatureType `json:"featureType,omitempty"` + + // Fields inherited from FeatureValidationRequestBase +} + +var _ json.Marshaler = FeatureValidationRequest{} + +func (s FeatureValidationRequest) MarshalJSON() ([]byte, error) { + type wrapper FeatureValidationRequest + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling FeatureValidationRequest: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling FeatureValidationRequest: %+v", err) + } + decoded["objectType"] = "FeatureValidationRequest" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling FeatureValidationRequest: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/dataprotection/2023-11-01/dppfeaturesupport/model_featurevalidationrequestbase.go b/resource-manager/dataprotection/2023-11-01/dppfeaturesupport/model_featurevalidationrequestbase.go new file mode 100644 index 00000000000..80efd7fd693 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/dppfeaturesupport/model_featurevalidationrequestbase.go @@ -0,0 +1,53 @@ +package dppfeaturesupport + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FeatureValidationRequestBase interface { +} + +// RawFeatureValidationRequestBaseImpl is returned when the Discriminated Value +// doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawFeatureValidationRequestBaseImpl struct { + Type string + Values map[string]interface{} +} + +func unmarshalFeatureValidationRequestBaseImplementation(input []byte) (FeatureValidationRequestBase, error) { + if input == nil { + return nil, nil + } + + var temp map[string]interface{} + if err := json.Unmarshal(input, &temp); err != nil { + return nil, fmt.Errorf("unmarshaling FeatureValidationRequestBase into map[string]interface: %+v", err) + } + + value, ok := temp["objectType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "FeatureValidationRequest") { + var out FeatureValidationRequest + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into FeatureValidationRequest: %+v", err) + } + return out, nil + } + + out := RawFeatureValidationRequestBaseImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/dataprotection/2023-11-01/dppfeaturesupport/model_featurevalidationresponse.go b/resource-manager/dataprotection/2023-11-01/dppfeaturesupport/model_featurevalidationresponse.go new file mode 100644 index 00000000000..cf7a0191334 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/dppfeaturesupport/model_featurevalidationresponse.go @@ -0,0 +1,42 @@ +package dppfeaturesupport + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ FeatureValidationResponseBase = FeatureValidationResponse{} + +type FeatureValidationResponse struct { + FeatureType *FeatureType `json:"featureType,omitempty"` + Features *[]SupportedFeature `json:"features,omitempty"` + + // Fields inherited from FeatureValidationResponseBase +} + +var _ json.Marshaler = FeatureValidationResponse{} + +func (s FeatureValidationResponse) MarshalJSON() ([]byte, error) { + type wrapper FeatureValidationResponse + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling FeatureValidationResponse: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling FeatureValidationResponse: %+v", err) + } + decoded["objectType"] = "FeatureValidationResponse" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling FeatureValidationResponse: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/dataprotection/2023-11-01/dppfeaturesupport/model_featurevalidationresponsebase.go b/resource-manager/dataprotection/2023-11-01/dppfeaturesupport/model_featurevalidationresponsebase.go new file mode 100644 index 00000000000..77514fd0908 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/dppfeaturesupport/model_featurevalidationresponsebase.go @@ -0,0 +1,53 @@ +package dppfeaturesupport + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FeatureValidationResponseBase interface { +} + +// RawFeatureValidationResponseBaseImpl is returned when the Discriminated Value +// doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawFeatureValidationResponseBaseImpl struct { + Type string + Values map[string]interface{} +} + +func unmarshalFeatureValidationResponseBaseImplementation(input []byte) (FeatureValidationResponseBase, error) { + if input == nil { + return nil, nil + } + + var temp map[string]interface{} + if err := json.Unmarshal(input, &temp); err != nil { + return nil, fmt.Errorf("unmarshaling FeatureValidationResponseBase into map[string]interface: %+v", err) + } + + value, ok := temp["objectType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "FeatureValidationResponse") { + var out FeatureValidationResponse + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into FeatureValidationResponse: %+v", err) + } + return out, nil + } + + out := RawFeatureValidationResponseBaseImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/dataprotection/2023-11-01/dppfeaturesupport/model_supportedfeature.go b/resource-manager/dataprotection/2023-11-01/dppfeaturesupport/model_supportedfeature.go new file mode 100644 index 00000000000..f32f28b1b2c --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/dppfeaturesupport/model_supportedfeature.go @@ -0,0 +1,10 @@ +package dppfeaturesupport + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SupportedFeature struct { + ExposureControlledFeatures *[]string `json:"exposureControlledFeatures,omitempty"` + FeatureName *string `json:"featureName,omitempty"` + SupportStatus *FeatureSupportStatus `json:"supportStatus,omitempty"` +} diff --git a/resource-manager/dataprotection/2023-11-01/dppfeaturesupport/version.go b/resource-manager/dataprotection/2023-11-01/dppfeaturesupport/version.go new file mode 100644 index 00000000000..66724a764fd --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/dppfeaturesupport/version.go @@ -0,0 +1,12 @@ +package dppfeaturesupport + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-11-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/dppfeaturesupport/%s", defaultApiVersion) +} diff --git a/resource-manager/dataprotection/2023-11-01/dppjob/README.md b/resource-manager/dataprotection/2023-11-01/dppjob/README.md new file mode 100644 index 00000000000..5870207eba4 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/dppjob/README.md @@ -0,0 +1,63 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2023-11-01/dppjob` Documentation + +The `dppjob` SDK allows for interaction with the Azure Resource Manager Service `dataprotection` (API Version `2023-11-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2023-11-01/dppjob" +``` + + +### Client Initialization + +```go +client := dppjob.NewDppJobClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DppJobClient.FetchCrossRegionRestoreJobGet` + +```go +ctx := context.TODO() +id := dppjob.NewProviderLocationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationValue") + +payload := dppjob.CrossRegionRestoreJobRequest{ + // ... +} + + +read, err := client.FetchCrossRegionRestoreJobGet(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DppJobClient.FetchCrossRegionRestoreJobsList` + +```go +ctx := context.TODO() +id := dppjob.NewProviderLocationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationValue") + +payload := dppjob.CrossRegionRestoreJobsRequest{ + // ... +} + + +// alternatively `client.FetchCrossRegionRestoreJobsList(ctx, id, payload, dppjob.DefaultFetchCrossRegionRestoreJobsListOperationOptions())` can be used to do batched pagination +items, err := client.FetchCrossRegionRestoreJobsListComplete(ctx, id, payload, dppjob.DefaultFetchCrossRegionRestoreJobsListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/dataprotection/2023-11-01/dppjob/client.go b/resource-manager/dataprotection/2023-11-01/dppjob/client.go new file mode 100644 index 00000000000..0d6159de0c6 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/dppjob/client.go @@ -0,0 +1,26 @@ +package dppjob + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DppJobClient struct { + Client *resourcemanager.Client +} + +func NewDppJobClientWithBaseURI(sdkApi sdkEnv.Api) (*DppJobClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "dppjob", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DppJobClient: %+v", err) + } + + return &DppJobClient{ + Client: client, + }, nil +} diff --git a/resource-manager/dataprotection/2023-11-01/dppjob/id_providerlocation.go b/resource-manager/dataprotection/2023-11-01/dppjob/id_providerlocation.go new file mode 100644 index 00000000000..689b13b88e7 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/dppjob/id_providerlocation.go @@ -0,0 +1,125 @@ +package dppjob + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = ProviderLocationId{} + +// ProviderLocationId is a struct representing the Resource ID for a Provider Location +type ProviderLocationId struct { + SubscriptionId string + ResourceGroupName string + LocationName string +} + +// NewProviderLocationID returns a new ProviderLocationId struct +func NewProviderLocationID(subscriptionId string, resourceGroupName string, locationName string) ProviderLocationId { + return ProviderLocationId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + LocationName: locationName, + } +} + +// ParseProviderLocationID parses 'input' into a ProviderLocationId +func ParseProviderLocationID(input string) (*ProviderLocationId, error) { + parser := resourceids.NewParserFromResourceIdType(ProviderLocationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProviderLocationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseProviderLocationIDInsensitively parses 'input' case-insensitively into a ProviderLocationId +// note: this method should only be used for API response data and not user input +func ParseProviderLocationIDInsensitively(input string) (*ProviderLocationId, error) { + parser := resourceids.NewParserFromResourceIdType(ProviderLocationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProviderLocationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ProviderLocationId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.LocationName, ok = input.Parsed["locationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "locationName", input) + } + + return nil +} + +// ValidateProviderLocationID checks that 'input' can be parsed as a Provider Location ID +func ValidateProviderLocationID(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 := ParseProviderLocationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Provider Location ID +func (id ProviderLocationId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DataProtection/locations/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.LocationName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Provider Location ID +func (id ProviderLocationId) 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("staticMicrosoftDataProtection", "Microsoft.DataProtection", "Microsoft.DataProtection"), + resourceids.StaticSegment("staticLocations", "locations", "locations"), + resourceids.UserSpecifiedSegment("locationName", "locationValue"), + } +} + +// String returns a human-readable description of this Provider Location ID +func (id ProviderLocationId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Location Name: %q", id.LocationName), + } + return fmt.Sprintf("Provider Location (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/dataprotection/2023-11-01/dppjob/id_providerlocation_test.go b/resource-manager/dataprotection/2023-11-01/dppjob/id_providerlocation_test.go new file mode 100644 index 00000000000..20070ad4078 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/dppjob/id_providerlocation_test.go @@ -0,0 +1,282 @@ +package dppjob + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = ProviderLocationId{} + +func TestNewProviderLocationID(t *testing.T) { + id := NewProviderLocationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.LocationName != "locationValue" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationValue") + } +} + +func TestFormatProviderLocationID(t *testing.T) { + actual := NewProviderLocationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/locations/locationValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProviderLocationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProviderLocationId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/locations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/locations/locationValue", + Expected: &ProviderLocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/locations/locationValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProviderLocationID(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.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + } +} + +func TestParseProviderLocationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProviderLocationId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/lOcAtIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/locations/locationValue", + Expected: &ProviderLocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/locations/locationValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/lOcAtIoNs/lOcAtIoNvAlUe", + Expected: &ProviderLocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + LocationName: "lOcAtIoNvAlUe", + }, + }, + { + // 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.dAtApRoTeCtIoN/lOcAtIoNs/lOcAtIoNvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProviderLocationIDInsensitively(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.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + } +} + +func TestSegmentsForProviderLocationId(t *testing.T) { + segments := ProviderLocationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ProviderLocationId 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/dataprotection/2023-11-01/dppjob/method_fetchcrossregionrestorejobget.go b/resource-manager/dataprotection/2023-11-01/dppjob/method_fetchcrossregionrestorejobget.go new file mode 100644 index 00000000000..417d10bedca --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/dppjob/method_fetchcrossregionrestorejobget.go @@ -0,0 +1,56 @@ +package dppjob + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FetchCrossRegionRestoreJobGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AzureBackupJobResource +} + +// FetchCrossRegionRestoreJobGet ... +func (c DppJobClient) FetchCrossRegionRestoreJobGet(ctx context.Context, id ProviderLocationId, input CrossRegionRestoreJobRequest) (result FetchCrossRegionRestoreJobGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/fetchCrossRegionRestoreJob", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/dataprotection/2023-11-01/dppjob/method_fetchcrossregionrestorejobslist.go b/resource-manager/dataprotection/2023-11-01/dppjob/method_fetchcrossregionrestorejobslist.go new file mode 100644 index 00000000000..0557cf02c26 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/dppjob/method_fetchcrossregionrestorejobslist.go @@ -0,0 +1,117 @@ +package dppjob + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FetchCrossRegionRestoreJobsListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]AzureBackupJobResource +} + +type FetchCrossRegionRestoreJobsListCompleteResult struct { + Items []AzureBackupJobResource +} + +type FetchCrossRegionRestoreJobsListOperationOptions struct { + Filter *string +} + +func DefaultFetchCrossRegionRestoreJobsListOperationOptions() FetchCrossRegionRestoreJobsListOperationOptions { + return FetchCrossRegionRestoreJobsListOperationOptions{} +} + +func (o FetchCrossRegionRestoreJobsListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o FetchCrossRegionRestoreJobsListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o FetchCrossRegionRestoreJobsListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + return &out +} + +// FetchCrossRegionRestoreJobsList ... +func (c DppJobClient) FetchCrossRegionRestoreJobsList(ctx context.Context, id ProviderLocationId, input CrossRegionRestoreJobsRequest, options FetchCrossRegionRestoreJobsListOperationOptions) (result FetchCrossRegionRestoreJobsListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/fetchCrossRegionRestoreJobs", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]AzureBackupJobResource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// FetchCrossRegionRestoreJobsListComplete retrieves all the results into a single object +func (c DppJobClient) FetchCrossRegionRestoreJobsListComplete(ctx context.Context, id ProviderLocationId, input CrossRegionRestoreJobsRequest, options FetchCrossRegionRestoreJobsListOperationOptions) (FetchCrossRegionRestoreJobsListCompleteResult, error) { + return c.FetchCrossRegionRestoreJobsListCompleteMatchingPredicate(ctx, id, input, options, AzureBackupJobResourceOperationPredicate{}) +} + +// FetchCrossRegionRestoreJobsListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DppJobClient) FetchCrossRegionRestoreJobsListCompleteMatchingPredicate(ctx context.Context, id ProviderLocationId, input CrossRegionRestoreJobsRequest, options FetchCrossRegionRestoreJobsListOperationOptions, predicate AzureBackupJobResourceOperationPredicate) (result FetchCrossRegionRestoreJobsListCompleteResult, err error) { + items := make([]AzureBackupJobResource, 0) + + resp, err := c.FetchCrossRegionRestoreJobsList(ctx, id, input, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = FetchCrossRegionRestoreJobsListCompleteResult{ + Items: items, + } + return +} diff --git a/resource-manager/dataprotection/2023-11-01/dppjob/model_azurebackupjob.go b/resource-manager/dataprotection/2023-11-01/dppjob/model_azurebackupjob.go new file mode 100644 index 00000000000..65be91508fc --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/dppjob/model_azurebackupjob.go @@ -0,0 +1,65 @@ +package dppjob + +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 AzureBackupJob struct { + ActivityID string `json:"activityID"` + BackupInstanceFriendlyName string `json:"backupInstanceFriendlyName"` + BackupInstanceId *string `json:"backupInstanceId,omitempty"` + DataSourceId string `json:"dataSourceId"` + DataSourceLocation string `json:"dataSourceLocation"` + DataSourceName string `json:"dataSourceName"` + DataSourceSetName *string `json:"dataSourceSetName,omitempty"` + DataSourceType string `json:"dataSourceType"` + DestinationDataStoreName *string `json:"destinationDataStoreName,omitempty"` + Duration *string `json:"duration,omitempty"` + EndTime *string `json:"endTime,omitempty"` + ErrorDetails *[]UserFacingError `json:"errorDetails,omitempty"` + Etag *string `json:"etag,omitempty"` + ExtendedInfo *JobExtendedInfo `json:"extendedInfo,omitempty"` + IsUserTriggered bool `json:"isUserTriggered"` + Operation string `json:"operation"` + OperationCategory string `json:"operationCategory"` + PolicyId *string `json:"policyId,omitempty"` + PolicyName *string `json:"policyName,omitempty"` + ProgressEnabled bool `json:"progressEnabled"` + ProgressUrl *string `json:"progressUrl,omitempty"` + RehydrationPriority *string `json:"rehydrationPriority,omitempty"` + RestoreType *string `json:"restoreType,omitempty"` + SourceDataStoreName *string `json:"sourceDataStoreName,omitempty"` + SourceResourceGroup string `json:"sourceResourceGroup"` + SourceSubscriptionID string `json:"sourceSubscriptionID"` + StartTime string `json:"startTime"` + Status string `json:"status"` + SubscriptionId string `json:"subscriptionId"` + SupportedActions []string `json:"supportedActions"` + VaultName string `json:"vaultName"` +} + +func (o *AzureBackupJob) GetEndTimeAsTime() (*time.Time, error) { + if o.EndTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EndTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureBackupJob) SetEndTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EndTime = &formatted +} + +func (o *AzureBackupJob) GetStartTimeAsTime() (*time.Time, error) { + return dates.ParseAsFormat(&o.StartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureBackupJob) SetStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartTime = formatted +} diff --git a/resource-manager/dataprotection/2023-11-01/dppjob/model_azurebackupjobresource.go b/resource-manager/dataprotection/2023-11-01/dppjob/model_azurebackupjobresource.go new file mode 100644 index 00000000000..51c24fa7f16 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/dppjob/model_azurebackupjobresource.go @@ -0,0 +1,16 @@ +package dppjob + +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 AzureBackupJobResource struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *AzureBackupJob `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/dataprotection/2023-11-01/dppjob/model_crossregionrestorejobrequest.go b/resource-manager/dataprotection/2023-11-01/dppjob/model_crossregionrestorejobrequest.go new file mode 100644 index 00000000000..a1c23f023e2 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/dppjob/model_crossregionrestorejobrequest.go @@ -0,0 +1,10 @@ +package dppjob + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CrossRegionRestoreJobRequest struct { + JobId string `json:"jobId"` + SourceBackupVaultId string `json:"sourceBackupVaultId"` + SourceRegion string `json:"sourceRegion"` +} diff --git a/resource-manager/dataprotection/2023-11-01/dppjob/model_crossregionrestorejobsrequest.go b/resource-manager/dataprotection/2023-11-01/dppjob/model_crossregionrestorejobsrequest.go new file mode 100644 index 00000000000..a75015188e1 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/dppjob/model_crossregionrestorejobsrequest.go @@ -0,0 +1,9 @@ +package dppjob + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CrossRegionRestoreJobsRequest struct { + SourceBackupVaultId string `json:"sourceBackupVaultId"` + SourceRegion string `json:"sourceRegion"` +} diff --git a/resource-manager/dataprotection/2023-11-01/dppjob/model_innererror.go b/resource-manager/dataprotection/2023-11-01/dppjob/model_innererror.go new file mode 100644 index 00000000000..cc4341695b4 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/dppjob/model_innererror.go @@ -0,0 +1,10 @@ +package dppjob + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type InnerError struct { + AdditionalInfo *map[string]string `json:"additionalInfo,omitempty"` + Code *string `json:"code,omitempty"` + EmbeddedInnerError *InnerError `json:"embeddedInnerError,omitempty"` +} diff --git a/resource-manager/dataprotection/2023-11-01/dppjob/model_jobextendedinfo.go b/resource-manager/dataprotection/2023-11-01/dppjob/model_jobextendedinfo.go new file mode 100644 index 00000000000..92a9c42ff56 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/dppjob/model_jobextendedinfo.go @@ -0,0 +1,15 @@ +package dppjob + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobExtendedInfo struct { + AdditionalDetails *map[string]string `json:"additionalDetails,omitempty"` + BackupInstanceState *string `json:"backupInstanceState,omitempty"` + DataTransferredInBytes *float64 `json:"dataTransferredInBytes,omitempty"` + RecoveryDestination *string `json:"recoveryDestination,omitempty"` + SourceRecoverPoint *RestoreJobRecoveryPointDetails `json:"sourceRecoverPoint,omitempty"` + SubTasks *[]JobSubTask `json:"subTasks,omitempty"` + TargetRecoverPoint *RestoreJobRecoveryPointDetails `json:"targetRecoverPoint,omitempty"` + WarningDetails *[]UserFacingWarningDetail `json:"warningDetails,omitempty"` +} diff --git a/resource-manager/dataprotection/2023-11-01/dppjob/model_jobsubtask.go b/resource-manager/dataprotection/2023-11-01/dppjob/model_jobsubtask.go new file mode 100644 index 00000000000..e329c0eadda --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/dppjob/model_jobsubtask.go @@ -0,0 +1,12 @@ +package dppjob + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobSubTask struct { + AdditionalDetails *map[string]string `json:"additionalDetails,omitempty"` + TaskId int64 `json:"taskId"` + TaskName string `json:"taskName"` + TaskProgress *string `json:"taskProgress,omitempty"` + TaskStatus string `json:"taskStatus"` +} diff --git a/resource-manager/dataprotection/2023-11-01/dppjob/model_restorejobrecoverypointdetails.go b/resource-manager/dataprotection/2023-11-01/dppjob/model_restorejobrecoverypointdetails.go new file mode 100644 index 00000000000..10f708f3acd --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/dppjob/model_restorejobrecoverypointdetails.go @@ -0,0 +1,27 @@ +package dppjob + +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 RestoreJobRecoveryPointDetails struct { + RecoveryPointID *string `json:"recoveryPointID,omitempty"` + RecoveryPointTime *string `json:"recoveryPointTime,omitempty"` +} + +func (o *RestoreJobRecoveryPointDetails) GetRecoveryPointTimeAsTime() (*time.Time, error) { + if o.RecoveryPointTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.RecoveryPointTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *RestoreJobRecoveryPointDetails) SetRecoveryPointTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.RecoveryPointTime = &formatted +} diff --git a/resource-manager/dataprotection/2023-11-01/dppjob/model_userfacingerror.go b/resource-manager/dataprotection/2023-11-01/dppjob/model_userfacingerror.go new file mode 100644 index 00000000000..d2f0c3f3043 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/dppjob/model_userfacingerror.go @@ -0,0 +1,16 @@ +package dppjob + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UserFacingError struct { + Code *string `json:"code,omitempty"` + Details *[]UserFacingError `json:"details,omitempty"` + InnerError *InnerError `json:"innerError,omitempty"` + IsRetryable *bool `json:"isRetryable,omitempty"` + IsUserError *bool `json:"isUserError,omitempty"` + Message *string `json:"message,omitempty"` + Properties *map[string]string `json:"properties,omitempty"` + RecommendedAction *[]string `json:"recommendedAction,omitempty"` + Target *string `json:"target,omitempty"` +} diff --git a/resource-manager/dataprotection/2023-11-01/dppjob/model_userfacingwarningdetail.go b/resource-manager/dataprotection/2023-11-01/dppjob/model_userfacingwarningdetail.go new file mode 100644 index 00000000000..f398426c80d --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/dppjob/model_userfacingwarningdetail.go @@ -0,0 +1,9 @@ +package dppjob + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UserFacingWarningDetail struct { + ResourceName *string `json:"resourceName,omitempty"` + Warning UserFacingError `json:"warning"` +} diff --git a/resource-manager/dataprotection/2023-11-01/dppjob/predicates.go b/resource-manager/dataprotection/2023-11-01/dppjob/predicates.go new file mode 100644 index 00000000000..3a5fc03f205 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/dppjob/predicates.go @@ -0,0 +1,27 @@ +package dppjob + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureBackupJobResourceOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p AzureBackupJobResourceOperationPredicate) Matches(input AzureBackupJobResource) 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/dataprotection/2023-11-01/dppjob/version.go b/resource-manager/dataprotection/2023-11-01/dppjob/version.go new file mode 100644 index 00000000000..78e84edb5f1 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/dppjob/version.go @@ -0,0 +1,12 @@ +package dppjob + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-11-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/dppjob/%s", defaultApiVersion) +} diff --git a/resource-manager/dataprotection/2023-11-01/dppresourceguardproxies/README.md b/resource-manager/dataprotection/2023-11-01/dppresourceguardproxies/README.md new file mode 100644 index 00000000000..0a40e874e0d --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/dppresourceguardproxies/README.md @@ -0,0 +1,111 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2023-11-01/dppresourceguardproxies` Documentation + +The `dppresourceguardproxies` SDK allows for interaction with the Azure Resource Manager Service `dataprotection` (API Version `2023-11-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2023-11-01/dppresourceguardproxies" +``` + + +### Client Initialization + +```go +client := dppresourceguardproxies.NewDppResourceGuardProxiesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DppResourceGuardProxiesClient.DppResourceGuardProxyCreateOrUpdate` + +```go +ctx := context.TODO() +id := dppresourceguardproxies.NewBackupResourceGuardProxyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultValue", "backupResourceGuardProxyValue") + +payload := dppresourceguardproxies.ResourceGuardProxyBaseResource{ + // ... +} + + +read, err := client.DppResourceGuardProxyCreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DppResourceGuardProxiesClient.DppResourceGuardProxyDelete` + +```go +ctx := context.TODO() +id := dppresourceguardproxies.NewBackupResourceGuardProxyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultValue", "backupResourceGuardProxyValue") + +read, err := client.DppResourceGuardProxyDelete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DppResourceGuardProxiesClient.DppResourceGuardProxyGet` + +```go +ctx := context.TODO() +id := dppresourceguardproxies.NewBackupResourceGuardProxyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultValue", "backupResourceGuardProxyValue") + +read, err := client.DppResourceGuardProxyGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DppResourceGuardProxiesClient.DppResourceGuardProxyList` + +```go +ctx := context.TODO() +id := dppresourceguardproxies.NewBackupVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultValue") + +// alternatively `client.DppResourceGuardProxyList(ctx, id)` can be used to do batched pagination +items, err := client.DppResourceGuardProxyListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `DppResourceGuardProxiesClient.DppResourceGuardProxyUnlockDelete` + +```go +ctx := context.TODO() +id := dppresourceguardproxies.NewBackupResourceGuardProxyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultValue", "backupResourceGuardProxyValue") + +payload := dppresourceguardproxies.UnlockDeleteRequest{ + // ... +} + + +read, err := client.DppResourceGuardProxyUnlockDelete(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/dataprotection/2023-11-01/dppresourceguardproxies/client.go b/resource-manager/dataprotection/2023-11-01/dppresourceguardproxies/client.go new file mode 100644 index 00000000000..f44efd92c08 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/dppresourceguardproxies/client.go @@ -0,0 +1,26 @@ +package dppresourceguardproxies + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DppResourceGuardProxiesClient struct { + Client *resourcemanager.Client +} + +func NewDppResourceGuardProxiesClientWithBaseURI(sdkApi sdkEnv.Api) (*DppResourceGuardProxiesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "dppresourceguardproxies", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DppResourceGuardProxiesClient: %+v", err) + } + + return &DppResourceGuardProxiesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/dataprotection/2023-11-01/dppresourceguardproxies/id_backupresourceguardproxy.go b/resource-manager/dataprotection/2023-11-01/dppresourceguardproxies/id_backupresourceguardproxy.go new file mode 100644 index 00000000000..731225b9808 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/dppresourceguardproxies/id_backupresourceguardproxy.go @@ -0,0 +1,134 @@ +package dppresourceguardproxies + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = BackupResourceGuardProxyId{} + +// BackupResourceGuardProxyId is a struct representing the Resource ID for a Backup Resource Guard Proxy +type BackupResourceGuardProxyId struct { + SubscriptionId string + ResourceGroupName string + BackupVaultName string + BackupResourceGuardProxyName string +} + +// NewBackupResourceGuardProxyID returns a new BackupResourceGuardProxyId struct +func NewBackupResourceGuardProxyID(subscriptionId string, resourceGroupName string, backupVaultName string, backupResourceGuardProxyName string) BackupResourceGuardProxyId { + return BackupResourceGuardProxyId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + BackupVaultName: backupVaultName, + BackupResourceGuardProxyName: backupResourceGuardProxyName, + } +} + +// ParseBackupResourceGuardProxyID parses 'input' into a BackupResourceGuardProxyId +func ParseBackupResourceGuardProxyID(input string) (*BackupResourceGuardProxyId, error) { + parser := resourceids.NewParserFromResourceIdType(BackupResourceGuardProxyId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BackupResourceGuardProxyId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseBackupResourceGuardProxyIDInsensitively parses 'input' case-insensitively into a BackupResourceGuardProxyId +// note: this method should only be used for API response data and not user input +func ParseBackupResourceGuardProxyIDInsensitively(input string) (*BackupResourceGuardProxyId, error) { + parser := resourceids.NewParserFromResourceIdType(BackupResourceGuardProxyId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BackupResourceGuardProxyId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *BackupResourceGuardProxyId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.BackupVaultName, ok = input.Parsed["backupVaultName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "backupVaultName", input) + } + + if id.BackupResourceGuardProxyName, ok = input.Parsed["backupResourceGuardProxyName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "backupResourceGuardProxyName", input) + } + + return nil +} + +// ValidateBackupResourceGuardProxyID checks that 'input' can be parsed as a Backup Resource Guard Proxy ID +func ValidateBackupResourceGuardProxyID(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 := ParseBackupResourceGuardProxyID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Backup Resource Guard Proxy ID +func (id BackupResourceGuardProxyId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DataProtection/backupVaults/%s/backupResourceGuardProxies/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.BackupVaultName, id.BackupResourceGuardProxyName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Backup Resource Guard Proxy ID +func (id BackupResourceGuardProxyId) 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("staticMicrosoftDataProtection", "Microsoft.DataProtection", "Microsoft.DataProtection"), + resourceids.StaticSegment("staticBackupVaults", "backupVaults", "backupVaults"), + resourceids.UserSpecifiedSegment("backupVaultName", "backupVaultValue"), + resourceids.StaticSegment("staticBackupResourceGuardProxies", "backupResourceGuardProxies", "backupResourceGuardProxies"), + resourceids.UserSpecifiedSegment("backupResourceGuardProxyName", "backupResourceGuardProxyValue"), + } +} + +// String returns a human-readable description of this Backup Resource Guard Proxy ID +func (id BackupResourceGuardProxyId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Backup Vault Name: %q", id.BackupVaultName), + fmt.Sprintf("Backup Resource Guard Proxy Name: %q", id.BackupResourceGuardProxyName), + } + return fmt.Sprintf("Backup Resource Guard Proxy (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/dataprotection/2023-11-01/dppresourceguardproxies/id_backupresourceguardproxy_test.go b/resource-manager/dataprotection/2023-11-01/dppresourceguardproxies/id_backupresourceguardproxy_test.go new file mode 100644 index 00000000000..fc400d13146 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/dppresourceguardproxies/id_backupresourceguardproxy_test.go @@ -0,0 +1,327 @@ +package dppresourceguardproxies + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = BackupResourceGuardProxyId{} + +func TestNewBackupResourceGuardProxyID(t *testing.T) { + id := NewBackupResourceGuardProxyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultValue", "backupResourceGuardProxyValue") + + 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.BackupVaultName != "backupVaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'BackupVaultName'", id.BackupVaultName, "backupVaultValue") + } + + if id.BackupResourceGuardProxyName != "backupResourceGuardProxyValue" { + t.Fatalf("Expected %q but got %q for Segment 'BackupResourceGuardProxyName'", id.BackupResourceGuardProxyName, "backupResourceGuardProxyValue") + } +} + +func TestFormatBackupResourceGuardProxyID(t *testing.T) { + actual := NewBackupResourceGuardProxyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultValue", "backupResourceGuardProxyValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/backupResourceGuardProxies/backupResourceGuardProxyValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseBackupResourceGuardProxyID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BackupResourceGuardProxyId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/backupResourceGuardProxies", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/backupResourceGuardProxies/backupResourceGuardProxyValue", + Expected: &BackupResourceGuardProxyId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + BackupVaultName: "backupVaultValue", + BackupResourceGuardProxyName: "backupResourceGuardProxyValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/backupResourceGuardProxies/backupResourceGuardProxyValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBackupResourceGuardProxyID(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.BackupVaultName != v.Expected.BackupVaultName { + t.Fatalf("Expected %q but got %q for BackupVaultName", v.Expected.BackupVaultName, actual.BackupVaultName) + } + + if actual.BackupResourceGuardProxyName != v.Expected.BackupResourceGuardProxyName { + t.Fatalf("Expected %q but got %q for BackupResourceGuardProxyName", v.Expected.BackupResourceGuardProxyName, actual.BackupResourceGuardProxyName) + } + + } +} + +func TestParseBackupResourceGuardProxyIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BackupResourceGuardProxyId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/backupResourceGuardProxies", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtVaLuE/bAcKuPrEsOuRcEgUaRdPrOxIeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/backupResourceGuardProxies/backupResourceGuardProxyValue", + Expected: &BackupResourceGuardProxyId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + BackupVaultName: "backupVaultValue", + BackupResourceGuardProxyName: "backupResourceGuardProxyValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/backupResourceGuardProxies/backupResourceGuardProxyValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtVaLuE/bAcKuPrEsOuRcEgUaRdPrOxIeS/bAcKuPrEsOuRcEgUaRdPrOxYvAlUe", + Expected: &BackupResourceGuardProxyId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + BackupVaultName: "bAcKuPvAuLtVaLuE", + BackupResourceGuardProxyName: "bAcKuPrEsOuRcEgUaRdPrOxYvAlUe", + }, + }, + { + // 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.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtVaLuE/bAcKuPrEsOuRcEgUaRdPrOxIeS/bAcKuPrEsOuRcEgUaRdPrOxYvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBackupResourceGuardProxyIDInsensitively(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.BackupVaultName != v.Expected.BackupVaultName { + t.Fatalf("Expected %q but got %q for BackupVaultName", v.Expected.BackupVaultName, actual.BackupVaultName) + } + + if actual.BackupResourceGuardProxyName != v.Expected.BackupResourceGuardProxyName { + t.Fatalf("Expected %q but got %q for BackupResourceGuardProxyName", v.Expected.BackupResourceGuardProxyName, actual.BackupResourceGuardProxyName) + } + + } +} + +func TestSegmentsForBackupResourceGuardProxyId(t *testing.T) { + segments := BackupResourceGuardProxyId{}.Segments() + if len(segments) == 0 { + t.Fatalf("BackupResourceGuardProxyId 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/dataprotection/2023-11-01/dppresourceguardproxies/id_backupvault.go b/resource-manager/dataprotection/2023-11-01/dppresourceguardproxies/id_backupvault.go new file mode 100644 index 00000000000..fa090742191 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/dppresourceguardproxies/id_backupvault.go @@ -0,0 +1,125 @@ +package dppresourceguardproxies + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = BackupVaultId{} + +// BackupVaultId is a struct representing the Resource ID for a Backup Vault +type BackupVaultId struct { + SubscriptionId string + ResourceGroupName string + BackupVaultName string +} + +// NewBackupVaultID returns a new BackupVaultId struct +func NewBackupVaultID(subscriptionId string, resourceGroupName string, backupVaultName string) BackupVaultId { + return BackupVaultId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + BackupVaultName: backupVaultName, + } +} + +// ParseBackupVaultID parses 'input' into a BackupVaultId +func ParseBackupVaultID(input string) (*BackupVaultId, error) { + parser := resourceids.NewParserFromResourceIdType(BackupVaultId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BackupVaultId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseBackupVaultIDInsensitively parses 'input' case-insensitively into a BackupVaultId +// note: this method should only be used for API response data and not user input +func ParseBackupVaultIDInsensitively(input string) (*BackupVaultId, error) { + parser := resourceids.NewParserFromResourceIdType(BackupVaultId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BackupVaultId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *BackupVaultId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.BackupVaultName, ok = input.Parsed["backupVaultName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "backupVaultName", input) + } + + return nil +} + +// ValidateBackupVaultID checks that 'input' can be parsed as a Backup Vault ID +func ValidateBackupVaultID(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 := ParseBackupVaultID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Backup Vault ID +func (id BackupVaultId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DataProtection/backupVaults/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.BackupVaultName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Backup Vault ID +func (id BackupVaultId) 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("staticMicrosoftDataProtection", "Microsoft.DataProtection", "Microsoft.DataProtection"), + resourceids.StaticSegment("staticBackupVaults", "backupVaults", "backupVaults"), + resourceids.UserSpecifiedSegment("backupVaultName", "backupVaultValue"), + } +} + +// String returns a human-readable description of this Backup Vault ID +func (id BackupVaultId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Backup Vault Name: %q", id.BackupVaultName), + } + return fmt.Sprintf("Backup Vault (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/dataprotection/2023-11-01/dppresourceguardproxies/id_backupvault_test.go b/resource-manager/dataprotection/2023-11-01/dppresourceguardproxies/id_backupvault_test.go new file mode 100644 index 00000000000..867550d6df3 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/dppresourceguardproxies/id_backupvault_test.go @@ -0,0 +1,282 @@ +package dppresourceguardproxies + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = BackupVaultId{} + +func TestNewBackupVaultID(t *testing.T) { + id := NewBackupVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultValue") + + 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.BackupVaultName != "backupVaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'BackupVaultName'", id.BackupVaultName, "backupVaultValue") + } +} + +func TestFormatBackupVaultID(t *testing.T) { + actual := NewBackupVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseBackupVaultID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BackupVaultId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue", + Expected: &BackupVaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + BackupVaultName: "backupVaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBackupVaultID(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.BackupVaultName != v.Expected.BackupVaultName { + t.Fatalf("Expected %q but got %q for BackupVaultName", v.Expected.BackupVaultName, actual.BackupVaultName) + } + + } +} + +func TestParseBackupVaultIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BackupVaultId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue", + Expected: &BackupVaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + BackupVaultName: "backupVaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtVaLuE", + Expected: &BackupVaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + BackupVaultName: "bAcKuPvAuLtVaLuE", + }, + }, + { + // 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.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBackupVaultIDInsensitively(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.BackupVaultName != v.Expected.BackupVaultName { + t.Fatalf("Expected %q but got %q for BackupVaultName", v.Expected.BackupVaultName, actual.BackupVaultName) + } + + } +} + +func TestSegmentsForBackupVaultId(t *testing.T) { + segments := BackupVaultId{}.Segments() + if len(segments) == 0 { + t.Fatalf("BackupVaultId 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/dataprotection/2023-11-01/dppresourceguardproxies/method_dppresourceguardproxycreateorupdate.go b/resource-manager/dataprotection/2023-11-01/dppresourceguardproxies/method_dppresourceguardproxycreateorupdate.go new file mode 100644 index 00000000000..e4dbcdf8ed6 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/dppresourceguardproxies/method_dppresourceguardproxycreateorupdate.go @@ -0,0 +1,55 @@ +package dppresourceguardproxies + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DppResourceGuardProxyCreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ResourceGuardProxyBaseResource +} + +// DppResourceGuardProxyCreateOrUpdate ... +func (c DppResourceGuardProxiesClient) DppResourceGuardProxyCreateOrUpdate(ctx context.Context, id BackupResourceGuardProxyId, input ResourceGuardProxyBaseResource) (result DppResourceGuardProxyCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/dataprotection/2023-11-01/dppresourceguardproxies/method_dppresourceguardproxydelete.go b/resource-manager/dataprotection/2023-11-01/dppresourceguardproxies/method_dppresourceguardproxydelete.go new file mode 100644 index 00000000000..86075b7794f --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/dppresourceguardproxies/method_dppresourceguardproxydelete.go @@ -0,0 +1,47 @@ +package dppresourceguardproxies + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DppResourceGuardProxyDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// DppResourceGuardProxyDelete ... +func (c DppResourceGuardProxiesClient) DppResourceGuardProxyDelete(ctx context.Context, id BackupResourceGuardProxyId) (result DppResourceGuardProxyDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/dataprotection/2023-11-01/dppresourceguardproxies/method_dppresourceguardproxyget.go b/resource-manager/dataprotection/2023-11-01/dppresourceguardproxies/method_dppresourceguardproxyget.go new file mode 100644 index 00000000000..dbd3ed01970 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/dppresourceguardproxies/method_dppresourceguardproxyget.go @@ -0,0 +1,51 @@ +package dppresourceguardproxies + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DppResourceGuardProxyGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ResourceGuardProxyBaseResource +} + +// DppResourceGuardProxyGet ... +func (c DppResourceGuardProxiesClient) DppResourceGuardProxyGet(ctx context.Context, id BackupResourceGuardProxyId) (result DppResourceGuardProxyGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/dataprotection/2023-11-01/dppresourceguardproxies/method_dppresourceguardproxylist.go b/resource-manager/dataprotection/2023-11-01/dppresourceguardproxies/method_dppresourceguardproxylist.go new file mode 100644 index 00000000000..ce0f2d74e2e --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/dppresourceguardproxies/method_dppresourceguardproxylist.go @@ -0,0 +1,89 @@ +package dppresourceguardproxies + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DppResourceGuardProxyListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ResourceGuardProxyBaseResource +} + +type DppResourceGuardProxyListCompleteResult struct { + Items []ResourceGuardProxyBaseResource +} + +// DppResourceGuardProxyList ... +func (c DppResourceGuardProxiesClient) DppResourceGuardProxyList(ctx context.Context, id BackupVaultId) (result DppResourceGuardProxyListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/backupResourceGuardProxies", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]ResourceGuardProxyBaseResource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// DppResourceGuardProxyListComplete retrieves all the results into a single object +func (c DppResourceGuardProxiesClient) DppResourceGuardProxyListComplete(ctx context.Context, id BackupVaultId) (DppResourceGuardProxyListCompleteResult, error) { + return c.DppResourceGuardProxyListCompleteMatchingPredicate(ctx, id, ResourceGuardProxyBaseResourceOperationPredicate{}) +} + +// DppResourceGuardProxyListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DppResourceGuardProxiesClient) DppResourceGuardProxyListCompleteMatchingPredicate(ctx context.Context, id BackupVaultId, predicate ResourceGuardProxyBaseResourceOperationPredicate) (result DppResourceGuardProxyListCompleteResult, err error) { + items := make([]ResourceGuardProxyBaseResource, 0) + + resp, err := c.DppResourceGuardProxyList(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = DppResourceGuardProxyListCompleteResult{ + Items: items, + } + return +} diff --git a/resource-manager/dataprotection/2023-11-01/dppresourceguardproxies/method_dppresourceguardproxyunlockdelete.go b/resource-manager/dataprotection/2023-11-01/dppresourceguardproxies/method_dppresourceguardproxyunlockdelete.go new file mode 100644 index 00000000000..31e6fa8e17d --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/dppresourceguardproxies/method_dppresourceguardproxyunlockdelete.go @@ -0,0 +1,56 @@ +package dppresourceguardproxies + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DppResourceGuardProxyUnlockDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *UnlockDeleteResponse +} + +// DppResourceGuardProxyUnlockDelete ... +func (c DppResourceGuardProxiesClient) DppResourceGuardProxyUnlockDelete(ctx context.Context, id BackupResourceGuardProxyId, input UnlockDeleteRequest) (result DppResourceGuardProxyUnlockDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/unlockDelete", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/dataprotection/2023-11-01/dppresourceguardproxies/model_resourceguardoperationdetail.go b/resource-manager/dataprotection/2023-11-01/dppresourceguardproxies/model_resourceguardoperationdetail.go new file mode 100644 index 00000000000..6540ed78351 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/dppresourceguardproxies/model_resourceguardoperationdetail.go @@ -0,0 +1,9 @@ +package dppresourceguardproxies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceGuardOperationDetail struct { + DefaultResourceRequest *string `json:"defaultResourceRequest,omitempty"` + VaultCriticalOperation *string `json:"vaultCriticalOperation,omitempty"` +} diff --git a/resource-manager/dataprotection/2023-11-01/dppresourceguardproxies/model_resourceguardproxybase.go b/resource-manager/dataprotection/2023-11-01/dppresourceguardproxies/model_resourceguardproxybase.go new file mode 100644 index 00000000000..d752010f8cc --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/dppresourceguardproxies/model_resourceguardproxybase.go @@ -0,0 +1,11 @@ +package dppresourceguardproxies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceGuardProxyBase struct { + Description *string `json:"description,omitempty"` + LastUpdatedTime *string `json:"lastUpdatedTime,omitempty"` + ResourceGuardOperationDetails *[]ResourceGuardOperationDetail `json:"resourceGuardOperationDetails,omitempty"` + ResourceGuardResourceId *string `json:"resourceGuardResourceId,omitempty"` +} diff --git a/resource-manager/dataprotection/2023-11-01/dppresourceguardproxies/model_resourceguardproxybaseresource.go b/resource-manager/dataprotection/2023-11-01/dppresourceguardproxies/model_resourceguardproxybaseresource.go new file mode 100644 index 00000000000..4e6713c4856 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/dppresourceguardproxies/model_resourceguardproxybaseresource.go @@ -0,0 +1,16 @@ +package dppresourceguardproxies + +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 ResourceGuardProxyBaseResource struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ResourceGuardProxyBase `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/dataprotection/2023-11-01/dppresourceguardproxies/model_unlockdeleterequest.go b/resource-manager/dataprotection/2023-11-01/dppresourceguardproxies/model_unlockdeleterequest.go new file mode 100644 index 00000000000..e5415cf7db3 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/dppresourceguardproxies/model_unlockdeleterequest.go @@ -0,0 +1,9 @@ +package dppresourceguardproxies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UnlockDeleteRequest struct { + ResourceGuardOperationRequests *[]string `json:"resourceGuardOperationRequests,omitempty"` + ResourceToBeDeleted *string `json:"resourceToBeDeleted,omitempty"` +} diff --git a/resource-manager/dataprotection/2023-11-01/dppresourceguardproxies/model_unlockdeleteresponse.go b/resource-manager/dataprotection/2023-11-01/dppresourceguardproxies/model_unlockdeleteresponse.go new file mode 100644 index 00000000000..408d1ec0fc8 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/dppresourceguardproxies/model_unlockdeleteresponse.go @@ -0,0 +1,8 @@ +package dppresourceguardproxies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UnlockDeleteResponse struct { + UnlockDeleteExpiryTime *string `json:"unlockDeleteExpiryTime,omitempty"` +} diff --git a/resource-manager/dataprotection/2023-11-01/dppresourceguardproxies/predicates.go b/resource-manager/dataprotection/2023-11-01/dppresourceguardproxies/predicates.go new file mode 100644 index 00000000000..6da3b96156e --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/dppresourceguardproxies/predicates.go @@ -0,0 +1,27 @@ +package dppresourceguardproxies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceGuardProxyBaseResourceOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ResourceGuardProxyBaseResourceOperationPredicate) Matches(input ResourceGuardProxyBaseResource) 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/dataprotection/2023-11-01/dppresourceguardproxies/version.go b/resource-manager/dataprotection/2023-11-01/dppresourceguardproxies/version.go new file mode 100644 index 00000000000..55d829af2d3 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/dppresourceguardproxies/version.go @@ -0,0 +1,12 @@ +package dppresourceguardproxies + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-11-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/dppresourceguardproxies/%s", defaultApiVersion) +} diff --git a/resource-manager/dataprotection/2023-11-01/fetchsecondaryrecoverypoints/README.md b/resource-manager/dataprotection/2023-11-01/fetchsecondaryrecoverypoints/README.md new file mode 100644 index 00000000000..161e902de02 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/fetchsecondaryrecoverypoints/README.md @@ -0,0 +1,42 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2023-11-01/fetchsecondaryrecoverypoints` Documentation + +The `fetchsecondaryrecoverypoints` SDK allows for interaction with the Azure Resource Manager Service `dataprotection` (API Version `2023-11-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2023-11-01/fetchsecondaryrecoverypoints" +``` + + +### Client Initialization + +```go +client := fetchsecondaryrecoverypoints.NewFetchSecondaryRecoveryPointsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `FetchSecondaryRecoveryPointsClient.List` + +```go +ctx := context.TODO() +id := fetchsecondaryrecoverypoints.NewProviderLocationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationValue") + +payload := fetchsecondaryrecoverypoints.FetchSecondaryRPsRequestParameters{ + // ... +} + + +// alternatively `client.List(ctx, id, payload, fetchsecondaryrecoverypoints.DefaultListOperationOptions())` can be used to do batched pagination +items, err := client.ListComplete(ctx, id, payload, fetchsecondaryrecoverypoints.DefaultListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/dataprotection/2023-11-01/fetchsecondaryrecoverypoints/client.go b/resource-manager/dataprotection/2023-11-01/fetchsecondaryrecoverypoints/client.go new file mode 100644 index 00000000000..0ac726e9656 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/fetchsecondaryrecoverypoints/client.go @@ -0,0 +1,26 @@ +package fetchsecondaryrecoverypoints + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FetchSecondaryRecoveryPointsClient struct { + Client *resourcemanager.Client +} + +func NewFetchSecondaryRecoveryPointsClientWithBaseURI(sdkApi sdkEnv.Api) (*FetchSecondaryRecoveryPointsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "fetchsecondaryrecoverypoints", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating FetchSecondaryRecoveryPointsClient: %+v", err) + } + + return &FetchSecondaryRecoveryPointsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/dataprotection/2023-11-01/fetchsecondaryrecoverypoints/constants.go b/resource-manager/dataprotection/2023-11-01/fetchsecondaryrecoverypoints/constants.go new file mode 100644 index 00000000000..4ad5deabceb --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/fetchsecondaryrecoverypoints/constants.go @@ -0,0 +1,101 @@ +package fetchsecondaryrecoverypoints + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecoveryPointCompletionState string + +const ( + RecoveryPointCompletionStateCompleted RecoveryPointCompletionState = "Completed" + RecoveryPointCompletionStatePartial RecoveryPointCompletionState = "Partial" +) + +func PossibleValuesForRecoveryPointCompletionState() []string { + return []string{ + string(RecoveryPointCompletionStateCompleted), + string(RecoveryPointCompletionStatePartial), + } +} + +func (s *RecoveryPointCompletionState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRecoveryPointCompletionState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRecoveryPointCompletionState(input string) (*RecoveryPointCompletionState, error) { + vals := map[string]RecoveryPointCompletionState{ + "completed": RecoveryPointCompletionStateCompleted, + "partial": RecoveryPointCompletionStatePartial, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RecoveryPointCompletionState(input) + return &out, nil +} + +type RehydrationStatus string + +const ( + RehydrationStatusCOMPLETED RehydrationStatus = "COMPLETED" + RehydrationStatusCREATEINPROGRESS RehydrationStatus = "CREATE_IN_PROGRESS" + RehydrationStatusDELETED RehydrationStatus = "DELETED" + RehydrationStatusDELETEINPROGRESS RehydrationStatus = "DELETE_IN_PROGRESS" + RehydrationStatusFAILED RehydrationStatus = "FAILED" +) + +func PossibleValuesForRehydrationStatus() []string { + return []string{ + string(RehydrationStatusCOMPLETED), + string(RehydrationStatusCREATEINPROGRESS), + string(RehydrationStatusDELETED), + string(RehydrationStatusDELETEINPROGRESS), + string(RehydrationStatusFAILED), + } +} + +func (s *RehydrationStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRehydrationStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRehydrationStatus(input string) (*RehydrationStatus, error) { + vals := map[string]RehydrationStatus{ + "completed": RehydrationStatusCOMPLETED, + "create_in_progress": RehydrationStatusCREATEINPROGRESS, + "deleted": RehydrationStatusDELETED, + "delete_in_progress": RehydrationStatusDELETEINPROGRESS, + "failed": RehydrationStatusFAILED, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RehydrationStatus(input) + return &out, nil +} diff --git a/resource-manager/dataprotection/2023-11-01/fetchsecondaryrecoverypoints/id_providerlocation.go b/resource-manager/dataprotection/2023-11-01/fetchsecondaryrecoverypoints/id_providerlocation.go new file mode 100644 index 00000000000..e24f220f415 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/fetchsecondaryrecoverypoints/id_providerlocation.go @@ -0,0 +1,125 @@ +package fetchsecondaryrecoverypoints + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = ProviderLocationId{} + +// ProviderLocationId is a struct representing the Resource ID for a Provider Location +type ProviderLocationId struct { + SubscriptionId string + ResourceGroupName string + LocationName string +} + +// NewProviderLocationID returns a new ProviderLocationId struct +func NewProviderLocationID(subscriptionId string, resourceGroupName string, locationName string) ProviderLocationId { + return ProviderLocationId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + LocationName: locationName, + } +} + +// ParseProviderLocationID parses 'input' into a ProviderLocationId +func ParseProviderLocationID(input string) (*ProviderLocationId, error) { + parser := resourceids.NewParserFromResourceIdType(ProviderLocationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProviderLocationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseProviderLocationIDInsensitively parses 'input' case-insensitively into a ProviderLocationId +// note: this method should only be used for API response data and not user input +func ParseProviderLocationIDInsensitively(input string) (*ProviderLocationId, error) { + parser := resourceids.NewParserFromResourceIdType(ProviderLocationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProviderLocationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ProviderLocationId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.LocationName, ok = input.Parsed["locationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "locationName", input) + } + + return nil +} + +// ValidateProviderLocationID checks that 'input' can be parsed as a Provider Location ID +func ValidateProviderLocationID(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 := ParseProviderLocationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Provider Location ID +func (id ProviderLocationId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DataProtection/locations/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.LocationName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Provider Location ID +func (id ProviderLocationId) 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("staticMicrosoftDataProtection", "Microsoft.DataProtection", "Microsoft.DataProtection"), + resourceids.StaticSegment("staticLocations", "locations", "locations"), + resourceids.UserSpecifiedSegment("locationName", "locationValue"), + } +} + +// String returns a human-readable description of this Provider Location ID +func (id ProviderLocationId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Location Name: %q", id.LocationName), + } + return fmt.Sprintf("Provider Location (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/dataprotection/2023-11-01/fetchsecondaryrecoverypoints/id_providerlocation_test.go b/resource-manager/dataprotection/2023-11-01/fetchsecondaryrecoverypoints/id_providerlocation_test.go new file mode 100644 index 00000000000..322e2947e3c --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/fetchsecondaryrecoverypoints/id_providerlocation_test.go @@ -0,0 +1,282 @@ +package fetchsecondaryrecoverypoints + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = ProviderLocationId{} + +func TestNewProviderLocationID(t *testing.T) { + id := NewProviderLocationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.LocationName != "locationValue" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationValue") + } +} + +func TestFormatProviderLocationID(t *testing.T) { + actual := NewProviderLocationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/locations/locationValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProviderLocationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProviderLocationId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/locations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/locations/locationValue", + Expected: &ProviderLocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/locations/locationValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProviderLocationID(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.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + } +} + +func TestParseProviderLocationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProviderLocationId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/lOcAtIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/locations/locationValue", + Expected: &ProviderLocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/locations/locationValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/lOcAtIoNs/lOcAtIoNvAlUe", + Expected: &ProviderLocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + LocationName: "lOcAtIoNvAlUe", + }, + }, + { + // 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.dAtApRoTeCtIoN/lOcAtIoNs/lOcAtIoNvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProviderLocationIDInsensitively(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.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + } +} + +func TestSegmentsForProviderLocationId(t *testing.T) { + segments := ProviderLocationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ProviderLocationId 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/dataprotection/2023-11-01/fetchsecondaryrecoverypoints/method_list.go b/resource-manager/dataprotection/2023-11-01/fetchsecondaryrecoverypoints/method_list.go new file mode 100644 index 00000000000..d74d8a7a43f --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/fetchsecondaryrecoverypoints/method_list.go @@ -0,0 +1,117 @@ +package fetchsecondaryrecoverypoints + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]AzureBackupRecoveryPointResource +} + +type ListCompleteResult struct { + Items []AzureBackupRecoveryPointResource +} + +type ListOperationOptions struct { + Filter *string +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + return &out +} + +// List ... +func (c FetchSecondaryRecoveryPointsClient) List(ctx context.Context, id ProviderLocationId, input FetchSecondaryRPsRequestParameters, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/fetchSecondaryRecoveryPoints", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]AzureBackupRecoveryPointResource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c FetchSecondaryRecoveryPointsClient) ListComplete(ctx context.Context, id ProviderLocationId, input FetchSecondaryRPsRequestParameters, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, input, options, AzureBackupRecoveryPointResourceOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c FetchSecondaryRecoveryPointsClient) ListCompleteMatchingPredicate(ctx context.Context, id ProviderLocationId, input FetchSecondaryRPsRequestParameters, options ListOperationOptions, predicate AzureBackupRecoveryPointResourceOperationPredicate) (result ListCompleteResult, err error) { + items := make([]AzureBackupRecoveryPointResource, 0) + + resp, err := c.List(ctx, id, input, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + Items: items, + } + return +} diff --git a/resource-manager/dataprotection/2023-11-01/fetchsecondaryrecoverypoints/model_azurebackupdiscreterecoverypoint.go b/resource-manager/dataprotection/2023-11-01/fetchsecondaryrecoverypoints/model_azurebackupdiscreterecoverypoint.go new file mode 100644 index 00000000000..33e554f5b79 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/fetchsecondaryrecoverypoints/model_azurebackupdiscreterecoverypoint.go @@ -0,0 +1,51 @@ +package fetchsecondaryrecoverypoints + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ AzureBackupRecoveryPoint = AzureBackupDiscreteRecoveryPoint{} + +type AzureBackupDiscreteRecoveryPoint struct { + ExpiryTime *string `json:"expiryTime,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + PolicyName *string `json:"policyName,omitempty"` + PolicyVersion *string `json:"policyVersion,omitempty"` + RecoveryPointDataStoresDetails *[]RecoveryPointDataStoreDetails `json:"recoveryPointDataStoresDetails,omitempty"` + RecoveryPointId *string `json:"recoveryPointId,omitempty"` + RecoveryPointState *RecoveryPointCompletionState `json:"recoveryPointState,omitempty"` + RecoveryPointTime string `json:"recoveryPointTime"` + RecoveryPointType *string `json:"recoveryPointType,omitempty"` + RetentionTagName *string `json:"retentionTagName,omitempty"` + RetentionTagVersion *string `json:"retentionTagVersion,omitempty"` + + // Fields inherited from AzureBackupRecoveryPoint +} + +var _ json.Marshaler = AzureBackupDiscreteRecoveryPoint{} + +func (s AzureBackupDiscreteRecoveryPoint) MarshalJSON() ([]byte, error) { + type wrapper AzureBackupDiscreteRecoveryPoint + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureBackupDiscreteRecoveryPoint: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureBackupDiscreteRecoveryPoint: %+v", err) + } + decoded["objectType"] = "AzureBackupDiscreteRecoveryPoint" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureBackupDiscreteRecoveryPoint: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/dataprotection/2023-11-01/fetchsecondaryrecoverypoints/model_azurebackuprecoverypoint.go b/resource-manager/dataprotection/2023-11-01/fetchsecondaryrecoverypoints/model_azurebackuprecoverypoint.go new file mode 100644 index 00000000000..81815b8b85c --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/fetchsecondaryrecoverypoints/model_azurebackuprecoverypoint.go @@ -0,0 +1,53 @@ +package fetchsecondaryrecoverypoints + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureBackupRecoveryPoint interface { +} + +// RawAzureBackupRecoveryPointImpl is returned when the Discriminated Value +// doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawAzureBackupRecoveryPointImpl struct { + Type string + Values map[string]interface{} +} + +func unmarshalAzureBackupRecoveryPointImplementation(input []byte) (AzureBackupRecoveryPoint, error) { + if input == nil { + return nil, nil + } + + var temp map[string]interface{} + if err := json.Unmarshal(input, &temp); err != nil { + return nil, fmt.Errorf("unmarshaling AzureBackupRecoveryPoint into map[string]interface: %+v", err) + } + + value, ok := temp["objectType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "AzureBackupDiscreteRecoveryPoint") { + var out AzureBackupDiscreteRecoveryPoint + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureBackupDiscreteRecoveryPoint: %+v", err) + } + return out, nil + } + + out := RawAzureBackupRecoveryPointImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/dataprotection/2023-11-01/fetchsecondaryrecoverypoints/model_azurebackuprecoverypointresource.go b/resource-manager/dataprotection/2023-11-01/fetchsecondaryrecoverypoints/model_azurebackuprecoverypointresource.go new file mode 100644 index 00000000000..b09db4ee8cd --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/fetchsecondaryrecoverypoints/model_azurebackuprecoverypointresource.go @@ -0,0 +1,48 @@ +package fetchsecondaryrecoverypoints + +import ( + "encoding/json" + "fmt" + + "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 AzureBackupRecoveryPointResource struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties AzureBackupRecoveryPoint `json:"properties"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Unmarshaler = &AzureBackupRecoveryPointResource{} + +func (s *AzureBackupRecoveryPointResource) UnmarshalJSON(bytes []byte) error { + type alias AzureBackupRecoveryPointResource + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into AzureBackupRecoveryPointResource: %+v", err) + } + + s.Id = decoded.Id + s.Name = decoded.Name + s.SystemData = decoded.SystemData + s.Type = decoded.Type + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling AzureBackupRecoveryPointResource into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["properties"]; ok { + impl, err := unmarshalAzureBackupRecoveryPointImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'Properties' for 'AzureBackupRecoveryPointResource': %+v", err) + } + s.Properties = impl + } + return nil +} diff --git a/resource-manager/dataprotection/2023-11-01/fetchsecondaryrecoverypoints/model_fetchsecondaryrpsrequestparameters.go b/resource-manager/dataprotection/2023-11-01/fetchsecondaryrecoverypoints/model_fetchsecondaryrpsrequestparameters.go new file mode 100644 index 00000000000..7a692e03408 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/fetchsecondaryrecoverypoints/model_fetchsecondaryrpsrequestparameters.go @@ -0,0 +1,9 @@ +package fetchsecondaryrecoverypoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FetchSecondaryRPsRequestParameters struct { + SourceBackupInstanceId *string `json:"sourceBackupInstanceId,omitempty"` + SourceRegion *string `json:"sourceRegion,omitempty"` +} diff --git a/resource-manager/dataprotection/2023-11-01/fetchsecondaryrecoverypoints/model_recoverypointdatastoredetails.go b/resource-manager/dataprotection/2023-11-01/fetchsecondaryrecoverypoints/model_recoverypointdatastoredetails.go new file mode 100644 index 00000000000..abdf9b9007f --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/fetchsecondaryrecoverypoints/model_recoverypointdatastoredetails.go @@ -0,0 +1,58 @@ +package fetchsecondaryrecoverypoints + +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 RecoveryPointDataStoreDetails struct { + CreationTime *string `json:"creationTime,omitempty"` + ExpiryTime *string `json:"expiryTime,omitempty"` + Id *string `json:"id,omitempty"` + MetaData *string `json:"metaData,omitempty"` + RehydrationExpiryTime *string `json:"rehydrationExpiryTime,omitempty"` + RehydrationStatus *RehydrationStatus `json:"rehydrationStatus,omitempty"` + State *string `json:"state,omitempty"` + Type *string `json:"type,omitempty"` + Visible *bool `json:"visible,omitempty"` +} + +func (o *RecoveryPointDataStoreDetails) GetCreationTimeAsTime() (*time.Time, error) { + if o.CreationTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreationTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *RecoveryPointDataStoreDetails) SetCreationTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreationTime = &formatted +} + +func (o *RecoveryPointDataStoreDetails) GetExpiryTimeAsTime() (*time.Time, error) { + if o.ExpiryTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ExpiryTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *RecoveryPointDataStoreDetails) SetExpiryTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ExpiryTime = &formatted +} + +func (o *RecoveryPointDataStoreDetails) GetRehydrationExpiryTimeAsTime() (*time.Time, error) { + if o.RehydrationExpiryTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.RehydrationExpiryTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *RecoveryPointDataStoreDetails) SetRehydrationExpiryTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.RehydrationExpiryTime = &formatted +} diff --git a/resource-manager/dataprotection/2023-11-01/fetchsecondaryrecoverypoints/predicates.go b/resource-manager/dataprotection/2023-11-01/fetchsecondaryrecoverypoints/predicates.go new file mode 100644 index 00000000000..b9a05d28a27 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/fetchsecondaryrecoverypoints/predicates.go @@ -0,0 +1,27 @@ +package fetchsecondaryrecoverypoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureBackupRecoveryPointResourceOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p AzureBackupRecoveryPointResourceOperationPredicate) Matches(input AzureBackupRecoveryPointResource) 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/dataprotection/2023-11-01/fetchsecondaryrecoverypoints/version.go b/resource-manager/dataprotection/2023-11-01/fetchsecondaryrecoverypoints/version.go new file mode 100644 index 00000000000..2a74c791073 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/fetchsecondaryrecoverypoints/version.go @@ -0,0 +1,12 @@ +package fetchsecondaryrecoverypoints + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-11-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/fetchsecondaryrecoverypoints/%s", defaultApiVersion) +} diff --git a/resource-manager/dataprotection/2023-11-01/findrestorabletimeranges/README.md b/resource-manager/dataprotection/2023-11-01/findrestorabletimeranges/README.md new file mode 100644 index 00000000000..ff2e70818cd --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/findrestorabletimeranges/README.md @@ -0,0 +1,41 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2023-11-01/findrestorabletimeranges` Documentation + +The `findrestorabletimeranges` SDK allows for interaction with the Azure Resource Manager Service `dataprotection` (API Version `2023-11-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2023-11-01/findrestorabletimeranges" +``` + + +### Client Initialization + +```go +client := findrestorabletimeranges.NewFindRestorableTimeRangesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `FindRestorableTimeRangesClient.RestorableTimeRangesFind` + +```go +ctx := context.TODO() +id := findrestorabletimeranges.NewBackupInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultValue", "backupInstanceValue") + +payload := findrestorabletimeranges.AzureBackupFindRestorableTimeRangesRequest{ + // ... +} + + +read, err := client.RestorableTimeRangesFind(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/dataprotection/2023-11-01/findrestorabletimeranges/client.go b/resource-manager/dataprotection/2023-11-01/findrestorabletimeranges/client.go new file mode 100644 index 00000000000..bfd1fda26df --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/findrestorabletimeranges/client.go @@ -0,0 +1,26 @@ +package findrestorabletimeranges + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FindRestorableTimeRangesClient struct { + Client *resourcemanager.Client +} + +func NewFindRestorableTimeRangesClientWithBaseURI(sdkApi sdkEnv.Api) (*FindRestorableTimeRangesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "findrestorabletimeranges", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating FindRestorableTimeRangesClient: %+v", err) + } + + return &FindRestorableTimeRangesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/dataprotection/2023-11-01/findrestorabletimeranges/constants.go b/resource-manager/dataprotection/2023-11-01/findrestorabletimeranges/constants.go new file mode 100644 index 00000000000..3afd71927af --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/findrestorabletimeranges/constants.go @@ -0,0 +1,54 @@ +package findrestorabletimeranges + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RestoreSourceDataStoreType string + +const ( + RestoreSourceDataStoreTypeArchiveStore RestoreSourceDataStoreType = "ArchiveStore" + RestoreSourceDataStoreTypeOperationalStore RestoreSourceDataStoreType = "OperationalStore" + RestoreSourceDataStoreTypeVaultStore RestoreSourceDataStoreType = "VaultStore" +) + +func PossibleValuesForRestoreSourceDataStoreType() []string { + return []string{ + string(RestoreSourceDataStoreTypeArchiveStore), + string(RestoreSourceDataStoreTypeOperationalStore), + string(RestoreSourceDataStoreTypeVaultStore), + } +} + +func (s *RestoreSourceDataStoreType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRestoreSourceDataStoreType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRestoreSourceDataStoreType(input string) (*RestoreSourceDataStoreType, error) { + vals := map[string]RestoreSourceDataStoreType{ + "archivestore": RestoreSourceDataStoreTypeArchiveStore, + "operationalstore": RestoreSourceDataStoreTypeOperationalStore, + "vaultstore": RestoreSourceDataStoreTypeVaultStore, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RestoreSourceDataStoreType(input) + return &out, nil +} diff --git a/resource-manager/dataprotection/2023-11-01/findrestorabletimeranges/id_backupinstance.go b/resource-manager/dataprotection/2023-11-01/findrestorabletimeranges/id_backupinstance.go new file mode 100644 index 00000000000..53677a4cb15 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/findrestorabletimeranges/id_backupinstance.go @@ -0,0 +1,134 @@ +package findrestorabletimeranges + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = BackupInstanceId{} + +// BackupInstanceId is a struct representing the Resource ID for a Backup Instance +type BackupInstanceId struct { + SubscriptionId string + ResourceGroupName string + BackupVaultName string + BackupInstanceName string +} + +// NewBackupInstanceID returns a new BackupInstanceId struct +func NewBackupInstanceID(subscriptionId string, resourceGroupName string, backupVaultName string, backupInstanceName string) BackupInstanceId { + return BackupInstanceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + BackupVaultName: backupVaultName, + BackupInstanceName: backupInstanceName, + } +} + +// ParseBackupInstanceID parses 'input' into a BackupInstanceId +func ParseBackupInstanceID(input string) (*BackupInstanceId, error) { + parser := resourceids.NewParserFromResourceIdType(BackupInstanceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BackupInstanceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseBackupInstanceIDInsensitively parses 'input' case-insensitively into a BackupInstanceId +// note: this method should only be used for API response data and not user input +func ParseBackupInstanceIDInsensitively(input string) (*BackupInstanceId, error) { + parser := resourceids.NewParserFromResourceIdType(BackupInstanceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BackupInstanceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *BackupInstanceId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.BackupVaultName, ok = input.Parsed["backupVaultName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "backupVaultName", input) + } + + if id.BackupInstanceName, ok = input.Parsed["backupInstanceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "backupInstanceName", input) + } + + return nil +} + +// ValidateBackupInstanceID checks that 'input' can be parsed as a Backup Instance ID +func ValidateBackupInstanceID(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 := ParseBackupInstanceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Backup Instance ID +func (id BackupInstanceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DataProtection/backupVaults/%s/backupInstances/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.BackupVaultName, id.BackupInstanceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Backup Instance ID +func (id BackupInstanceId) 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("staticMicrosoftDataProtection", "Microsoft.DataProtection", "Microsoft.DataProtection"), + resourceids.StaticSegment("staticBackupVaults", "backupVaults", "backupVaults"), + resourceids.UserSpecifiedSegment("backupVaultName", "backupVaultValue"), + resourceids.StaticSegment("staticBackupInstances", "backupInstances", "backupInstances"), + resourceids.UserSpecifiedSegment("backupInstanceName", "backupInstanceValue"), + } +} + +// String returns a human-readable description of this Backup Instance ID +func (id BackupInstanceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Backup Vault Name: %q", id.BackupVaultName), + fmt.Sprintf("Backup Instance Name: %q", id.BackupInstanceName), + } + return fmt.Sprintf("Backup Instance (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/dataprotection/2023-11-01/findrestorabletimeranges/id_backupinstance_test.go b/resource-manager/dataprotection/2023-11-01/findrestorabletimeranges/id_backupinstance_test.go new file mode 100644 index 00000000000..a4882911f9e --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/findrestorabletimeranges/id_backupinstance_test.go @@ -0,0 +1,327 @@ +package findrestorabletimeranges + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = BackupInstanceId{} + +func TestNewBackupInstanceID(t *testing.T) { + id := NewBackupInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultValue", "backupInstanceValue") + + 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.BackupVaultName != "backupVaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'BackupVaultName'", id.BackupVaultName, "backupVaultValue") + } + + if id.BackupInstanceName != "backupInstanceValue" { + t.Fatalf("Expected %q but got %q for Segment 'BackupInstanceName'", id.BackupInstanceName, "backupInstanceValue") + } +} + +func TestFormatBackupInstanceID(t *testing.T) { + actual := NewBackupInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultValue", "backupInstanceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/backupInstances/backupInstanceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseBackupInstanceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BackupInstanceId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/backupInstances", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/backupInstances/backupInstanceValue", + Expected: &BackupInstanceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + BackupVaultName: "backupVaultValue", + BackupInstanceName: "backupInstanceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/backupInstances/backupInstanceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBackupInstanceID(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.BackupVaultName != v.Expected.BackupVaultName { + t.Fatalf("Expected %q but got %q for BackupVaultName", v.Expected.BackupVaultName, actual.BackupVaultName) + } + + if actual.BackupInstanceName != v.Expected.BackupInstanceName { + t.Fatalf("Expected %q but got %q for BackupInstanceName", v.Expected.BackupInstanceName, actual.BackupInstanceName) + } + + } +} + +func TestParseBackupInstanceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BackupInstanceId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/backupInstances", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtVaLuE/bAcKuPiNsTaNcEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/backupInstances/backupInstanceValue", + Expected: &BackupInstanceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + BackupVaultName: "backupVaultValue", + BackupInstanceName: "backupInstanceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/backupInstances/backupInstanceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtVaLuE/bAcKuPiNsTaNcEs/bAcKuPiNsTaNcEvAlUe", + Expected: &BackupInstanceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + BackupVaultName: "bAcKuPvAuLtVaLuE", + BackupInstanceName: "bAcKuPiNsTaNcEvAlUe", + }, + }, + { + // 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.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtVaLuE/bAcKuPiNsTaNcEs/bAcKuPiNsTaNcEvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBackupInstanceIDInsensitively(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.BackupVaultName != v.Expected.BackupVaultName { + t.Fatalf("Expected %q but got %q for BackupVaultName", v.Expected.BackupVaultName, actual.BackupVaultName) + } + + if actual.BackupInstanceName != v.Expected.BackupInstanceName { + t.Fatalf("Expected %q but got %q for BackupInstanceName", v.Expected.BackupInstanceName, actual.BackupInstanceName) + } + + } +} + +func TestSegmentsForBackupInstanceId(t *testing.T) { + segments := BackupInstanceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("BackupInstanceId 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/dataprotection/2023-11-01/findrestorabletimeranges/method_restorabletimerangesfind.go b/resource-manager/dataprotection/2023-11-01/findrestorabletimeranges/method_restorabletimerangesfind.go new file mode 100644 index 00000000000..50cad8eb851 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/findrestorabletimeranges/method_restorabletimerangesfind.go @@ -0,0 +1,56 @@ +package findrestorabletimeranges + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RestorableTimeRangesFindOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AzureBackupFindRestorableTimeRangesResponseResource +} + +// RestorableTimeRangesFind ... +func (c FindRestorableTimeRangesClient) RestorableTimeRangesFind(ctx context.Context, id BackupInstanceId, input AzureBackupFindRestorableTimeRangesRequest) (result RestorableTimeRangesFindOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/findRestorableTimeRanges", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/dataprotection/2023-11-01/findrestorabletimeranges/model_azurebackupfindrestorabletimerangesrequest.go b/resource-manager/dataprotection/2023-11-01/findrestorabletimeranges/model_azurebackupfindrestorabletimerangesrequest.go new file mode 100644 index 00000000000..3788f11d512 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/findrestorabletimeranges/model_azurebackupfindrestorabletimerangesrequest.go @@ -0,0 +1,10 @@ +package findrestorabletimeranges + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureBackupFindRestorableTimeRangesRequest struct { + EndTime *string `json:"endTime,omitempty"` + SourceDataStoreType RestoreSourceDataStoreType `json:"sourceDataStoreType"` + StartTime *string `json:"startTime,omitempty"` +} diff --git a/resource-manager/dataprotection/2023-11-01/findrestorabletimeranges/model_azurebackupfindrestorabletimerangesresponse.go b/resource-manager/dataprotection/2023-11-01/findrestorabletimeranges/model_azurebackupfindrestorabletimerangesresponse.go new file mode 100644 index 00000000000..2c361dccf44 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/findrestorabletimeranges/model_azurebackupfindrestorabletimerangesresponse.go @@ -0,0 +1,9 @@ +package findrestorabletimeranges + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureBackupFindRestorableTimeRangesResponse struct { + ObjectType *string `json:"objectType,omitempty"` + RestorableTimeRanges *[]RestorableTimeRange `json:"restorableTimeRanges,omitempty"` +} diff --git a/resource-manager/dataprotection/2023-11-01/findrestorabletimeranges/model_azurebackupfindrestorabletimerangesresponseresource.go b/resource-manager/dataprotection/2023-11-01/findrestorabletimeranges/model_azurebackupfindrestorabletimerangesresponseresource.go new file mode 100644 index 00000000000..bd16082c55f --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/findrestorabletimeranges/model_azurebackupfindrestorabletimerangesresponseresource.go @@ -0,0 +1,16 @@ +package findrestorabletimeranges + +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 AzureBackupFindRestorableTimeRangesResponseResource struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *AzureBackupFindRestorableTimeRangesResponse `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/dataprotection/2023-11-01/findrestorabletimeranges/model_restorabletimerange.go b/resource-manager/dataprotection/2023-11-01/findrestorabletimeranges/model_restorabletimerange.go new file mode 100644 index 00000000000..1ea7cdc9433 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/findrestorabletimeranges/model_restorabletimerange.go @@ -0,0 +1,10 @@ +package findrestorabletimeranges + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RestorableTimeRange struct { + EndTime string `json:"endTime"` + ObjectType *string `json:"objectType,omitempty"` + StartTime string `json:"startTime"` +} diff --git a/resource-manager/dataprotection/2023-11-01/findrestorabletimeranges/version.go b/resource-manager/dataprotection/2023-11-01/findrestorabletimeranges/version.go new file mode 100644 index 00000000000..676249247b5 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/findrestorabletimeranges/version.go @@ -0,0 +1,12 @@ +package findrestorabletimeranges + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-11-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/findrestorabletimeranges/%s", defaultApiVersion) +} diff --git a/resource-manager/dataprotection/2023-11-01/recoverypoint/README.md b/resource-manager/dataprotection/2023-11-01/recoverypoint/README.md new file mode 100644 index 00000000000..3198d3e94b7 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/recoverypoint/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2023-11-01/recoverypoint` Documentation + +The `recoverypoint` SDK allows for interaction with the Azure Resource Manager Service `dataprotection` (API Version `2023-11-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2023-11-01/recoverypoint" +``` + + +### Client Initialization + +```go +client := recoverypoint.NewRecoveryPointClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `RecoveryPointClient.Get` + +```go +ctx := context.TODO() +id := recoverypoint.NewRecoveryPointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultValue", "backupInstanceValue", "recoveryPointIdValue") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `RecoveryPointClient.List` + +```go +ctx := context.TODO() +id := recoverypoint.NewBackupInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultValue", "backupInstanceValue") + +// alternatively `client.List(ctx, id, recoverypoint.DefaultListOperationOptions())` can be used to do batched pagination +items, err := client.ListComplete(ctx, id, recoverypoint.DefaultListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/dataprotection/2023-11-01/recoverypoint/client.go b/resource-manager/dataprotection/2023-11-01/recoverypoint/client.go new file mode 100644 index 00000000000..d58f74c6c6a --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/recoverypoint/client.go @@ -0,0 +1,26 @@ +package recoverypoint + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecoveryPointClient struct { + Client *resourcemanager.Client +} + +func NewRecoveryPointClientWithBaseURI(sdkApi sdkEnv.Api) (*RecoveryPointClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "recoverypoint", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating RecoveryPointClient: %+v", err) + } + + return &RecoveryPointClient{ + Client: client, + }, nil +} diff --git a/resource-manager/dataprotection/2023-11-01/recoverypoint/constants.go b/resource-manager/dataprotection/2023-11-01/recoverypoint/constants.go new file mode 100644 index 00000000000..9a81c1ea973 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/recoverypoint/constants.go @@ -0,0 +1,101 @@ +package recoverypoint + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecoveryPointCompletionState string + +const ( + RecoveryPointCompletionStateCompleted RecoveryPointCompletionState = "Completed" + RecoveryPointCompletionStatePartial RecoveryPointCompletionState = "Partial" +) + +func PossibleValuesForRecoveryPointCompletionState() []string { + return []string{ + string(RecoveryPointCompletionStateCompleted), + string(RecoveryPointCompletionStatePartial), + } +} + +func (s *RecoveryPointCompletionState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRecoveryPointCompletionState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRecoveryPointCompletionState(input string) (*RecoveryPointCompletionState, error) { + vals := map[string]RecoveryPointCompletionState{ + "completed": RecoveryPointCompletionStateCompleted, + "partial": RecoveryPointCompletionStatePartial, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RecoveryPointCompletionState(input) + return &out, nil +} + +type RehydrationStatus string + +const ( + RehydrationStatusCOMPLETED RehydrationStatus = "COMPLETED" + RehydrationStatusCREATEINPROGRESS RehydrationStatus = "CREATE_IN_PROGRESS" + RehydrationStatusDELETED RehydrationStatus = "DELETED" + RehydrationStatusDELETEINPROGRESS RehydrationStatus = "DELETE_IN_PROGRESS" + RehydrationStatusFAILED RehydrationStatus = "FAILED" +) + +func PossibleValuesForRehydrationStatus() []string { + return []string{ + string(RehydrationStatusCOMPLETED), + string(RehydrationStatusCREATEINPROGRESS), + string(RehydrationStatusDELETED), + string(RehydrationStatusDELETEINPROGRESS), + string(RehydrationStatusFAILED), + } +} + +func (s *RehydrationStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRehydrationStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRehydrationStatus(input string) (*RehydrationStatus, error) { + vals := map[string]RehydrationStatus{ + "completed": RehydrationStatusCOMPLETED, + "create_in_progress": RehydrationStatusCREATEINPROGRESS, + "deleted": RehydrationStatusDELETED, + "delete_in_progress": RehydrationStatusDELETEINPROGRESS, + "failed": RehydrationStatusFAILED, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RehydrationStatus(input) + return &out, nil +} diff --git a/resource-manager/dataprotection/2023-11-01/recoverypoint/id_backupinstance.go b/resource-manager/dataprotection/2023-11-01/recoverypoint/id_backupinstance.go new file mode 100644 index 00000000000..a80e687857a --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/recoverypoint/id_backupinstance.go @@ -0,0 +1,134 @@ +package recoverypoint + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = BackupInstanceId{} + +// BackupInstanceId is a struct representing the Resource ID for a Backup Instance +type BackupInstanceId struct { + SubscriptionId string + ResourceGroupName string + BackupVaultName string + BackupInstanceName string +} + +// NewBackupInstanceID returns a new BackupInstanceId struct +func NewBackupInstanceID(subscriptionId string, resourceGroupName string, backupVaultName string, backupInstanceName string) BackupInstanceId { + return BackupInstanceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + BackupVaultName: backupVaultName, + BackupInstanceName: backupInstanceName, + } +} + +// ParseBackupInstanceID parses 'input' into a BackupInstanceId +func ParseBackupInstanceID(input string) (*BackupInstanceId, error) { + parser := resourceids.NewParserFromResourceIdType(BackupInstanceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BackupInstanceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseBackupInstanceIDInsensitively parses 'input' case-insensitively into a BackupInstanceId +// note: this method should only be used for API response data and not user input +func ParseBackupInstanceIDInsensitively(input string) (*BackupInstanceId, error) { + parser := resourceids.NewParserFromResourceIdType(BackupInstanceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BackupInstanceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *BackupInstanceId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.BackupVaultName, ok = input.Parsed["backupVaultName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "backupVaultName", input) + } + + if id.BackupInstanceName, ok = input.Parsed["backupInstanceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "backupInstanceName", input) + } + + return nil +} + +// ValidateBackupInstanceID checks that 'input' can be parsed as a Backup Instance ID +func ValidateBackupInstanceID(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 := ParseBackupInstanceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Backup Instance ID +func (id BackupInstanceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DataProtection/backupVaults/%s/backupInstances/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.BackupVaultName, id.BackupInstanceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Backup Instance ID +func (id BackupInstanceId) 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("staticMicrosoftDataProtection", "Microsoft.DataProtection", "Microsoft.DataProtection"), + resourceids.StaticSegment("staticBackupVaults", "backupVaults", "backupVaults"), + resourceids.UserSpecifiedSegment("backupVaultName", "backupVaultValue"), + resourceids.StaticSegment("staticBackupInstances", "backupInstances", "backupInstances"), + resourceids.UserSpecifiedSegment("backupInstanceName", "backupInstanceValue"), + } +} + +// String returns a human-readable description of this Backup Instance ID +func (id BackupInstanceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Backup Vault Name: %q", id.BackupVaultName), + fmt.Sprintf("Backup Instance Name: %q", id.BackupInstanceName), + } + return fmt.Sprintf("Backup Instance (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/dataprotection/2023-11-01/recoverypoint/id_backupinstance_test.go b/resource-manager/dataprotection/2023-11-01/recoverypoint/id_backupinstance_test.go new file mode 100644 index 00000000000..a49799bb68c --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/recoverypoint/id_backupinstance_test.go @@ -0,0 +1,327 @@ +package recoverypoint + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = BackupInstanceId{} + +func TestNewBackupInstanceID(t *testing.T) { + id := NewBackupInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultValue", "backupInstanceValue") + + 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.BackupVaultName != "backupVaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'BackupVaultName'", id.BackupVaultName, "backupVaultValue") + } + + if id.BackupInstanceName != "backupInstanceValue" { + t.Fatalf("Expected %q but got %q for Segment 'BackupInstanceName'", id.BackupInstanceName, "backupInstanceValue") + } +} + +func TestFormatBackupInstanceID(t *testing.T) { + actual := NewBackupInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultValue", "backupInstanceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/backupInstances/backupInstanceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseBackupInstanceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BackupInstanceId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/backupInstances", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/backupInstances/backupInstanceValue", + Expected: &BackupInstanceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + BackupVaultName: "backupVaultValue", + BackupInstanceName: "backupInstanceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/backupInstances/backupInstanceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBackupInstanceID(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.BackupVaultName != v.Expected.BackupVaultName { + t.Fatalf("Expected %q but got %q for BackupVaultName", v.Expected.BackupVaultName, actual.BackupVaultName) + } + + if actual.BackupInstanceName != v.Expected.BackupInstanceName { + t.Fatalf("Expected %q but got %q for BackupInstanceName", v.Expected.BackupInstanceName, actual.BackupInstanceName) + } + + } +} + +func TestParseBackupInstanceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BackupInstanceId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/backupInstances", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtVaLuE/bAcKuPiNsTaNcEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/backupInstances/backupInstanceValue", + Expected: &BackupInstanceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + BackupVaultName: "backupVaultValue", + BackupInstanceName: "backupInstanceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/backupInstances/backupInstanceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtVaLuE/bAcKuPiNsTaNcEs/bAcKuPiNsTaNcEvAlUe", + Expected: &BackupInstanceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + BackupVaultName: "bAcKuPvAuLtVaLuE", + BackupInstanceName: "bAcKuPiNsTaNcEvAlUe", + }, + }, + { + // 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.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtVaLuE/bAcKuPiNsTaNcEs/bAcKuPiNsTaNcEvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBackupInstanceIDInsensitively(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.BackupVaultName != v.Expected.BackupVaultName { + t.Fatalf("Expected %q but got %q for BackupVaultName", v.Expected.BackupVaultName, actual.BackupVaultName) + } + + if actual.BackupInstanceName != v.Expected.BackupInstanceName { + t.Fatalf("Expected %q but got %q for BackupInstanceName", v.Expected.BackupInstanceName, actual.BackupInstanceName) + } + + } +} + +func TestSegmentsForBackupInstanceId(t *testing.T) { + segments := BackupInstanceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("BackupInstanceId 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/dataprotection/2023-11-01/recoverypoint/id_recoverypoint.go b/resource-manager/dataprotection/2023-11-01/recoverypoint/id_recoverypoint.go new file mode 100644 index 00000000000..7eb4b2133bb --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/recoverypoint/id_recoverypoint.go @@ -0,0 +1,143 @@ +package recoverypoint + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = RecoveryPointId{} + +// RecoveryPointId is a struct representing the Resource ID for a Recovery Point +type RecoveryPointId struct { + SubscriptionId string + ResourceGroupName string + BackupVaultName string + BackupInstanceName string + RecoveryPointId string +} + +// NewRecoveryPointID returns a new RecoveryPointId struct +func NewRecoveryPointID(subscriptionId string, resourceGroupName string, backupVaultName string, backupInstanceName string, recoveryPointId string) RecoveryPointId { + return RecoveryPointId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + BackupVaultName: backupVaultName, + BackupInstanceName: backupInstanceName, + RecoveryPointId: recoveryPointId, + } +} + +// ParseRecoveryPointID parses 'input' into a RecoveryPointId +func ParseRecoveryPointID(input string) (*RecoveryPointId, error) { + parser := resourceids.NewParserFromResourceIdType(RecoveryPointId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RecoveryPointId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseRecoveryPointIDInsensitively parses 'input' case-insensitively into a RecoveryPointId +// note: this method should only be used for API response data and not user input +func ParseRecoveryPointIDInsensitively(input string) (*RecoveryPointId, error) { + parser := resourceids.NewParserFromResourceIdType(RecoveryPointId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RecoveryPointId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *RecoveryPointId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.BackupVaultName, ok = input.Parsed["backupVaultName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "backupVaultName", input) + } + + if id.BackupInstanceName, ok = input.Parsed["backupInstanceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "backupInstanceName", input) + } + + if id.RecoveryPointId, ok = input.Parsed["recoveryPointId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "recoveryPointId", input) + } + + return nil +} + +// ValidateRecoveryPointID checks that 'input' can be parsed as a Recovery Point ID +func ValidateRecoveryPointID(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 := ParseRecoveryPointID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Recovery Point ID +func (id RecoveryPointId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DataProtection/backupVaults/%s/backupInstances/%s/recoveryPoints/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.BackupVaultName, id.BackupInstanceName, id.RecoveryPointId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Recovery Point ID +func (id RecoveryPointId) 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("staticMicrosoftDataProtection", "Microsoft.DataProtection", "Microsoft.DataProtection"), + resourceids.StaticSegment("staticBackupVaults", "backupVaults", "backupVaults"), + resourceids.UserSpecifiedSegment("backupVaultName", "backupVaultValue"), + resourceids.StaticSegment("staticBackupInstances", "backupInstances", "backupInstances"), + resourceids.UserSpecifiedSegment("backupInstanceName", "backupInstanceValue"), + resourceids.StaticSegment("staticRecoveryPoints", "recoveryPoints", "recoveryPoints"), + resourceids.UserSpecifiedSegment("recoveryPointId", "recoveryPointIdValue"), + } +} + +// String returns a human-readable description of this Recovery Point ID +func (id RecoveryPointId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Backup Vault Name: %q", id.BackupVaultName), + fmt.Sprintf("Backup Instance Name: %q", id.BackupInstanceName), + fmt.Sprintf("Recovery Point: %q", id.RecoveryPointId), + } + return fmt.Sprintf("Recovery Point (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/dataprotection/2023-11-01/recoverypoint/id_recoverypoint_test.go b/resource-manager/dataprotection/2023-11-01/recoverypoint/id_recoverypoint_test.go new file mode 100644 index 00000000000..95eaf7b9684 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/recoverypoint/id_recoverypoint_test.go @@ -0,0 +1,372 @@ +package recoverypoint + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = RecoveryPointId{} + +func TestNewRecoveryPointID(t *testing.T) { + id := NewRecoveryPointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultValue", "backupInstanceValue", "recoveryPointIdValue") + + 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.BackupVaultName != "backupVaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'BackupVaultName'", id.BackupVaultName, "backupVaultValue") + } + + if id.BackupInstanceName != "backupInstanceValue" { + t.Fatalf("Expected %q but got %q for Segment 'BackupInstanceName'", id.BackupInstanceName, "backupInstanceValue") + } + + if id.RecoveryPointId != "recoveryPointIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'RecoveryPointId'", id.RecoveryPointId, "recoveryPointIdValue") + } +} + +func TestFormatRecoveryPointID(t *testing.T) { + actual := NewRecoveryPointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultValue", "backupInstanceValue", "recoveryPointIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/backupInstances/backupInstanceValue/recoveryPoints/recoveryPointIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseRecoveryPointID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RecoveryPointId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/backupInstances", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/backupInstances/backupInstanceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/backupInstances/backupInstanceValue/recoveryPoints", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/backupInstances/backupInstanceValue/recoveryPoints/recoveryPointIdValue", + Expected: &RecoveryPointId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + BackupVaultName: "backupVaultValue", + BackupInstanceName: "backupInstanceValue", + RecoveryPointId: "recoveryPointIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/backupInstances/backupInstanceValue/recoveryPoints/recoveryPointIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRecoveryPointID(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.BackupVaultName != v.Expected.BackupVaultName { + t.Fatalf("Expected %q but got %q for BackupVaultName", v.Expected.BackupVaultName, actual.BackupVaultName) + } + + if actual.BackupInstanceName != v.Expected.BackupInstanceName { + t.Fatalf("Expected %q but got %q for BackupInstanceName", v.Expected.BackupInstanceName, actual.BackupInstanceName) + } + + if actual.RecoveryPointId != v.Expected.RecoveryPointId { + t.Fatalf("Expected %q but got %q for RecoveryPointId", v.Expected.RecoveryPointId, actual.RecoveryPointId) + } + + } +} + +func TestParseRecoveryPointIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RecoveryPointId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/backupInstances", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtVaLuE/bAcKuPiNsTaNcEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/backupInstances/backupInstanceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtVaLuE/bAcKuPiNsTaNcEs/bAcKuPiNsTaNcEvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/backupInstances/backupInstanceValue/recoveryPoints", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtVaLuE/bAcKuPiNsTaNcEs/bAcKuPiNsTaNcEvAlUe/rEcOvErYpOiNtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/backupInstances/backupInstanceValue/recoveryPoints/recoveryPointIdValue", + Expected: &RecoveryPointId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + BackupVaultName: "backupVaultValue", + BackupInstanceName: "backupInstanceValue", + RecoveryPointId: "recoveryPointIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultValue/backupInstances/backupInstanceValue/recoveryPoints/recoveryPointIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtVaLuE/bAcKuPiNsTaNcEs/bAcKuPiNsTaNcEvAlUe/rEcOvErYpOiNtS/rEcOvErYpOiNtIdVaLuE", + Expected: &RecoveryPointId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + BackupVaultName: "bAcKuPvAuLtVaLuE", + BackupInstanceName: "bAcKuPiNsTaNcEvAlUe", + RecoveryPointId: "rEcOvErYpOiNtIdVaLuE", + }, + }, + { + // 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.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtVaLuE/bAcKuPiNsTaNcEs/bAcKuPiNsTaNcEvAlUe/rEcOvErYpOiNtS/rEcOvErYpOiNtIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRecoveryPointIDInsensitively(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.BackupVaultName != v.Expected.BackupVaultName { + t.Fatalf("Expected %q but got %q for BackupVaultName", v.Expected.BackupVaultName, actual.BackupVaultName) + } + + if actual.BackupInstanceName != v.Expected.BackupInstanceName { + t.Fatalf("Expected %q but got %q for BackupInstanceName", v.Expected.BackupInstanceName, actual.BackupInstanceName) + } + + if actual.RecoveryPointId != v.Expected.RecoveryPointId { + t.Fatalf("Expected %q but got %q for RecoveryPointId", v.Expected.RecoveryPointId, actual.RecoveryPointId) + } + + } +} + +func TestSegmentsForRecoveryPointId(t *testing.T) { + segments := RecoveryPointId{}.Segments() + if len(segments) == 0 { + t.Fatalf("RecoveryPointId 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/dataprotection/2023-11-01/recoverypoint/method_get.go b/resource-manager/dataprotection/2023-11-01/recoverypoint/method_get.go new file mode 100644 index 00000000000..ee3747c9476 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/recoverypoint/method_get.go @@ -0,0 +1,51 @@ +package recoverypoint + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AzureBackupRecoveryPointResource +} + +// Get ... +func (c RecoveryPointClient) Get(ctx context.Context, id RecoveryPointId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/dataprotection/2023-11-01/recoverypoint/method_list.go b/resource-manager/dataprotection/2023-11-01/recoverypoint/method_list.go new file mode 100644 index 00000000000..8555f5d4e55 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/recoverypoint/method_list.go @@ -0,0 +1,117 @@ +package recoverypoint + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]AzureBackupRecoveryPointResource +} + +type ListCompleteResult struct { + Items []AzureBackupRecoveryPointResource +} + +type ListOperationOptions struct { + Filter *string +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + return &out +} + +// List ... +func (c RecoveryPointClient) List(ctx context.Context, id BackupInstanceId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/recoveryPoints", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]AzureBackupRecoveryPointResource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c RecoveryPointClient) ListComplete(ctx context.Context, id BackupInstanceId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, AzureBackupRecoveryPointResourceOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c RecoveryPointClient) ListCompleteMatchingPredicate(ctx context.Context, id BackupInstanceId, options ListOperationOptions, predicate AzureBackupRecoveryPointResourceOperationPredicate) (result ListCompleteResult, err error) { + items := make([]AzureBackupRecoveryPointResource, 0) + + resp, err := c.List(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + Items: items, + } + return +} diff --git a/resource-manager/dataprotection/2023-11-01/recoverypoint/model_azurebackupdiscreterecoverypoint.go b/resource-manager/dataprotection/2023-11-01/recoverypoint/model_azurebackupdiscreterecoverypoint.go new file mode 100644 index 00000000000..ecc3e64361c --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/recoverypoint/model_azurebackupdiscreterecoverypoint.go @@ -0,0 +1,51 @@ +package recoverypoint + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ AzureBackupRecoveryPoint = AzureBackupDiscreteRecoveryPoint{} + +type AzureBackupDiscreteRecoveryPoint struct { + ExpiryTime *string `json:"expiryTime,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + PolicyName *string `json:"policyName,omitempty"` + PolicyVersion *string `json:"policyVersion,omitempty"` + RecoveryPointDataStoresDetails *[]RecoveryPointDataStoreDetails `json:"recoveryPointDataStoresDetails,omitempty"` + RecoveryPointId *string `json:"recoveryPointId,omitempty"` + RecoveryPointState *RecoveryPointCompletionState `json:"recoveryPointState,omitempty"` + RecoveryPointTime string `json:"recoveryPointTime"` + RecoveryPointType *string `json:"recoveryPointType,omitempty"` + RetentionTagName *string `json:"retentionTagName,omitempty"` + RetentionTagVersion *string `json:"retentionTagVersion,omitempty"` + + // Fields inherited from AzureBackupRecoveryPoint +} + +var _ json.Marshaler = AzureBackupDiscreteRecoveryPoint{} + +func (s AzureBackupDiscreteRecoveryPoint) MarshalJSON() ([]byte, error) { + type wrapper AzureBackupDiscreteRecoveryPoint + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureBackupDiscreteRecoveryPoint: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureBackupDiscreteRecoveryPoint: %+v", err) + } + decoded["objectType"] = "AzureBackupDiscreteRecoveryPoint" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureBackupDiscreteRecoveryPoint: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/dataprotection/2023-11-01/recoverypoint/model_azurebackuprecoverypoint.go b/resource-manager/dataprotection/2023-11-01/recoverypoint/model_azurebackuprecoverypoint.go new file mode 100644 index 00000000000..384f69a0f65 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/recoverypoint/model_azurebackuprecoverypoint.go @@ -0,0 +1,53 @@ +package recoverypoint + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureBackupRecoveryPoint interface { +} + +// RawAzureBackupRecoveryPointImpl is returned when the Discriminated Value +// doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawAzureBackupRecoveryPointImpl struct { + Type string + Values map[string]interface{} +} + +func unmarshalAzureBackupRecoveryPointImplementation(input []byte) (AzureBackupRecoveryPoint, error) { + if input == nil { + return nil, nil + } + + var temp map[string]interface{} + if err := json.Unmarshal(input, &temp); err != nil { + return nil, fmt.Errorf("unmarshaling AzureBackupRecoveryPoint into map[string]interface: %+v", err) + } + + value, ok := temp["objectType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "AzureBackupDiscreteRecoveryPoint") { + var out AzureBackupDiscreteRecoveryPoint + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureBackupDiscreteRecoveryPoint: %+v", err) + } + return out, nil + } + + out := RawAzureBackupRecoveryPointImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/dataprotection/2023-11-01/recoverypoint/model_azurebackuprecoverypointresource.go b/resource-manager/dataprotection/2023-11-01/recoverypoint/model_azurebackuprecoverypointresource.go new file mode 100644 index 00000000000..8f11d9bda9d --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/recoverypoint/model_azurebackuprecoverypointresource.go @@ -0,0 +1,48 @@ +package recoverypoint + +import ( + "encoding/json" + "fmt" + + "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 AzureBackupRecoveryPointResource struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties AzureBackupRecoveryPoint `json:"properties"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Unmarshaler = &AzureBackupRecoveryPointResource{} + +func (s *AzureBackupRecoveryPointResource) UnmarshalJSON(bytes []byte) error { + type alias AzureBackupRecoveryPointResource + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into AzureBackupRecoveryPointResource: %+v", err) + } + + s.Id = decoded.Id + s.Name = decoded.Name + s.SystemData = decoded.SystemData + s.Type = decoded.Type + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling AzureBackupRecoveryPointResource into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["properties"]; ok { + impl, err := unmarshalAzureBackupRecoveryPointImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'Properties' for 'AzureBackupRecoveryPointResource': %+v", err) + } + s.Properties = impl + } + return nil +} diff --git a/resource-manager/dataprotection/2023-11-01/recoverypoint/model_recoverypointdatastoredetails.go b/resource-manager/dataprotection/2023-11-01/recoverypoint/model_recoverypointdatastoredetails.go new file mode 100644 index 00000000000..0cde4767bde --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/recoverypoint/model_recoverypointdatastoredetails.go @@ -0,0 +1,58 @@ +package recoverypoint + +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 RecoveryPointDataStoreDetails struct { + CreationTime *string `json:"creationTime,omitempty"` + ExpiryTime *string `json:"expiryTime,omitempty"` + Id *string `json:"id,omitempty"` + MetaData *string `json:"metaData,omitempty"` + RehydrationExpiryTime *string `json:"rehydrationExpiryTime,omitempty"` + RehydrationStatus *RehydrationStatus `json:"rehydrationStatus,omitempty"` + State *string `json:"state,omitempty"` + Type *string `json:"type,omitempty"` + Visible *bool `json:"visible,omitempty"` +} + +func (o *RecoveryPointDataStoreDetails) GetCreationTimeAsTime() (*time.Time, error) { + if o.CreationTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreationTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *RecoveryPointDataStoreDetails) SetCreationTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreationTime = &formatted +} + +func (o *RecoveryPointDataStoreDetails) GetExpiryTimeAsTime() (*time.Time, error) { + if o.ExpiryTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ExpiryTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *RecoveryPointDataStoreDetails) SetExpiryTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ExpiryTime = &formatted +} + +func (o *RecoveryPointDataStoreDetails) GetRehydrationExpiryTimeAsTime() (*time.Time, error) { + if o.RehydrationExpiryTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.RehydrationExpiryTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *RecoveryPointDataStoreDetails) SetRehydrationExpiryTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.RehydrationExpiryTime = &formatted +} diff --git a/resource-manager/dataprotection/2023-11-01/recoverypoint/predicates.go b/resource-manager/dataprotection/2023-11-01/recoverypoint/predicates.go new file mode 100644 index 00000000000..4c929e3a8cc --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/recoverypoint/predicates.go @@ -0,0 +1,27 @@ +package recoverypoint + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureBackupRecoveryPointResourceOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p AzureBackupRecoveryPointResourceOperationPredicate) Matches(input AzureBackupRecoveryPointResource) 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/dataprotection/2023-11-01/recoverypoint/version.go b/resource-manager/dataprotection/2023-11-01/recoverypoint/version.go new file mode 100644 index 00000000000..1a61dab10a3 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/recoverypoint/version.go @@ -0,0 +1,12 @@ +package recoverypoint + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-11-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/recoverypoint/%s", defaultApiVersion) +} diff --git a/resource-manager/dataprotection/2023-11-01/resourceguards/README.md b/resource-manager/dataprotection/2023-11-01/resourceguards/README.md new file mode 100644 index 00000000000..d9c61ce355a --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/resourceguards/README.md @@ -0,0 +1,326 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2023-11-01/resourceguards` Documentation + +The `resourceguards` SDK allows for interaction with the Azure Resource Manager Service `dataprotection` (API Version `2023-11-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2023-11-01/resourceguards" +``` + + +### Client Initialization + +```go +client := resourceguards.NewResourceGuardsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ResourceGuardsClient.Delete` + +```go +ctx := context.TODO() +id := resourceguards.NewResourceGuardID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceGuardValue") + +read, err := client.Delete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ResourceGuardsClient.Get` + +```go +ctx := context.TODO() +id := resourceguards.NewResourceGuardID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceGuardValue") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ResourceGuardsClient.GetBackupSecurityPINRequestsObjects` + +```go +ctx := context.TODO() +id := resourceguards.NewResourceGuardID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceGuardValue") + +// alternatively `client.GetBackupSecurityPINRequestsObjects(ctx, id)` can be used to do batched pagination +items, err := client.GetBackupSecurityPINRequestsObjectsComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ResourceGuardsClient.GetDefaultBackupSecurityPINRequestsObject` + +```go +ctx := context.TODO() +id := resourceguards.NewGetBackupSecurityPINRequestID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceGuardValue", "getBackupSecurityPINRequestValue") + +read, err := client.GetDefaultBackupSecurityPINRequestsObject(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ResourceGuardsClient.GetDefaultDeleteProtectedItemRequestsObject` + +```go +ctx := context.TODO() +id := resourceguards.NewDeleteProtectedItemRequestID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceGuardValue", "deleteProtectedItemRequestValue") + +read, err := client.GetDefaultDeleteProtectedItemRequestsObject(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ResourceGuardsClient.GetDefaultDeleteResourceGuardProxyRequestsObject` + +```go +ctx := context.TODO() +id := resourceguards.NewDeleteResourceGuardProxyRequestID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceGuardValue", "deleteResourceGuardProxyRequestValue") + +read, err := client.GetDefaultDeleteResourceGuardProxyRequestsObject(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ResourceGuardsClient.GetDefaultDisableSoftDeleteRequestsObject` + +```go +ctx := context.TODO() +id := resourceguards.NewDisableSoftDeleteRequestID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceGuardValue", "disableSoftDeleteRequestValue") + +read, err := client.GetDefaultDisableSoftDeleteRequestsObject(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ResourceGuardsClient.GetDefaultUpdateProtectedItemRequestsObject` + +```go +ctx := context.TODO() +id := resourceguards.NewUpdateProtectedItemRequestID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceGuardValue", "updateProtectedItemRequestValue") + +read, err := client.GetDefaultUpdateProtectedItemRequestsObject(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ResourceGuardsClient.GetDefaultUpdateProtectionPolicyRequestsObject` + +```go +ctx := context.TODO() +id := resourceguards.NewUpdateProtectionPolicyRequestID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceGuardValue", "updateProtectionPolicyRequestValue") + +read, err := client.GetDefaultUpdateProtectionPolicyRequestsObject(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ResourceGuardsClient.GetDeleteProtectedItemRequestsObjects` + +```go +ctx := context.TODO() +id := resourceguards.NewResourceGuardID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceGuardValue") + +// alternatively `client.GetDeleteProtectedItemRequestsObjects(ctx, id)` can be used to do batched pagination +items, err := client.GetDeleteProtectedItemRequestsObjectsComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ResourceGuardsClient.GetDeleteResourceGuardProxyRequestsObjects` + +```go +ctx := context.TODO() +id := resourceguards.NewResourceGuardID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceGuardValue") + +// alternatively `client.GetDeleteResourceGuardProxyRequestsObjects(ctx, id)` can be used to do batched pagination +items, err := client.GetDeleteResourceGuardProxyRequestsObjectsComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ResourceGuardsClient.GetDisableSoftDeleteRequestsObjects` + +```go +ctx := context.TODO() +id := resourceguards.NewResourceGuardID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceGuardValue") + +// alternatively `client.GetDisableSoftDeleteRequestsObjects(ctx, id)` can be used to do batched pagination +items, err := client.GetDisableSoftDeleteRequestsObjectsComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ResourceGuardsClient.GetResourcesInResourceGroup` + +```go +ctx := context.TODO() +id := resourceguards.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +// alternatively `client.GetResourcesInResourceGroup(ctx, id)` can be used to do batched pagination +items, err := client.GetResourcesInResourceGroupComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ResourceGuardsClient.GetResourcesInSubscription` + +```go +ctx := context.TODO() +id := resourceguards.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.GetResourcesInSubscription(ctx, id)` can be used to do batched pagination +items, err := client.GetResourcesInSubscriptionComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ResourceGuardsClient.GetUpdateProtectedItemRequestsObjects` + +```go +ctx := context.TODO() +id := resourceguards.NewResourceGuardID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceGuardValue") + +// alternatively `client.GetUpdateProtectedItemRequestsObjects(ctx, id)` can be used to do batched pagination +items, err := client.GetUpdateProtectedItemRequestsObjectsComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ResourceGuardsClient.GetUpdateProtectionPolicyRequestsObjects` + +```go +ctx := context.TODO() +id := resourceguards.NewResourceGuardID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceGuardValue") + +// alternatively `client.GetUpdateProtectionPolicyRequestsObjects(ctx, id)` can be used to do batched pagination +items, err := client.GetUpdateProtectionPolicyRequestsObjectsComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ResourceGuardsClient.Patch` + +```go +ctx := context.TODO() +id := resourceguards.NewResourceGuardID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceGuardValue") + +payload := resourceguards.PatchResourceGuardInput{ + // ... +} + + +read, err := client.Patch(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ResourceGuardsClient.Put` + +```go +ctx := context.TODO() +id := resourceguards.NewResourceGuardID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceGuardValue") + +payload := resourceguards.ResourceGuardResource{ + // ... +} + + +read, err := client.Put(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/dataprotection/2023-11-01/resourceguards/client.go b/resource-manager/dataprotection/2023-11-01/resourceguards/client.go new file mode 100644 index 00000000000..2a79980112d --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/resourceguards/client.go @@ -0,0 +1,26 @@ +package resourceguards + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceGuardsClient struct { + Client *resourcemanager.Client +} + +func NewResourceGuardsClientWithBaseURI(sdkApi sdkEnv.Api) (*ResourceGuardsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "resourceguards", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ResourceGuardsClient: %+v", err) + } + + return &ResourceGuardsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/dataprotection/2023-11-01/resourceguards/constants.go b/resource-manager/dataprotection/2023-11-01/resourceguards/constants.go new file mode 100644 index 00000000000..883176c506a --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/resourceguards/constants.go @@ -0,0 +1,60 @@ +package resourceguards + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProvisioningState string + +const ( + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateProvisioning ProvisioningState = "Provisioning" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateUnknown ProvisioningState = "Unknown" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateFailed), + string(ProvisioningStateProvisioning), + string(ProvisioningStateSucceeded), + string(ProvisioningStateUnknown), + string(ProvisioningStateUpdating), + } +} + +func (s *ProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "failed": ProvisioningStateFailed, + "provisioning": ProvisioningStateProvisioning, + "succeeded": ProvisioningStateSucceeded, + "unknown": ProvisioningStateUnknown, + "updating": ProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProvisioningState(input) + return &out, nil +} diff --git a/resource-manager/dataprotection/2023-11-01/resourceguards/id_deleteprotecteditemrequest.go b/resource-manager/dataprotection/2023-11-01/resourceguards/id_deleteprotecteditemrequest.go new file mode 100644 index 00000000000..077bf5a8c05 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/resourceguards/id_deleteprotecteditemrequest.go @@ -0,0 +1,134 @@ +package resourceguards + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = DeleteProtectedItemRequestId{} + +// DeleteProtectedItemRequestId is a struct representing the Resource ID for a Delete Protected Item Request +type DeleteProtectedItemRequestId struct { + SubscriptionId string + ResourceGroupName string + ResourceGuardName string + DeleteProtectedItemRequestName string +} + +// NewDeleteProtectedItemRequestID returns a new DeleteProtectedItemRequestId struct +func NewDeleteProtectedItemRequestID(subscriptionId string, resourceGroupName string, resourceGuardName string, deleteProtectedItemRequestName string) DeleteProtectedItemRequestId { + return DeleteProtectedItemRequestId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ResourceGuardName: resourceGuardName, + DeleteProtectedItemRequestName: deleteProtectedItemRequestName, + } +} + +// ParseDeleteProtectedItemRequestID parses 'input' into a DeleteProtectedItemRequestId +func ParseDeleteProtectedItemRequestID(input string) (*DeleteProtectedItemRequestId, error) { + parser := resourceids.NewParserFromResourceIdType(DeleteProtectedItemRequestId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DeleteProtectedItemRequestId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseDeleteProtectedItemRequestIDInsensitively parses 'input' case-insensitively into a DeleteProtectedItemRequestId +// note: this method should only be used for API response data and not user input +func ParseDeleteProtectedItemRequestIDInsensitively(input string) (*DeleteProtectedItemRequestId, error) { + parser := resourceids.NewParserFromResourceIdType(DeleteProtectedItemRequestId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DeleteProtectedItemRequestId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *DeleteProtectedItemRequestId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.ResourceGuardName, ok = input.Parsed["resourceGuardName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGuardName", input) + } + + if id.DeleteProtectedItemRequestName, ok = input.Parsed["deleteProtectedItemRequestName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "deleteProtectedItemRequestName", input) + } + + return nil +} + +// ValidateDeleteProtectedItemRequestID checks that 'input' can be parsed as a Delete Protected Item Request ID +func ValidateDeleteProtectedItemRequestID(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 := ParseDeleteProtectedItemRequestID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Delete Protected Item Request ID +func (id DeleteProtectedItemRequestId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DataProtection/resourceGuards/%s/deleteProtectedItemRequests/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ResourceGuardName, id.DeleteProtectedItemRequestName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Delete Protected Item Request ID +func (id DeleteProtectedItemRequestId) 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("staticMicrosoftDataProtection", "Microsoft.DataProtection", "Microsoft.DataProtection"), + resourceids.StaticSegment("staticResourceGuards", "resourceGuards", "resourceGuards"), + resourceids.UserSpecifiedSegment("resourceGuardName", "resourceGuardValue"), + resourceids.StaticSegment("staticDeleteProtectedItemRequests", "deleteProtectedItemRequests", "deleteProtectedItemRequests"), + resourceids.UserSpecifiedSegment("deleteProtectedItemRequestName", "deleteProtectedItemRequestValue"), + } +} + +// String returns a human-readable description of this Delete Protected Item Request ID +func (id DeleteProtectedItemRequestId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Resource Guard Name: %q", id.ResourceGuardName), + fmt.Sprintf("Delete Protected Item Request Name: %q", id.DeleteProtectedItemRequestName), + } + return fmt.Sprintf("Delete Protected Item Request (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/dataprotection/2023-11-01/resourceguards/id_deleteprotecteditemrequest_test.go b/resource-manager/dataprotection/2023-11-01/resourceguards/id_deleteprotecteditemrequest_test.go new file mode 100644 index 00000000000..1aa41325d3e --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/resourceguards/id_deleteprotecteditemrequest_test.go @@ -0,0 +1,327 @@ +package resourceguards + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = DeleteProtectedItemRequestId{} + +func TestNewDeleteProtectedItemRequestID(t *testing.T) { + id := NewDeleteProtectedItemRequestID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceGuardValue", "deleteProtectedItemRequestValue") + + 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.ResourceGuardName != "resourceGuardValue" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGuardName'", id.ResourceGuardName, "resourceGuardValue") + } + + if id.DeleteProtectedItemRequestName != "deleteProtectedItemRequestValue" { + t.Fatalf("Expected %q but got %q for Segment 'DeleteProtectedItemRequestName'", id.DeleteProtectedItemRequestName, "deleteProtectedItemRequestValue") + } +} + +func TestFormatDeleteProtectedItemRequestID(t *testing.T) { + actual := NewDeleteProtectedItemRequestID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceGuardValue", "deleteProtectedItemRequestValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardValue/deleteProtectedItemRequests/deleteProtectedItemRequestValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseDeleteProtectedItemRequestID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DeleteProtectedItemRequestId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardValue/deleteProtectedItemRequests", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardValue/deleteProtectedItemRequests/deleteProtectedItemRequestValue", + Expected: &DeleteProtectedItemRequestId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ResourceGuardName: "resourceGuardValue", + DeleteProtectedItemRequestName: "deleteProtectedItemRequestValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardValue/deleteProtectedItemRequests/deleteProtectedItemRequestValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDeleteProtectedItemRequestID(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.ResourceGuardName != v.Expected.ResourceGuardName { + t.Fatalf("Expected %q but got %q for ResourceGuardName", v.Expected.ResourceGuardName, actual.ResourceGuardName) + } + + if actual.DeleteProtectedItemRequestName != v.Expected.DeleteProtectedItemRequestName { + t.Fatalf("Expected %q but got %q for DeleteProtectedItemRequestName", v.Expected.DeleteProtectedItemRequestName, actual.DeleteProtectedItemRequestName) + } + + } +} + +func TestParseDeleteProtectedItemRequestIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DeleteProtectedItemRequestId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/rEsOuRcEgUaRdS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/rEsOuRcEgUaRdS/rEsOuRcEgUaRdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardValue/deleteProtectedItemRequests", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/rEsOuRcEgUaRdS/rEsOuRcEgUaRdVaLuE/dElEtEpRoTeCtEdItEmReQuEsTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardValue/deleteProtectedItemRequests/deleteProtectedItemRequestValue", + Expected: &DeleteProtectedItemRequestId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ResourceGuardName: "resourceGuardValue", + DeleteProtectedItemRequestName: "deleteProtectedItemRequestValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardValue/deleteProtectedItemRequests/deleteProtectedItemRequestValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/rEsOuRcEgUaRdS/rEsOuRcEgUaRdVaLuE/dElEtEpRoTeCtEdItEmReQuEsTs/dElEtEpRoTeCtEdItEmReQuEsTvAlUe", + Expected: &DeleteProtectedItemRequestId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ResourceGuardName: "rEsOuRcEgUaRdVaLuE", + DeleteProtectedItemRequestName: "dElEtEpRoTeCtEdItEmReQuEsTvAlUe", + }, + }, + { + // 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.dAtApRoTeCtIoN/rEsOuRcEgUaRdS/rEsOuRcEgUaRdVaLuE/dElEtEpRoTeCtEdItEmReQuEsTs/dElEtEpRoTeCtEdItEmReQuEsTvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDeleteProtectedItemRequestIDInsensitively(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.ResourceGuardName != v.Expected.ResourceGuardName { + t.Fatalf("Expected %q but got %q for ResourceGuardName", v.Expected.ResourceGuardName, actual.ResourceGuardName) + } + + if actual.DeleteProtectedItemRequestName != v.Expected.DeleteProtectedItemRequestName { + t.Fatalf("Expected %q but got %q for DeleteProtectedItemRequestName", v.Expected.DeleteProtectedItemRequestName, actual.DeleteProtectedItemRequestName) + } + + } +} + +func TestSegmentsForDeleteProtectedItemRequestId(t *testing.T) { + segments := DeleteProtectedItemRequestId{}.Segments() + if len(segments) == 0 { + t.Fatalf("DeleteProtectedItemRequestId 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/dataprotection/2023-11-01/resourceguards/id_deleteresourceguardproxyrequest.go b/resource-manager/dataprotection/2023-11-01/resourceguards/id_deleteresourceguardproxyrequest.go new file mode 100644 index 00000000000..3bdca535a6f --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/resourceguards/id_deleteresourceguardproxyrequest.go @@ -0,0 +1,134 @@ +package resourceguards + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = DeleteResourceGuardProxyRequestId{} + +// DeleteResourceGuardProxyRequestId is a struct representing the Resource ID for a Delete Resource Guard Proxy Request +type DeleteResourceGuardProxyRequestId struct { + SubscriptionId string + ResourceGroupName string + ResourceGuardName string + DeleteResourceGuardProxyRequestName string +} + +// NewDeleteResourceGuardProxyRequestID returns a new DeleteResourceGuardProxyRequestId struct +func NewDeleteResourceGuardProxyRequestID(subscriptionId string, resourceGroupName string, resourceGuardName string, deleteResourceGuardProxyRequestName string) DeleteResourceGuardProxyRequestId { + return DeleteResourceGuardProxyRequestId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ResourceGuardName: resourceGuardName, + DeleteResourceGuardProxyRequestName: deleteResourceGuardProxyRequestName, + } +} + +// ParseDeleteResourceGuardProxyRequestID parses 'input' into a DeleteResourceGuardProxyRequestId +func ParseDeleteResourceGuardProxyRequestID(input string) (*DeleteResourceGuardProxyRequestId, error) { + parser := resourceids.NewParserFromResourceIdType(DeleteResourceGuardProxyRequestId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DeleteResourceGuardProxyRequestId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseDeleteResourceGuardProxyRequestIDInsensitively parses 'input' case-insensitively into a DeleteResourceGuardProxyRequestId +// note: this method should only be used for API response data and not user input +func ParseDeleteResourceGuardProxyRequestIDInsensitively(input string) (*DeleteResourceGuardProxyRequestId, error) { + parser := resourceids.NewParserFromResourceIdType(DeleteResourceGuardProxyRequestId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DeleteResourceGuardProxyRequestId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *DeleteResourceGuardProxyRequestId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.ResourceGuardName, ok = input.Parsed["resourceGuardName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGuardName", input) + } + + if id.DeleteResourceGuardProxyRequestName, ok = input.Parsed["deleteResourceGuardProxyRequestName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "deleteResourceGuardProxyRequestName", input) + } + + return nil +} + +// ValidateDeleteResourceGuardProxyRequestID checks that 'input' can be parsed as a Delete Resource Guard Proxy Request ID +func ValidateDeleteResourceGuardProxyRequestID(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 := ParseDeleteResourceGuardProxyRequestID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Delete Resource Guard Proxy Request ID +func (id DeleteResourceGuardProxyRequestId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DataProtection/resourceGuards/%s/deleteResourceGuardProxyRequests/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ResourceGuardName, id.DeleteResourceGuardProxyRequestName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Delete Resource Guard Proxy Request ID +func (id DeleteResourceGuardProxyRequestId) 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("staticMicrosoftDataProtection", "Microsoft.DataProtection", "Microsoft.DataProtection"), + resourceids.StaticSegment("staticResourceGuards", "resourceGuards", "resourceGuards"), + resourceids.UserSpecifiedSegment("resourceGuardName", "resourceGuardValue"), + resourceids.StaticSegment("staticDeleteResourceGuardProxyRequests", "deleteResourceGuardProxyRequests", "deleteResourceGuardProxyRequests"), + resourceids.UserSpecifiedSegment("deleteResourceGuardProxyRequestName", "deleteResourceGuardProxyRequestValue"), + } +} + +// String returns a human-readable description of this Delete Resource Guard Proxy Request ID +func (id DeleteResourceGuardProxyRequestId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Resource Guard Name: %q", id.ResourceGuardName), + fmt.Sprintf("Delete Resource Guard Proxy Request Name: %q", id.DeleteResourceGuardProxyRequestName), + } + return fmt.Sprintf("Delete Resource Guard Proxy Request (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/dataprotection/2023-11-01/resourceguards/id_deleteresourceguardproxyrequest_test.go b/resource-manager/dataprotection/2023-11-01/resourceguards/id_deleteresourceguardproxyrequest_test.go new file mode 100644 index 00000000000..f58a831df0c --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/resourceguards/id_deleteresourceguardproxyrequest_test.go @@ -0,0 +1,327 @@ +package resourceguards + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = DeleteResourceGuardProxyRequestId{} + +func TestNewDeleteResourceGuardProxyRequestID(t *testing.T) { + id := NewDeleteResourceGuardProxyRequestID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceGuardValue", "deleteResourceGuardProxyRequestValue") + + 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.ResourceGuardName != "resourceGuardValue" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGuardName'", id.ResourceGuardName, "resourceGuardValue") + } + + if id.DeleteResourceGuardProxyRequestName != "deleteResourceGuardProxyRequestValue" { + t.Fatalf("Expected %q but got %q for Segment 'DeleteResourceGuardProxyRequestName'", id.DeleteResourceGuardProxyRequestName, "deleteResourceGuardProxyRequestValue") + } +} + +func TestFormatDeleteResourceGuardProxyRequestID(t *testing.T) { + actual := NewDeleteResourceGuardProxyRequestID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceGuardValue", "deleteResourceGuardProxyRequestValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardValue/deleteResourceGuardProxyRequests/deleteResourceGuardProxyRequestValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseDeleteResourceGuardProxyRequestID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DeleteResourceGuardProxyRequestId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardValue/deleteResourceGuardProxyRequests", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardValue/deleteResourceGuardProxyRequests/deleteResourceGuardProxyRequestValue", + Expected: &DeleteResourceGuardProxyRequestId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ResourceGuardName: "resourceGuardValue", + DeleteResourceGuardProxyRequestName: "deleteResourceGuardProxyRequestValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardValue/deleteResourceGuardProxyRequests/deleteResourceGuardProxyRequestValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDeleteResourceGuardProxyRequestID(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.ResourceGuardName != v.Expected.ResourceGuardName { + t.Fatalf("Expected %q but got %q for ResourceGuardName", v.Expected.ResourceGuardName, actual.ResourceGuardName) + } + + if actual.DeleteResourceGuardProxyRequestName != v.Expected.DeleteResourceGuardProxyRequestName { + t.Fatalf("Expected %q but got %q for DeleteResourceGuardProxyRequestName", v.Expected.DeleteResourceGuardProxyRequestName, actual.DeleteResourceGuardProxyRequestName) + } + + } +} + +func TestParseDeleteResourceGuardProxyRequestIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DeleteResourceGuardProxyRequestId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/rEsOuRcEgUaRdS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/rEsOuRcEgUaRdS/rEsOuRcEgUaRdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardValue/deleteResourceGuardProxyRequests", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/rEsOuRcEgUaRdS/rEsOuRcEgUaRdVaLuE/dElEtErEsOuRcEgUaRdPrOxYrEqUeStS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardValue/deleteResourceGuardProxyRequests/deleteResourceGuardProxyRequestValue", + Expected: &DeleteResourceGuardProxyRequestId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ResourceGuardName: "resourceGuardValue", + DeleteResourceGuardProxyRequestName: "deleteResourceGuardProxyRequestValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardValue/deleteResourceGuardProxyRequests/deleteResourceGuardProxyRequestValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/rEsOuRcEgUaRdS/rEsOuRcEgUaRdVaLuE/dElEtErEsOuRcEgUaRdPrOxYrEqUeStS/dElEtErEsOuRcEgUaRdPrOxYrEqUeStVaLuE", + Expected: &DeleteResourceGuardProxyRequestId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ResourceGuardName: "rEsOuRcEgUaRdVaLuE", + DeleteResourceGuardProxyRequestName: "dElEtErEsOuRcEgUaRdPrOxYrEqUeStVaLuE", + }, + }, + { + // 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.dAtApRoTeCtIoN/rEsOuRcEgUaRdS/rEsOuRcEgUaRdVaLuE/dElEtErEsOuRcEgUaRdPrOxYrEqUeStS/dElEtErEsOuRcEgUaRdPrOxYrEqUeStVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDeleteResourceGuardProxyRequestIDInsensitively(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.ResourceGuardName != v.Expected.ResourceGuardName { + t.Fatalf("Expected %q but got %q for ResourceGuardName", v.Expected.ResourceGuardName, actual.ResourceGuardName) + } + + if actual.DeleteResourceGuardProxyRequestName != v.Expected.DeleteResourceGuardProxyRequestName { + t.Fatalf("Expected %q but got %q for DeleteResourceGuardProxyRequestName", v.Expected.DeleteResourceGuardProxyRequestName, actual.DeleteResourceGuardProxyRequestName) + } + + } +} + +func TestSegmentsForDeleteResourceGuardProxyRequestId(t *testing.T) { + segments := DeleteResourceGuardProxyRequestId{}.Segments() + if len(segments) == 0 { + t.Fatalf("DeleteResourceGuardProxyRequestId 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/dataprotection/2023-11-01/resourceguards/id_disablesoftdeleterequest.go b/resource-manager/dataprotection/2023-11-01/resourceguards/id_disablesoftdeleterequest.go new file mode 100644 index 00000000000..51e4b8a6126 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/resourceguards/id_disablesoftdeleterequest.go @@ -0,0 +1,134 @@ +package resourceguards + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = DisableSoftDeleteRequestId{} + +// DisableSoftDeleteRequestId is a struct representing the Resource ID for a Disable Soft Delete Request +type DisableSoftDeleteRequestId struct { + SubscriptionId string + ResourceGroupName string + ResourceGuardName string + DisableSoftDeleteRequestName string +} + +// NewDisableSoftDeleteRequestID returns a new DisableSoftDeleteRequestId struct +func NewDisableSoftDeleteRequestID(subscriptionId string, resourceGroupName string, resourceGuardName string, disableSoftDeleteRequestName string) DisableSoftDeleteRequestId { + return DisableSoftDeleteRequestId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ResourceGuardName: resourceGuardName, + DisableSoftDeleteRequestName: disableSoftDeleteRequestName, + } +} + +// ParseDisableSoftDeleteRequestID parses 'input' into a DisableSoftDeleteRequestId +func ParseDisableSoftDeleteRequestID(input string) (*DisableSoftDeleteRequestId, error) { + parser := resourceids.NewParserFromResourceIdType(DisableSoftDeleteRequestId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DisableSoftDeleteRequestId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseDisableSoftDeleteRequestIDInsensitively parses 'input' case-insensitively into a DisableSoftDeleteRequestId +// note: this method should only be used for API response data and not user input +func ParseDisableSoftDeleteRequestIDInsensitively(input string) (*DisableSoftDeleteRequestId, error) { + parser := resourceids.NewParserFromResourceIdType(DisableSoftDeleteRequestId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DisableSoftDeleteRequestId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *DisableSoftDeleteRequestId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.ResourceGuardName, ok = input.Parsed["resourceGuardName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGuardName", input) + } + + if id.DisableSoftDeleteRequestName, ok = input.Parsed["disableSoftDeleteRequestName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "disableSoftDeleteRequestName", input) + } + + return nil +} + +// ValidateDisableSoftDeleteRequestID checks that 'input' can be parsed as a Disable Soft Delete Request ID +func ValidateDisableSoftDeleteRequestID(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 := ParseDisableSoftDeleteRequestID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Disable Soft Delete Request ID +func (id DisableSoftDeleteRequestId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DataProtection/resourceGuards/%s/disableSoftDeleteRequests/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ResourceGuardName, id.DisableSoftDeleteRequestName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Disable Soft Delete Request ID +func (id DisableSoftDeleteRequestId) 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("staticMicrosoftDataProtection", "Microsoft.DataProtection", "Microsoft.DataProtection"), + resourceids.StaticSegment("staticResourceGuards", "resourceGuards", "resourceGuards"), + resourceids.UserSpecifiedSegment("resourceGuardName", "resourceGuardValue"), + resourceids.StaticSegment("staticDisableSoftDeleteRequests", "disableSoftDeleteRequests", "disableSoftDeleteRequests"), + resourceids.UserSpecifiedSegment("disableSoftDeleteRequestName", "disableSoftDeleteRequestValue"), + } +} + +// String returns a human-readable description of this Disable Soft Delete Request ID +func (id DisableSoftDeleteRequestId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Resource Guard Name: %q", id.ResourceGuardName), + fmt.Sprintf("Disable Soft Delete Request Name: %q", id.DisableSoftDeleteRequestName), + } + return fmt.Sprintf("Disable Soft Delete Request (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/dataprotection/2023-11-01/resourceguards/id_disablesoftdeleterequest_test.go b/resource-manager/dataprotection/2023-11-01/resourceguards/id_disablesoftdeleterequest_test.go new file mode 100644 index 00000000000..1d6808cbf81 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/resourceguards/id_disablesoftdeleterequest_test.go @@ -0,0 +1,327 @@ +package resourceguards + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = DisableSoftDeleteRequestId{} + +func TestNewDisableSoftDeleteRequestID(t *testing.T) { + id := NewDisableSoftDeleteRequestID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceGuardValue", "disableSoftDeleteRequestValue") + + 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.ResourceGuardName != "resourceGuardValue" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGuardName'", id.ResourceGuardName, "resourceGuardValue") + } + + if id.DisableSoftDeleteRequestName != "disableSoftDeleteRequestValue" { + t.Fatalf("Expected %q but got %q for Segment 'DisableSoftDeleteRequestName'", id.DisableSoftDeleteRequestName, "disableSoftDeleteRequestValue") + } +} + +func TestFormatDisableSoftDeleteRequestID(t *testing.T) { + actual := NewDisableSoftDeleteRequestID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceGuardValue", "disableSoftDeleteRequestValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardValue/disableSoftDeleteRequests/disableSoftDeleteRequestValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseDisableSoftDeleteRequestID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DisableSoftDeleteRequestId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardValue/disableSoftDeleteRequests", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardValue/disableSoftDeleteRequests/disableSoftDeleteRequestValue", + Expected: &DisableSoftDeleteRequestId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ResourceGuardName: "resourceGuardValue", + DisableSoftDeleteRequestName: "disableSoftDeleteRequestValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardValue/disableSoftDeleteRequests/disableSoftDeleteRequestValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDisableSoftDeleteRequestID(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.ResourceGuardName != v.Expected.ResourceGuardName { + t.Fatalf("Expected %q but got %q for ResourceGuardName", v.Expected.ResourceGuardName, actual.ResourceGuardName) + } + + if actual.DisableSoftDeleteRequestName != v.Expected.DisableSoftDeleteRequestName { + t.Fatalf("Expected %q but got %q for DisableSoftDeleteRequestName", v.Expected.DisableSoftDeleteRequestName, actual.DisableSoftDeleteRequestName) + } + + } +} + +func TestParseDisableSoftDeleteRequestIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DisableSoftDeleteRequestId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/rEsOuRcEgUaRdS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/rEsOuRcEgUaRdS/rEsOuRcEgUaRdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardValue/disableSoftDeleteRequests", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/rEsOuRcEgUaRdS/rEsOuRcEgUaRdVaLuE/dIsAbLeSoFtDeLeTeReQuEsTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardValue/disableSoftDeleteRequests/disableSoftDeleteRequestValue", + Expected: &DisableSoftDeleteRequestId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ResourceGuardName: "resourceGuardValue", + DisableSoftDeleteRequestName: "disableSoftDeleteRequestValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardValue/disableSoftDeleteRequests/disableSoftDeleteRequestValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/rEsOuRcEgUaRdS/rEsOuRcEgUaRdVaLuE/dIsAbLeSoFtDeLeTeReQuEsTs/dIsAbLeSoFtDeLeTeReQuEsTvAlUe", + Expected: &DisableSoftDeleteRequestId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ResourceGuardName: "rEsOuRcEgUaRdVaLuE", + DisableSoftDeleteRequestName: "dIsAbLeSoFtDeLeTeReQuEsTvAlUe", + }, + }, + { + // 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.dAtApRoTeCtIoN/rEsOuRcEgUaRdS/rEsOuRcEgUaRdVaLuE/dIsAbLeSoFtDeLeTeReQuEsTs/dIsAbLeSoFtDeLeTeReQuEsTvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDisableSoftDeleteRequestIDInsensitively(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.ResourceGuardName != v.Expected.ResourceGuardName { + t.Fatalf("Expected %q but got %q for ResourceGuardName", v.Expected.ResourceGuardName, actual.ResourceGuardName) + } + + if actual.DisableSoftDeleteRequestName != v.Expected.DisableSoftDeleteRequestName { + t.Fatalf("Expected %q but got %q for DisableSoftDeleteRequestName", v.Expected.DisableSoftDeleteRequestName, actual.DisableSoftDeleteRequestName) + } + + } +} + +func TestSegmentsForDisableSoftDeleteRequestId(t *testing.T) { + segments := DisableSoftDeleteRequestId{}.Segments() + if len(segments) == 0 { + t.Fatalf("DisableSoftDeleteRequestId 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/dataprotection/2023-11-01/resourceguards/id_getbackupsecuritypinrequest.go b/resource-manager/dataprotection/2023-11-01/resourceguards/id_getbackupsecuritypinrequest.go new file mode 100644 index 00000000000..5c057ffdbc9 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/resourceguards/id_getbackupsecuritypinrequest.go @@ -0,0 +1,134 @@ +package resourceguards + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = GetBackupSecurityPINRequestId{} + +// GetBackupSecurityPINRequestId is a struct representing the Resource ID for a Get Backup Security P I N Request +type GetBackupSecurityPINRequestId struct { + SubscriptionId string + ResourceGroupName string + ResourceGuardName string + GetBackupSecurityPINRequestName string +} + +// NewGetBackupSecurityPINRequestID returns a new GetBackupSecurityPINRequestId struct +func NewGetBackupSecurityPINRequestID(subscriptionId string, resourceGroupName string, resourceGuardName string, getBackupSecurityPINRequestName string) GetBackupSecurityPINRequestId { + return GetBackupSecurityPINRequestId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ResourceGuardName: resourceGuardName, + GetBackupSecurityPINRequestName: getBackupSecurityPINRequestName, + } +} + +// ParseGetBackupSecurityPINRequestID parses 'input' into a GetBackupSecurityPINRequestId +func ParseGetBackupSecurityPINRequestID(input string) (*GetBackupSecurityPINRequestId, error) { + parser := resourceids.NewParserFromResourceIdType(GetBackupSecurityPINRequestId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := GetBackupSecurityPINRequestId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseGetBackupSecurityPINRequestIDInsensitively parses 'input' case-insensitively into a GetBackupSecurityPINRequestId +// note: this method should only be used for API response data and not user input +func ParseGetBackupSecurityPINRequestIDInsensitively(input string) (*GetBackupSecurityPINRequestId, error) { + parser := resourceids.NewParserFromResourceIdType(GetBackupSecurityPINRequestId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := GetBackupSecurityPINRequestId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *GetBackupSecurityPINRequestId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.ResourceGuardName, ok = input.Parsed["resourceGuardName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGuardName", input) + } + + if id.GetBackupSecurityPINRequestName, ok = input.Parsed["getBackupSecurityPINRequestName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "getBackupSecurityPINRequestName", input) + } + + return nil +} + +// ValidateGetBackupSecurityPINRequestID checks that 'input' can be parsed as a Get Backup Security P I N Request ID +func ValidateGetBackupSecurityPINRequestID(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 := ParseGetBackupSecurityPINRequestID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Get Backup Security P I N Request ID +func (id GetBackupSecurityPINRequestId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DataProtection/resourceGuards/%s/getBackupSecurityPINRequests/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ResourceGuardName, id.GetBackupSecurityPINRequestName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Get Backup Security P I N Request ID +func (id GetBackupSecurityPINRequestId) 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("staticMicrosoftDataProtection", "Microsoft.DataProtection", "Microsoft.DataProtection"), + resourceids.StaticSegment("staticResourceGuards", "resourceGuards", "resourceGuards"), + resourceids.UserSpecifiedSegment("resourceGuardName", "resourceGuardValue"), + resourceids.StaticSegment("staticGetBackupSecurityPINRequests", "getBackupSecurityPINRequests", "getBackupSecurityPINRequests"), + resourceids.UserSpecifiedSegment("getBackupSecurityPINRequestName", "getBackupSecurityPINRequestValue"), + } +} + +// String returns a human-readable description of this Get Backup Security P I N Request ID +func (id GetBackupSecurityPINRequestId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Resource Guard Name: %q", id.ResourceGuardName), + fmt.Sprintf("Get Backup Security P I N Request Name: %q", id.GetBackupSecurityPINRequestName), + } + return fmt.Sprintf("Get Backup Security P I N Request (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/dataprotection/2023-11-01/resourceguards/id_getbackupsecuritypinrequest_test.go b/resource-manager/dataprotection/2023-11-01/resourceguards/id_getbackupsecuritypinrequest_test.go new file mode 100644 index 00000000000..f5eb47d5673 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/resourceguards/id_getbackupsecuritypinrequest_test.go @@ -0,0 +1,327 @@ +package resourceguards + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = GetBackupSecurityPINRequestId{} + +func TestNewGetBackupSecurityPINRequestID(t *testing.T) { + id := NewGetBackupSecurityPINRequestID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceGuardValue", "getBackupSecurityPINRequestValue") + + 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.ResourceGuardName != "resourceGuardValue" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGuardName'", id.ResourceGuardName, "resourceGuardValue") + } + + if id.GetBackupSecurityPINRequestName != "getBackupSecurityPINRequestValue" { + t.Fatalf("Expected %q but got %q for Segment 'GetBackupSecurityPINRequestName'", id.GetBackupSecurityPINRequestName, "getBackupSecurityPINRequestValue") + } +} + +func TestFormatGetBackupSecurityPINRequestID(t *testing.T) { + actual := NewGetBackupSecurityPINRequestID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceGuardValue", "getBackupSecurityPINRequestValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardValue/getBackupSecurityPINRequests/getBackupSecurityPINRequestValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseGetBackupSecurityPINRequestID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *GetBackupSecurityPINRequestId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardValue/getBackupSecurityPINRequests", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardValue/getBackupSecurityPINRequests/getBackupSecurityPINRequestValue", + Expected: &GetBackupSecurityPINRequestId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ResourceGuardName: "resourceGuardValue", + GetBackupSecurityPINRequestName: "getBackupSecurityPINRequestValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardValue/getBackupSecurityPINRequests/getBackupSecurityPINRequestValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseGetBackupSecurityPINRequestID(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.ResourceGuardName != v.Expected.ResourceGuardName { + t.Fatalf("Expected %q but got %q for ResourceGuardName", v.Expected.ResourceGuardName, actual.ResourceGuardName) + } + + if actual.GetBackupSecurityPINRequestName != v.Expected.GetBackupSecurityPINRequestName { + t.Fatalf("Expected %q but got %q for GetBackupSecurityPINRequestName", v.Expected.GetBackupSecurityPINRequestName, actual.GetBackupSecurityPINRequestName) + } + + } +} + +func TestParseGetBackupSecurityPINRequestIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *GetBackupSecurityPINRequestId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/rEsOuRcEgUaRdS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/rEsOuRcEgUaRdS/rEsOuRcEgUaRdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardValue/getBackupSecurityPINRequests", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/rEsOuRcEgUaRdS/rEsOuRcEgUaRdVaLuE/gEtBaCkUpSeCuRiTyPiNrEqUeStS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardValue/getBackupSecurityPINRequests/getBackupSecurityPINRequestValue", + Expected: &GetBackupSecurityPINRequestId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ResourceGuardName: "resourceGuardValue", + GetBackupSecurityPINRequestName: "getBackupSecurityPINRequestValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardValue/getBackupSecurityPINRequests/getBackupSecurityPINRequestValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/rEsOuRcEgUaRdS/rEsOuRcEgUaRdVaLuE/gEtBaCkUpSeCuRiTyPiNrEqUeStS/gEtBaCkUpSeCuRiTyPiNrEqUeStVaLuE", + Expected: &GetBackupSecurityPINRequestId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ResourceGuardName: "rEsOuRcEgUaRdVaLuE", + GetBackupSecurityPINRequestName: "gEtBaCkUpSeCuRiTyPiNrEqUeStVaLuE", + }, + }, + { + // 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.dAtApRoTeCtIoN/rEsOuRcEgUaRdS/rEsOuRcEgUaRdVaLuE/gEtBaCkUpSeCuRiTyPiNrEqUeStS/gEtBaCkUpSeCuRiTyPiNrEqUeStVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseGetBackupSecurityPINRequestIDInsensitively(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.ResourceGuardName != v.Expected.ResourceGuardName { + t.Fatalf("Expected %q but got %q for ResourceGuardName", v.Expected.ResourceGuardName, actual.ResourceGuardName) + } + + if actual.GetBackupSecurityPINRequestName != v.Expected.GetBackupSecurityPINRequestName { + t.Fatalf("Expected %q but got %q for GetBackupSecurityPINRequestName", v.Expected.GetBackupSecurityPINRequestName, actual.GetBackupSecurityPINRequestName) + } + + } +} + +func TestSegmentsForGetBackupSecurityPINRequestId(t *testing.T) { + segments := GetBackupSecurityPINRequestId{}.Segments() + if len(segments) == 0 { + t.Fatalf("GetBackupSecurityPINRequestId 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/dataprotection/2023-11-01/resourceguards/id_resourceguard.go b/resource-manager/dataprotection/2023-11-01/resourceguards/id_resourceguard.go new file mode 100644 index 00000000000..e6e61f5477f --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/resourceguards/id_resourceguard.go @@ -0,0 +1,125 @@ +package resourceguards + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = ResourceGuardId{} + +// ResourceGuardId is a struct representing the Resource ID for a Resource Guard +type ResourceGuardId struct { + SubscriptionId string + ResourceGroupName string + ResourceGuardName string +} + +// NewResourceGuardID returns a new ResourceGuardId struct +func NewResourceGuardID(subscriptionId string, resourceGroupName string, resourceGuardName string) ResourceGuardId { + return ResourceGuardId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ResourceGuardName: resourceGuardName, + } +} + +// ParseResourceGuardID parses 'input' into a ResourceGuardId +func ParseResourceGuardID(input string) (*ResourceGuardId, error) { + parser := resourceids.NewParserFromResourceIdType(ResourceGuardId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ResourceGuardId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseResourceGuardIDInsensitively parses 'input' case-insensitively into a ResourceGuardId +// note: this method should only be used for API response data and not user input +func ParseResourceGuardIDInsensitively(input string) (*ResourceGuardId, error) { + parser := resourceids.NewParserFromResourceIdType(ResourceGuardId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ResourceGuardId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ResourceGuardId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.ResourceGuardName, ok = input.Parsed["resourceGuardName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGuardName", input) + } + + return nil +} + +// ValidateResourceGuardID checks that 'input' can be parsed as a Resource Guard ID +func ValidateResourceGuardID(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 := ParseResourceGuardID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Resource Guard ID +func (id ResourceGuardId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DataProtection/resourceGuards/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ResourceGuardName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Resource Guard ID +func (id ResourceGuardId) 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("staticMicrosoftDataProtection", "Microsoft.DataProtection", "Microsoft.DataProtection"), + resourceids.StaticSegment("staticResourceGuards", "resourceGuards", "resourceGuards"), + resourceids.UserSpecifiedSegment("resourceGuardName", "resourceGuardValue"), + } +} + +// String returns a human-readable description of this Resource Guard ID +func (id ResourceGuardId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Resource Guard Name: %q", id.ResourceGuardName), + } + return fmt.Sprintf("Resource Guard (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/dataprotection/2023-11-01/resourceguards/id_resourceguard_test.go b/resource-manager/dataprotection/2023-11-01/resourceguards/id_resourceguard_test.go new file mode 100644 index 00000000000..711026744f5 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/resourceguards/id_resourceguard_test.go @@ -0,0 +1,282 @@ +package resourceguards + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = ResourceGuardId{} + +func TestNewResourceGuardID(t *testing.T) { + id := NewResourceGuardID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceGuardValue") + + 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.ResourceGuardName != "resourceGuardValue" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGuardName'", id.ResourceGuardName, "resourceGuardValue") + } +} + +func TestFormatResourceGuardID(t *testing.T) { + actual := NewResourceGuardID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceGuardValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseResourceGuardID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ResourceGuardId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardValue", + Expected: &ResourceGuardId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ResourceGuardName: "resourceGuardValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseResourceGuardID(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.ResourceGuardName != v.Expected.ResourceGuardName { + t.Fatalf("Expected %q but got %q for ResourceGuardName", v.Expected.ResourceGuardName, actual.ResourceGuardName) + } + + } +} + +func TestParseResourceGuardIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ResourceGuardId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/rEsOuRcEgUaRdS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardValue", + Expected: &ResourceGuardId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ResourceGuardName: "resourceGuardValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/rEsOuRcEgUaRdS/rEsOuRcEgUaRdVaLuE", + Expected: &ResourceGuardId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ResourceGuardName: "rEsOuRcEgUaRdVaLuE", + }, + }, + { + // 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.dAtApRoTeCtIoN/rEsOuRcEgUaRdS/rEsOuRcEgUaRdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseResourceGuardIDInsensitively(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.ResourceGuardName != v.Expected.ResourceGuardName { + t.Fatalf("Expected %q but got %q for ResourceGuardName", v.Expected.ResourceGuardName, actual.ResourceGuardName) + } + + } +} + +func TestSegmentsForResourceGuardId(t *testing.T) { + segments := ResourceGuardId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ResourceGuardId 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/dataprotection/2023-11-01/resourceguards/id_updateprotecteditemrequest.go b/resource-manager/dataprotection/2023-11-01/resourceguards/id_updateprotecteditemrequest.go new file mode 100644 index 00000000000..0010cc6cb2f --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/resourceguards/id_updateprotecteditemrequest.go @@ -0,0 +1,134 @@ +package resourceguards + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = UpdateProtectedItemRequestId{} + +// UpdateProtectedItemRequestId is a struct representing the Resource ID for a Update Protected Item Request +type UpdateProtectedItemRequestId struct { + SubscriptionId string + ResourceGroupName string + ResourceGuardName string + UpdateProtectedItemRequestName string +} + +// NewUpdateProtectedItemRequestID returns a new UpdateProtectedItemRequestId struct +func NewUpdateProtectedItemRequestID(subscriptionId string, resourceGroupName string, resourceGuardName string, updateProtectedItemRequestName string) UpdateProtectedItemRequestId { + return UpdateProtectedItemRequestId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ResourceGuardName: resourceGuardName, + UpdateProtectedItemRequestName: updateProtectedItemRequestName, + } +} + +// ParseUpdateProtectedItemRequestID parses 'input' into a UpdateProtectedItemRequestId +func ParseUpdateProtectedItemRequestID(input string) (*UpdateProtectedItemRequestId, error) { + parser := resourceids.NewParserFromResourceIdType(UpdateProtectedItemRequestId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := UpdateProtectedItemRequestId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseUpdateProtectedItemRequestIDInsensitively parses 'input' case-insensitively into a UpdateProtectedItemRequestId +// note: this method should only be used for API response data and not user input +func ParseUpdateProtectedItemRequestIDInsensitively(input string) (*UpdateProtectedItemRequestId, error) { + parser := resourceids.NewParserFromResourceIdType(UpdateProtectedItemRequestId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := UpdateProtectedItemRequestId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *UpdateProtectedItemRequestId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.ResourceGuardName, ok = input.Parsed["resourceGuardName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGuardName", input) + } + + if id.UpdateProtectedItemRequestName, ok = input.Parsed["updateProtectedItemRequestName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "updateProtectedItemRequestName", input) + } + + return nil +} + +// ValidateUpdateProtectedItemRequestID checks that 'input' can be parsed as a Update Protected Item Request ID +func ValidateUpdateProtectedItemRequestID(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 := ParseUpdateProtectedItemRequestID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Update Protected Item Request ID +func (id UpdateProtectedItemRequestId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DataProtection/resourceGuards/%s/updateProtectedItemRequests/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ResourceGuardName, id.UpdateProtectedItemRequestName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Update Protected Item Request ID +func (id UpdateProtectedItemRequestId) 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("staticMicrosoftDataProtection", "Microsoft.DataProtection", "Microsoft.DataProtection"), + resourceids.StaticSegment("staticResourceGuards", "resourceGuards", "resourceGuards"), + resourceids.UserSpecifiedSegment("resourceGuardName", "resourceGuardValue"), + resourceids.StaticSegment("staticUpdateProtectedItemRequests", "updateProtectedItemRequests", "updateProtectedItemRequests"), + resourceids.UserSpecifiedSegment("updateProtectedItemRequestName", "updateProtectedItemRequestValue"), + } +} + +// String returns a human-readable description of this Update Protected Item Request ID +func (id UpdateProtectedItemRequestId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Resource Guard Name: %q", id.ResourceGuardName), + fmt.Sprintf("Update Protected Item Request Name: %q", id.UpdateProtectedItemRequestName), + } + return fmt.Sprintf("Update Protected Item Request (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/dataprotection/2023-11-01/resourceguards/id_updateprotecteditemrequest_test.go b/resource-manager/dataprotection/2023-11-01/resourceguards/id_updateprotecteditemrequest_test.go new file mode 100644 index 00000000000..7297ff9cbe6 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/resourceguards/id_updateprotecteditemrequest_test.go @@ -0,0 +1,327 @@ +package resourceguards + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = UpdateProtectedItemRequestId{} + +func TestNewUpdateProtectedItemRequestID(t *testing.T) { + id := NewUpdateProtectedItemRequestID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceGuardValue", "updateProtectedItemRequestValue") + + 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.ResourceGuardName != "resourceGuardValue" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGuardName'", id.ResourceGuardName, "resourceGuardValue") + } + + if id.UpdateProtectedItemRequestName != "updateProtectedItemRequestValue" { + t.Fatalf("Expected %q but got %q for Segment 'UpdateProtectedItemRequestName'", id.UpdateProtectedItemRequestName, "updateProtectedItemRequestValue") + } +} + +func TestFormatUpdateProtectedItemRequestID(t *testing.T) { + actual := NewUpdateProtectedItemRequestID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceGuardValue", "updateProtectedItemRequestValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardValue/updateProtectedItemRequests/updateProtectedItemRequestValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseUpdateProtectedItemRequestID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *UpdateProtectedItemRequestId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardValue/updateProtectedItemRequests", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardValue/updateProtectedItemRequests/updateProtectedItemRequestValue", + Expected: &UpdateProtectedItemRequestId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ResourceGuardName: "resourceGuardValue", + UpdateProtectedItemRequestName: "updateProtectedItemRequestValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardValue/updateProtectedItemRequests/updateProtectedItemRequestValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseUpdateProtectedItemRequestID(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.ResourceGuardName != v.Expected.ResourceGuardName { + t.Fatalf("Expected %q but got %q for ResourceGuardName", v.Expected.ResourceGuardName, actual.ResourceGuardName) + } + + if actual.UpdateProtectedItemRequestName != v.Expected.UpdateProtectedItemRequestName { + t.Fatalf("Expected %q but got %q for UpdateProtectedItemRequestName", v.Expected.UpdateProtectedItemRequestName, actual.UpdateProtectedItemRequestName) + } + + } +} + +func TestParseUpdateProtectedItemRequestIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *UpdateProtectedItemRequestId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/rEsOuRcEgUaRdS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/rEsOuRcEgUaRdS/rEsOuRcEgUaRdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardValue/updateProtectedItemRequests", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/rEsOuRcEgUaRdS/rEsOuRcEgUaRdVaLuE/uPdAtEpRoTeCtEdItEmReQuEsTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardValue/updateProtectedItemRequests/updateProtectedItemRequestValue", + Expected: &UpdateProtectedItemRequestId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ResourceGuardName: "resourceGuardValue", + UpdateProtectedItemRequestName: "updateProtectedItemRequestValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardValue/updateProtectedItemRequests/updateProtectedItemRequestValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/rEsOuRcEgUaRdS/rEsOuRcEgUaRdVaLuE/uPdAtEpRoTeCtEdItEmReQuEsTs/uPdAtEpRoTeCtEdItEmReQuEsTvAlUe", + Expected: &UpdateProtectedItemRequestId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ResourceGuardName: "rEsOuRcEgUaRdVaLuE", + UpdateProtectedItemRequestName: "uPdAtEpRoTeCtEdItEmReQuEsTvAlUe", + }, + }, + { + // 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.dAtApRoTeCtIoN/rEsOuRcEgUaRdS/rEsOuRcEgUaRdVaLuE/uPdAtEpRoTeCtEdItEmReQuEsTs/uPdAtEpRoTeCtEdItEmReQuEsTvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseUpdateProtectedItemRequestIDInsensitively(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.ResourceGuardName != v.Expected.ResourceGuardName { + t.Fatalf("Expected %q but got %q for ResourceGuardName", v.Expected.ResourceGuardName, actual.ResourceGuardName) + } + + if actual.UpdateProtectedItemRequestName != v.Expected.UpdateProtectedItemRequestName { + t.Fatalf("Expected %q but got %q for UpdateProtectedItemRequestName", v.Expected.UpdateProtectedItemRequestName, actual.UpdateProtectedItemRequestName) + } + + } +} + +func TestSegmentsForUpdateProtectedItemRequestId(t *testing.T) { + segments := UpdateProtectedItemRequestId{}.Segments() + if len(segments) == 0 { + t.Fatalf("UpdateProtectedItemRequestId 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/dataprotection/2023-11-01/resourceguards/id_updateprotectionpolicyrequest.go b/resource-manager/dataprotection/2023-11-01/resourceguards/id_updateprotectionpolicyrequest.go new file mode 100644 index 00000000000..3dd15fab913 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/resourceguards/id_updateprotectionpolicyrequest.go @@ -0,0 +1,134 @@ +package resourceguards + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = UpdateProtectionPolicyRequestId{} + +// UpdateProtectionPolicyRequestId is a struct representing the Resource ID for a Update Protection Policy Request +type UpdateProtectionPolicyRequestId struct { + SubscriptionId string + ResourceGroupName string + ResourceGuardName string + UpdateProtectionPolicyRequestName string +} + +// NewUpdateProtectionPolicyRequestID returns a new UpdateProtectionPolicyRequestId struct +func NewUpdateProtectionPolicyRequestID(subscriptionId string, resourceGroupName string, resourceGuardName string, updateProtectionPolicyRequestName string) UpdateProtectionPolicyRequestId { + return UpdateProtectionPolicyRequestId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ResourceGuardName: resourceGuardName, + UpdateProtectionPolicyRequestName: updateProtectionPolicyRequestName, + } +} + +// ParseUpdateProtectionPolicyRequestID parses 'input' into a UpdateProtectionPolicyRequestId +func ParseUpdateProtectionPolicyRequestID(input string) (*UpdateProtectionPolicyRequestId, error) { + parser := resourceids.NewParserFromResourceIdType(UpdateProtectionPolicyRequestId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := UpdateProtectionPolicyRequestId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseUpdateProtectionPolicyRequestIDInsensitively parses 'input' case-insensitively into a UpdateProtectionPolicyRequestId +// note: this method should only be used for API response data and not user input +func ParseUpdateProtectionPolicyRequestIDInsensitively(input string) (*UpdateProtectionPolicyRequestId, error) { + parser := resourceids.NewParserFromResourceIdType(UpdateProtectionPolicyRequestId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := UpdateProtectionPolicyRequestId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *UpdateProtectionPolicyRequestId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.ResourceGuardName, ok = input.Parsed["resourceGuardName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGuardName", input) + } + + if id.UpdateProtectionPolicyRequestName, ok = input.Parsed["updateProtectionPolicyRequestName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "updateProtectionPolicyRequestName", input) + } + + return nil +} + +// ValidateUpdateProtectionPolicyRequestID checks that 'input' can be parsed as a Update Protection Policy Request ID +func ValidateUpdateProtectionPolicyRequestID(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 := ParseUpdateProtectionPolicyRequestID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Update Protection Policy Request ID +func (id UpdateProtectionPolicyRequestId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DataProtection/resourceGuards/%s/updateProtectionPolicyRequests/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ResourceGuardName, id.UpdateProtectionPolicyRequestName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Update Protection Policy Request ID +func (id UpdateProtectionPolicyRequestId) 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("staticMicrosoftDataProtection", "Microsoft.DataProtection", "Microsoft.DataProtection"), + resourceids.StaticSegment("staticResourceGuards", "resourceGuards", "resourceGuards"), + resourceids.UserSpecifiedSegment("resourceGuardName", "resourceGuardValue"), + resourceids.StaticSegment("staticUpdateProtectionPolicyRequests", "updateProtectionPolicyRequests", "updateProtectionPolicyRequests"), + resourceids.UserSpecifiedSegment("updateProtectionPolicyRequestName", "updateProtectionPolicyRequestValue"), + } +} + +// String returns a human-readable description of this Update Protection Policy Request ID +func (id UpdateProtectionPolicyRequestId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Resource Guard Name: %q", id.ResourceGuardName), + fmt.Sprintf("Update Protection Policy Request Name: %q", id.UpdateProtectionPolicyRequestName), + } + return fmt.Sprintf("Update Protection Policy Request (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/dataprotection/2023-11-01/resourceguards/id_updateprotectionpolicyrequest_test.go b/resource-manager/dataprotection/2023-11-01/resourceguards/id_updateprotectionpolicyrequest_test.go new file mode 100644 index 00000000000..0f35a876e48 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/resourceguards/id_updateprotectionpolicyrequest_test.go @@ -0,0 +1,327 @@ +package resourceguards + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = UpdateProtectionPolicyRequestId{} + +func TestNewUpdateProtectionPolicyRequestID(t *testing.T) { + id := NewUpdateProtectionPolicyRequestID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceGuardValue", "updateProtectionPolicyRequestValue") + + 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.ResourceGuardName != "resourceGuardValue" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGuardName'", id.ResourceGuardName, "resourceGuardValue") + } + + if id.UpdateProtectionPolicyRequestName != "updateProtectionPolicyRequestValue" { + t.Fatalf("Expected %q but got %q for Segment 'UpdateProtectionPolicyRequestName'", id.UpdateProtectionPolicyRequestName, "updateProtectionPolicyRequestValue") + } +} + +func TestFormatUpdateProtectionPolicyRequestID(t *testing.T) { + actual := NewUpdateProtectionPolicyRequestID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceGuardValue", "updateProtectionPolicyRequestValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardValue/updateProtectionPolicyRequests/updateProtectionPolicyRequestValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseUpdateProtectionPolicyRequestID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *UpdateProtectionPolicyRequestId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardValue/updateProtectionPolicyRequests", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardValue/updateProtectionPolicyRequests/updateProtectionPolicyRequestValue", + Expected: &UpdateProtectionPolicyRequestId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ResourceGuardName: "resourceGuardValue", + UpdateProtectionPolicyRequestName: "updateProtectionPolicyRequestValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardValue/updateProtectionPolicyRequests/updateProtectionPolicyRequestValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseUpdateProtectionPolicyRequestID(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.ResourceGuardName != v.Expected.ResourceGuardName { + t.Fatalf("Expected %q but got %q for ResourceGuardName", v.Expected.ResourceGuardName, actual.ResourceGuardName) + } + + if actual.UpdateProtectionPolicyRequestName != v.Expected.UpdateProtectionPolicyRequestName { + t.Fatalf("Expected %q but got %q for UpdateProtectionPolicyRequestName", v.Expected.UpdateProtectionPolicyRequestName, actual.UpdateProtectionPolicyRequestName) + } + + } +} + +func TestParseUpdateProtectionPolicyRequestIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *UpdateProtectionPolicyRequestId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/rEsOuRcEgUaRdS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/rEsOuRcEgUaRdS/rEsOuRcEgUaRdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardValue/updateProtectionPolicyRequests", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/rEsOuRcEgUaRdS/rEsOuRcEgUaRdVaLuE/uPdAtEpRoTeCtIoNpOlIcYrEqUeStS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardValue/updateProtectionPolicyRequests/updateProtectionPolicyRequestValue", + Expected: &UpdateProtectionPolicyRequestId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ResourceGuardName: "resourceGuardValue", + UpdateProtectionPolicyRequestName: "updateProtectionPolicyRequestValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardValue/updateProtectionPolicyRequests/updateProtectionPolicyRequestValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/rEsOuRcEgUaRdS/rEsOuRcEgUaRdVaLuE/uPdAtEpRoTeCtIoNpOlIcYrEqUeStS/uPdAtEpRoTeCtIoNpOlIcYrEqUeStVaLuE", + Expected: &UpdateProtectionPolicyRequestId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ResourceGuardName: "rEsOuRcEgUaRdVaLuE", + UpdateProtectionPolicyRequestName: "uPdAtEpRoTeCtIoNpOlIcYrEqUeStVaLuE", + }, + }, + { + // 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.dAtApRoTeCtIoN/rEsOuRcEgUaRdS/rEsOuRcEgUaRdVaLuE/uPdAtEpRoTeCtIoNpOlIcYrEqUeStS/uPdAtEpRoTeCtIoNpOlIcYrEqUeStVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseUpdateProtectionPolicyRequestIDInsensitively(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.ResourceGuardName != v.Expected.ResourceGuardName { + t.Fatalf("Expected %q but got %q for ResourceGuardName", v.Expected.ResourceGuardName, actual.ResourceGuardName) + } + + if actual.UpdateProtectionPolicyRequestName != v.Expected.UpdateProtectionPolicyRequestName { + t.Fatalf("Expected %q but got %q for UpdateProtectionPolicyRequestName", v.Expected.UpdateProtectionPolicyRequestName, actual.UpdateProtectionPolicyRequestName) + } + + } +} + +func TestSegmentsForUpdateProtectionPolicyRequestId(t *testing.T) { + segments := UpdateProtectionPolicyRequestId{}.Segments() + if len(segments) == 0 { + t.Fatalf("UpdateProtectionPolicyRequestId 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/dataprotection/2023-11-01/resourceguards/method_delete.go b/resource-manager/dataprotection/2023-11-01/resourceguards/method_delete.go new file mode 100644 index 00000000000..7641951700d --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/resourceguards/method_delete.go @@ -0,0 +1,47 @@ +package resourceguards + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c ResourceGuardsClient) Delete(ctx context.Context, id ResourceGuardId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/dataprotection/2023-11-01/resourceguards/method_get.go b/resource-manager/dataprotection/2023-11-01/resourceguards/method_get.go new file mode 100644 index 00000000000..8574aef7877 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/resourceguards/method_get.go @@ -0,0 +1,51 @@ +package resourceguards + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ResourceGuardResource +} + +// Get ... +func (c ResourceGuardsClient) Get(ctx context.Context, id ResourceGuardId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/dataprotection/2023-11-01/resourceguards/method_getbackupsecuritypinrequestsobjects.go b/resource-manager/dataprotection/2023-11-01/resourceguards/method_getbackupsecuritypinrequestsobjects.go new file mode 100644 index 00000000000..83a3df24d01 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/resourceguards/method_getbackupsecuritypinrequestsobjects.go @@ -0,0 +1,89 @@ +package resourceguards + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetBackupSecurityPINRequestsObjectsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]DppBaseResource +} + +type GetBackupSecurityPINRequestsObjectsCompleteResult struct { + Items []DppBaseResource +} + +// GetBackupSecurityPINRequestsObjects ... +func (c ResourceGuardsClient) GetBackupSecurityPINRequestsObjects(ctx context.Context, id ResourceGuardId) (result GetBackupSecurityPINRequestsObjectsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/getBackupSecurityPINRequests", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]DppBaseResource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// GetBackupSecurityPINRequestsObjectsComplete retrieves all the results into a single object +func (c ResourceGuardsClient) GetBackupSecurityPINRequestsObjectsComplete(ctx context.Context, id ResourceGuardId) (GetBackupSecurityPINRequestsObjectsCompleteResult, error) { + return c.GetBackupSecurityPINRequestsObjectsCompleteMatchingPredicate(ctx, id, DppBaseResourceOperationPredicate{}) +} + +// GetBackupSecurityPINRequestsObjectsCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ResourceGuardsClient) GetBackupSecurityPINRequestsObjectsCompleteMatchingPredicate(ctx context.Context, id ResourceGuardId, predicate DppBaseResourceOperationPredicate) (result GetBackupSecurityPINRequestsObjectsCompleteResult, err error) { + items := make([]DppBaseResource, 0) + + resp, err := c.GetBackupSecurityPINRequestsObjects(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = GetBackupSecurityPINRequestsObjectsCompleteResult{ + Items: items, + } + return +} diff --git a/resource-manager/dataprotection/2023-11-01/resourceguards/method_getdefaultbackupsecuritypinrequestsobject.go b/resource-manager/dataprotection/2023-11-01/resourceguards/method_getdefaultbackupsecuritypinrequestsobject.go new file mode 100644 index 00000000000..6228677db71 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/resourceguards/method_getdefaultbackupsecuritypinrequestsobject.go @@ -0,0 +1,51 @@ +package resourceguards + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetDefaultBackupSecurityPINRequestsObjectOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DppBaseResource +} + +// GetDefaultBackupSecurityPINRequestsObject ... +func (c ResourceGuardsClient) GetDefaultBackupSecurityPINRequestsObject(ctx context.Context, id GetBackupSecurityPINRequestId) (result GetDefaultBackupSecurityPINRequestsObjectOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/dataprotection/2023-11-01/resourceguards/method_getdefaultdeleteprotecteditemrequestsobject.go b/resource-manager/dataprotection/2023-11-01/resourceguards/method_getdefaultdeleteprotecteditemrequestsobject.go new file mode 100644 index 00000000000..8900e2d59b7 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/resourceguards/method_getdefaultdeleteprotecteditemrequestsobject.go @@ -0,0 +1,51 @@ +package resourceguards + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetDefaultDeleteProtectedItemRequestsObjectOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DppBaseResource +} + +// GetDefaultDeleteProtectedItemRequestsObject ... +func (c ResourceGuardsClient) GetDefaultDeleteProtectedItemRequestsObject(ctx context.Context, id DeleteProtectedItemRequestId) (result GetDefaultDeleteProtectedItemRequestsObjectOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/dataprotection/2023-11-01/resourceguards/method_getdefaultdeleteresourceguardproxyrequestsobject.go b/resource-manager/dataprotection/2023-11-01/resourceguards/method_getdefaultdeleteresourceguardproxyrequestsobject.go new file mode 100644 index 00000000000..89ffd916f67 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/resourceguards/method_getdefaultdeleteresourceguardproxyrequestsobject.go @@ -0,0 +1,51 @@ +package resourceguards + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetDefaultDeleteResourceGuardProxyRequestsObjectOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DppBaseResource +} + +// GetDefaultDeleteResourceGuardProxyRequestsObject ... +func (c ResourceGuardsClient) GetDefaultDeleteResourceGuardProxyRequestsObject(ctx context.Context, id DeleteResourceGuardProxyRequestId) (result GetDefaultDeleteResourceGuardProxyRequestsObjectOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/dataprotection/2023-11-01/resourceguards/method_getdefaultdisablesoftdeleterequestsobject.go b/resource-manager/dataprotection/2023-11-01/resourceguards/method_getdefaultdisablesoftdeleterequestsobject.go new file mode 100644 index 00000000000..c229cf909c7 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/resourceguards/method_getdefaultdisablesoftdeleterequestsobject.go @@ -0,0 +1,51 @@ +package resourceguards + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetDefaultDisableSoftDeleteRequestsObjectOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DppBaseResource +} + +// GetDefaultDisableSoftDeleteRequestsObject ... +func (c ResourceGuardsClient) GetDefaultDisableSoftDeleteRequestsObject(ctx context.Context, id DisableSoftDeleteRequestId) (result GetDefaultDisableSoftDeleteRequestsObjectOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/dataprotection/2023-11-01/resourceguards/method_getdefaultupdateprotecteditemrequestsobject.go b/resource-manager/dataprotection/2023-11-01/resourceguards/method_getdefaultupdateprotecteditemrequestsobject.go new file mode 100644 index 00000000000..a84b65d248c --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/resourceguards/method_getdefaultupdateprotecteditemrequestsobject.go @@ -0,0 +1,51 @@ +package resourceguards + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetDefaultUpdateProtectedItemRequestsObjectOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DppBaseResource +} + +// GetDefaultUpdateProtectedItemRequestsObject ... +func (c ResourceGuardsClient) GetDefaultUpdateProtectedItemRequestsObject(ctx context.Context, id UpdateProtectedItemRequestId) (result GetDefaultUpdateProtectedItemRequestsObjectOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/dataprotection/2023-11-01/resourceguards/method_getdefaultupdateprotectionpolicyrequestsobject.go b/resource-manager/dataprotection/2023-11-01/resourceguards/method_getdefaultupdateprotectionpolicyrequestsobject.go new file mode 100644 index 00000000000..c762b2f8025 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/resourceguards/method_getdefaultupdateprotectionpolicyrequestsobject.go @@ -0,0 +1,51 @@ +package resourceguards + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetDefaultUpdateProtectionPolicyRequestsObjectOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DppBaseResource +} + +// GetDefaultUpdateProtectionPolicyRequestsObject ... +func (c ResourceGuardsClient) GetDefaultUpdateProtectionPolicyRequestsObject(ctx context.Context, id UpdateProtectionPolicyRequestId) (result GetDefaultUpdateProtectionPolicyRequestsObjectOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/dataprotection/2023-11-01/resourceguards/method_getdeleteprotecteditemrequestsobjects.go b/resource-manager/dataprotection/2023-11-01/resourceguards/method_getdeleteprotecteditemrequestsobjects.go new file mode 100644 index 00000000000..a31729ddd18 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/resourceguards/method_getdeleteprotecteditemrequestsobjects.go @@ -0,0 +1,89 @@ +package resourceguards + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetDeleteProtectedItemRequestsObjectsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]DppBaseResource +} + +type GetDeleteProtectedItemRequestsObjectsCompleteResult struct { + Items []DppBaseResource +} + +// GetDeleteProtectedItemRequestsObjects ... +func (c ResourceGuardsClient) GetDeleteProtectedItemRequestsObjects(ctx context.Context, id ResourceGuardId) (result GetDeleteProtectedItemRequestsObjectsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/deleteProtectedItemRequests", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]DppBaseResource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// GetDeleteProtectedItemRequestsObjectsComplete retrieves all the results into a single object +func (c ResourceGuardsClient) GetDeleteProtectedItemRequestsObjectsComplete(ctx context.Context, id ResourceGuardId) (GetDeleteProtectedItemRequestsObjectsCompleteResult, error) { + return c.GetDeleteProtectedItemRequestsObjectsCompleteMatchingPredicate(ctx, id, DppBaseResourceOperationPredicate{}) +} + +// GetDeleteProtectedItemRequestsObjectsCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ResourceGuardsClient) GetDeleteProtectedItemRequestsObjectsCompleteMatchingPredicate(ctx context.Context, id ResourceGuardId, predicate DppBaseResourceOperationPredicate) (result GetDeleteProtectedItemRequestsObjectsCompleteResult, err error) { + items := make([]DppBaseResource, 0) + + resp, err := c.GetDeleteProtectedItemRequestsObjects(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = GetDeleteProtectedItemRequestsObjectsCompleteResult{ + Items: items, + } + return +} diff --git a/resource-manager/dataprotection/2023-11-01/resourceguards/method_getdeleteresourceguardproxyrequestsobjects.go b/resource-manager/dataprotection/2023-11-01/resourceguards/method_getdeleteresourceguardproxyrequestsobjects.go new file mode 100644 index 00000000000..841ea552d8d --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/resourceguards/method_getdeleteresourceguardproxyrequestsobjects.go @@ -0,0 +1,89 @@ +package resourceguards + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetDeleteResourceGuardProxyRequestsObjectsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]DppBaseResource +} + +type GetDeleteResourceGuardProxyRequestsObjectsCompleteResult struct { + Items []DppBaseResource +} + +// GetDeleteResourceGuardProxyRequestsObjects ... +func (c ResourceGuardsClient) GetDeleteResourceGuardProxyRequestsObjects(ctx context.Context, id ResourceGuardId) (result GetDeleteResourceGuardProxyRequestsObjectsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/deleteResourceGuardProxyRequests", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]DppBaseResource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// GetDeleteResourceGuardProxyRequestsObjectsComplete retrieves all the results into a single object +func (c ResourceGuardsClient) GetDeleteResourceGuardProxyRequestsObjectsComplete(ctx context.Context, id ResourceGuardId) (GetDeleteResourceGuardProxyRequestsObjectsCompleteResult, error) { + return c.GetDeleteResourceGuardProxyRequestsObjectsCompleteMatchingPredicate(ctx, id, DppBaseResourceOperationPredicate{}) +} + +// GetDeleteResourceGuardProxyRequestsObjectsCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ResourceGuardsClient) GetDeleteResourceGuardProxyRequestsObjectsCompleteMatchingPredicate(ctx context.Context, id ResourceGuardId, predicate DppBaseResourceOperationPredicate) (result GetDeleteResourceGuardProxyRequestsObjectsCompleteResult, err error) { + items := make([]DppBaseResource, 0) + + resp, err := c.GetDeleteResourceGuardProxyRequestsObjects(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = GetDeleteResourceGuardProxyRequestsObjectsCompleteResult{ + Items: items, + } + return +} diff --git a/resource-manager/dataprotection/2023-11-01/resourceguards/method_getdisablesoftdeleterequestsobjects.go b/resource-manager/dataprotection/2023-11-01/resourceguards/method_getdisablesoftdeleterequestsobjects.go new file mode 100644 index 00000000000..d497dbf2308 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/resourceguards/method_getdisablesoftdeleterequestsobjects.go @@ -0,0 +1,89 @@ +package resourceguards + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetDisableSoftDeleteRequestsObjectsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]DppBaseResource +} + +type GetDisableSoftDeleteRequestsObjectsCompleteResult struct { + Items []DppBaseResource +} + +// GetDisableSoftDeleteRequestsObjects ... +func (c ResourceGuardsClient) GetDisableSoftDeleteRequestsObjects(ctx context.Context, id ResourceGuardId) (result GetDisableSoftDeleteRequestsObjectsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/disableSoftDeleteRequests", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]DppBaseResource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// GetDisableSoftDeleteRequestsObjectsComplete retrieves all the results into a single object +func (c ResourceGuardsClient) GetDisableSoftDeleteRequestsObjectsComplete(ctx context.Context, id ResourceGuardId) (GetDisableSoftDeleteRequestsObjectsCompleteResult, error) { + return c.GetDisableSoftDeleteRequestsObjectsCompleteMatchingPredicate(ctx, id, DppBaseResourceOperationPredicate{}) +} + +// GetDisableSoftDeleteRequestsObjectsCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ResourceGuardsClient) GetDisableSoftDeleteRequestsObjectsCompleteMatchingPredicate(ctx context.Context, id ResourceGuardId, predicate DppBaseResourceOperationPredicate) (result GetDisableSoftDeleteRequestsObjectsCompleteResult, err error) { + items := make([]DppBaseResource, 0) + + resp, err := c.GetDisableSoftDeleteRequestsObjects(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = GetDisableSoftDeleteRequestsObjectsCompleteResult{ + Items: items, + } + return +} diff --git a/resource-manager/dataprotection/2023-11-01/resourceguards/method_getresourcesinresourcegroup.go b/resource-manager/dataprotection/2023-11-01/resourceguards/method_getresourcesinresourcegroup.go new file mode 100644 index 00000000000..b791098f051 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/resourceguards/method_getresourcesinresourcegroup.go @@ -0,0 +1,90 @@ +package resourceguards + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetResourcesInResourceGroupOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ResourceGuardResource +} + +type GetResourcesInResourceGroupCompleteResult struct { + Items []ResourceGuardResource +} + +// GetResourcesInResourceGroup ... +func (c ResourceGuardsClient) GetResourcesInResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (result GetResourcesInResourceGroupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.DataProtection/resourceGuards", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]ResourceGuardResource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// GetResourcesInResourceGroupComplete retrieves all the results into a single object +func (c ResourceGuardsClient) GetResourcesInResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (GetResourcesInResourceGroupCompleteResult, error) { + return c.GetResourcesInResourceGroupCompleteMatchingPredicate(ctx, id, ResourceGuardResourceOperationPredicate{}) +} + +// GetResourcesInResourceGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ResourceGuardsClient) GetResourcesInResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate ResourceGuardResourceOperationPredicate) (result GetResourcesInResourceGroupCompleteResult, err error) { + items := make([]ResourceGuardResource, 0) + + resp, err := c.GetResourcesInResourceGroup(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = GetResourcesInResourceGroupCompleteResult{ + Items: items, + } + return +} diff --git a/resource-manager/dataprotection/2023-11-01/resourceguards/method_getresourcesinsubscription.go b/resource-manager/dataprotection/2023-11-01/resourceguards/method_getresourcesinsubscription.go new file mode 100644 index 00000000000..8970b624b2c --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/resourceguards/method_getresourcesinsubscription.go @@ -0,0 +1,90 @@ +package resourceguards + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetResourcesInSubscriptionOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ResourceGuardResource +} + +type GetResourcesInSubscriptionCompleteResult struct { + Items []ResourceGuardResource +} + +// GetResourcesInSubscription ... +func (c ResourceGuardsClient) GetResourcesInSubscription(ctx context.Context, id commonids.SubscriptionId) (result GetResourcesInSubscriptionOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.DataProtection/resourceGuards", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]ResourceGuardResource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// GetResourcesInSubscriptionComplete retrieves all the results into a single object +func (c ResourceGuardsClient) GetResourcesInSubscriptionComplete(ctx context.Context, id commonids.SubscriptionId) (GetResourcesInSubscriptionCompleteResult, error) { + return c.GetResourcesInSubscriptionCompleteMatchingPredicate(ctx, id, ResourceGuardResourceOperationPredicate{}) +} + +// GetResourcesInSubscriptionCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ResourceGuardsClient) GetResourcesInSubscriptionCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate ResourceGuardResourceOperationPredicate) (result GetResourcesInSubscriptionCompleteResult, err error) { + items := make([]ResourceGuardResource, 0) + + resp, err := c.GetResourcesInSubscription(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = GetResourcesInSubscriptionCompleteResult{ + Items: items, + } + return +} diff --git a/resource-manager/dataprotection/2023-11-01/resourceguards/method_getupdateprotecteditemrequestsobjects.go b/resource-manager/dataprotection/2023-11-01/resourceguards/method_getupdateprotecteditemrequestsobjects.go new file mode 100644 index 00000000000..3a107529e3c --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/resourceguards/method_getupdateprotecteditemrequestsobjects.go @@ -0,0 +1,89 @@ +package resourceguards + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetUpdateProtectedItemRequestsObjectsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]DppBaseResource +} + +type GetUpdateProtectedItemRequestsObjectsCompleteResult struct { + Items []DppBaseResource +} + +// GetUpdateProtectedItemRequestsObjects ... +func (c ResourceGuardsClient) GetUpdateProtectedItemRequestsObjects(ctx context.Context, id ResourceGuardId) (result GetUpdateProtectedItemRequestsObjectsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/updateProtectedItemRequests", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]DppBaseResource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// GetUpdateProtectedItemRequestsObjectsComplete retrieves all the results into a single object +func (c ResourceGuardsClient) GetUpdateProtectedItemRequestsObjectsComplete(ctx context.Context, id ResourceGuardId) (GetUpdateProtectedItemRequestsObjectsCompleteResult, error) { + return c.GetUpdateProtectedItemRequestsObjectsCompleteMatchingPredicate(ctx, id, DppBaseResourceOperationPredicate{}) +} + +// GetUpdateProtectedItemRequestsObjectsCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ResourceGuardsClient) GetUpdateProtectedItemRequestsObjectsCompleteMatchingPredicate(ctx context.Context, id ResourceGuardId, predicate DppBaseResourceOperationPredicate) (result GetUpdateProtectedItemRequestsObjectsCompleteResult, err error) { + items := make([]DppBaseResource, 0) + + resp, err := c.GetUpdateProtectedItemRequestsObjects(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = GetUpdateProtectedItemRequestsObjectsCompleteResult{ + Items: items, + } + return +} diff --git a/resource-manager/dataprotection/2023-11-01/resourceguards/method_getupdateprotectionpolicyrequestsobjects.go b/resource-manager/dataprotection/2023-11-01/resourceguards/method_getupdateprotectionpolicyrequestsobjects.go new file mode 100644 index 00000000000..9138a703889 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/resourceguards/method_getupdateprotectionpolicyrequestsobjects.go @@ -0,0 +1,89 @@ +package resourceguards + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetUpdateProtectionPolicyRequestsObjectsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]DppBaseResource +} + +type GetUpdateProtectionPolicyRequestsObjectsCompleteResult struct { + Items []DppBaseResource +} + +// GetUpdateProtectionPolicyRequestsObjects ... +func (c ResourceGuardsClient) GetUpdateProtectionPolicyRequestsObjects(ctx context.Context, id ResourceGuardId) (result GetUpdateProtectionPolicyRequestsObjectsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/updateProtectionPolicyRequests", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]DppBaseResource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// GetUpdateProtectionPolicyRequestsObjectsComplete retrieves all the results into a single object +func (c ResourceGuardsClient) GetUpdateProtectionPolicyRequestsObjectsComplete(ctx context.Context, id ResourceGuardId) (GetUpdateProtectionPolicyRequestsObjectsCompleteResult, error) { + return c.GetUpdateProtectionPolicyRequestsObjectsCompleteMatchingPredicate(ctx, id, DppBaseResourceOperationPredicate{}) +} + +// GetUpdateProtectionPolicyRequestsObjectsCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ResourceGuardsClient) GetUpdateProtectionPolicyRequestsObjectsCompleteMatchingPredicate(ctx context.Context, id ResourceGuardId, predicate DppBaseResourceOperationPredicate) (result GetUpdateProtectionPolicyRequestsObjectsCompleteResult, err error) { + items := make([]DppBaseResource, 0) + + resp, err := c.GetUpdateProtectionPolicyRequestsObjects(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = GetUpdateProtectionPolicyRequestsObjectsCompleteResult{ + Items: items, + } + return +} diff --git a/resource-manager/dataprotection/2023-11-01/resourceguards/method_patch.go b/resource-manager/dataprotection/2023-11-01/resourceguards/method_patch.go new file mode 100644 index 00000000000..c7192b6e468 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/resourceguards/method_patch.go @@ -0,0 +1,55 @@ +package resourceguards + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PatchOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ResourceGuardResource +} + +// Patch ... +func (c ResourceGuardsClient) Patch(ctx context.Context, id ResourceGuardId, input PatchResourceGuardInput) (result PatchOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/dataprotection/2023-11-01/resourceguards/method_put.go b/resource-manager/dataprotection/2023-11-01/resourceguards/method_put.go new file mode 100644 index 00000000000..8230641592c --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/resourceguards/method_put.go @@ -0,0 +1,56 @@ +package resourceguards + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PutOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ResourceGuardResource +} + +// Put ... +func (c ResourceGuardsClient) Put(ctx context.Context, id ResourceGuardId, input ResourceGuardResource) (result PutOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/dataprotection/2023-11-01/resourceguards/model_dppbaseresource.go b/resource-manager/dataprotection/2023-11-01/resourceguards/model_dppbaseresource.go new file mode 100644 index 00000000000..68d4e93d8b5 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/resourceguards/model_dppbaseresource.go @@ -0,0 +1,10 @@ +package resourceguards + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DppBaseResource struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/dataprotection/2023-11-01/resourceguards/model_patchresourceguardinput.go b/resource-manager/dataprotection/2023-11-01/resourceguards/model_patchresourceguardinput.go new file mode 100644 index 00000000000..f1fedc23f9b --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/resourceguards/model_patchresourceguardinput.go @@ -0,0 +1,8 @@ +package resourceguards + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PatchResourceGuardInput struct { + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/dataprotection/2023-11-01/resourceguards/model_resourceguard.go b/resource-manager/dataprotection/2023-11-01/resourceguards/model_resourceguard.go new file mode 100644 index 00000000000..968af9fa9f5 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/resourceguards/model_resourceguard.go @@ -0,0 +1,12 @@ +package resourceguards + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceGuard struct { + AllowAutoApprovals *bool `json:"allowAutoApprovals,omitempty"` + Description *string `json:"description,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + ResourceGuardOperations *[]ResourceGuardOperation `json:"resourceGuardOperations,omitempty"` + VaultCriticalOperationExclusionList *[]string `json:"vaultCriticalOperationExclusionList,omitempty"` +} diff --git a/resource-manager/dataprotection/2023-11-01/resourceguards/model_resourceguardoperation.go b/resource-manager/dataprotection/2023-11-01/resourceguards/model_resourceguardoperation.go new file mode 100644 index 00000000000..db7b25d6e59 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/resourceguards/model_resourceguardoperation.go @@ -0,0 +1,9 @@ +package resourceguards + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceGuardOperation struct { + RequestResourceType *string `json:"requestResourceType,omitempty"` + VaultCriticalOperation *string `json:"vaultCriticalOperation,omitempty"` +} diff --git a/resource-manager/dataprotection/2023-11-01/resourceguards/model_resourceguardresource.go b/resource-manager/dataprotection/2023-11-01/resourceguards/model_resourceguardresource.go new file mode 100644 index 00000000000..16508017629 --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/resourceguards/model_resourceguardresource.go @@ -0,0 +1,19 @@ +package resourceguards + +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 ResourceGuardResource struct { + ETag *string `json:"eTag,omitempty"` + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ResourceGuard `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/dataprotection/2023-11-01/resourceguards/predicates.go b/resource-manager/dataprotection/2023-11-01/resourceguards/predicates.go new file mode 100644 index 00000000000..839d8fbca1b --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/resourceguards/predicates.go @@ -0,0 +1,60 @@ +package resourceguards + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DppBaseResourceOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p DppBaseResourceOperationPredicate) Matches(input DppBaseResource) 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 ResourceGuardResourceOperationPredicate struct { + ETag *string + Id *string + Location *string + Name *string + Type *string +} + +func (p ResourceGuardResourceOperationPredicate) Matches(input ResourceGuardResource) 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.Location != nil && (input.Location == nil || *p.Location != *input.Location) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/dataprotection/2023-11-01/resourceguards/version.go b/resource-manager/dataprotection/2023-11-01/resourceguards/version.go new file mode 100644 index 00000000000..6e395489fda --- /dev/null +++ b/resource-manager/dataprotection/2023-11-01/resourceguards/version.go @@ -0,0 +1,12 @@ +package resourceguards + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-11-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/resourceguards/%s", defaultApiVersion) +}